Examples of SecurityEntry


Examples of org.apache.jetspeed.om.registry.SecurityEntry

            assertNotNull(fragment);
            Vector securityEntries = fragment.getSecurityEntries();
            assertTrue("Security Entries exist", !securityEntries.isEmpty());

            // test abstract
            SecurityEntry securityEntry = (SecurityEntry) securityEntries.firstElement();
            assertNotNull("Got first Security Entry", securityEntry);
            assertTrue("Getting expect security entry", securityEntry.getName().equals("basic_testcase"));

            // Get the action
            Vector securityAccesses = securityEntry.getAccesses();
            assertNotNull("Got SecurityAccesses", securityAccesses);
            SecurityAccess securityAccess = (SecurityAccess) securityAccesses.firstElement();
            assertNotNull("Got SecurityAccess", securityAccess);
            assertEquals("Verify action", "view", securityAccess.getAction());

            // Get allows
            Vector securityAllows = securityAccess.getAllows();
            assertNotNull("Got SecurityAllows", securityAllows);
            SecurityAllow securityAllow = (SecurityAllow) securityAllows.firstElement();
            assertNotNull("Got SecurityAllow", securityAllow);
            assertEquals("Verify role", "clerk", securityAllow.getRole());
            assertNull("Verify user" , securityAllow.getUser());

            securityAllow = (SecurityAllow) securityAllows.elementAt(1);
            assertNotNull("Got SecurityAllow", securityAllow);
            assertNull("Verify role", securityAllow.getRole());
            assertEquals("Verify user", "joe", securityAllow.getUser());

            securityAllow = (SecurityAllow) securityAllows.elementAt(2);
            assertNotNull("Got SecurityAllow", securityAllow);
            assertEquals("Verify role", "manager", securityAllow.getRole());
            assertEquals("Verify user", "fred", securityAllow.getUser());

            // test allows
            assertEquals("clerk role can view", true, securityEntry.allowsRole("clerk", "view"));
            assertEquals("manager role can view", true, securityEntry.allowsRole("manager", "view"));
            assertEquals("anonymous role can NOT view", false, securityEntry.allowsRole("anonymous", "view"));
            assertEquals("fred user can view", true, securityEntry.allowsUser("fred", "view"));
            assertEquals("joe user can view", true, securityEntry.allowsUser("joe", "view"));
            assertEquals("anonymous user can NOT view", false, securityEntry.allowsUser("anonymous", "view"));

            // Customize has <allow-id user="*"/>
            assertEquals("clerk role can NOT customize", false, securityEntry.allowsRole("clerk", "customize"));
            assertEquals("joe user can customize", true, securityEntry.allowsUser("joe", "customize"));

            // Minimize has no <allows-if .../>
            assertEquals("clerk role can NOT minimize", true, securityEntry.allowsRole("clerk", "minimize"));
            assertEquals("joe user can NOT minimize", true, securityEntry.allowsUser("joe", "minimize"));

            // Maximixe is not defined
            assertEquals("clerk role can NOT maximize", false, securityEntry.allowsRole("clerk", "maximize"));
            assertEquals("joe user can NOT maximize", false, securityEntry.allowsUser("joe", "maximize"));

            // Test the wide-open entry
            entryFound = false;
            for (Iterator securityIterator = securityEntries.iterator(); securityIterator.hasNext();)
            {
                securityEntry = (SecurityEntry) securityIterator.next();
                if (securityEntry.getName().equals("wide_open") == true)
                {
                    entryFound = true;
                    assertEquals("any role is NOT allowed", false, securityEntry.allowsRole("customer", "do_any_thing"));
                    assertEquals("any user is allowed", true, securityEntry.allowsUser("joe_customer", "do_any_thing"));
                }
            }
            assertTrue("Found wide_open security entry", entryFound);

            // Test the owner-only entry
            entryFound = false;
            for (Iterator securityIterator = securityEntries.iterator(); securityIterator.hasNext();)
            {
                securityEntry = (SecurityEntry) securityIterator.next();
                if (securityEntry.getName().equals("owner_only") == true)
                {
                    entryFound = true;
                    assertEquals("User joe_customer is not allowed", false,
                                 securityEntry.allowsUser("joe_customer", "do_any_thing"));
                    assertEquals("User joe_customer is not allowed", false,
                                 securityEntry.allowsUser("joe_customer", "do_any_thing", "joe_owner"));
                    assertEquals("User joe_owner is allowed", true,
                                 securityEntry.allowsUser("joe_owner", "do_any_thing", "joe_owner"));
                }
            }
            assertTrue("Found owner_only security entry", entryFound);
        }
    }
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

            // Test the wide-open entry
            boolean entryFound = false;
            Iterator securityIterator = null;
            for (securityIterator = securityEntries.iterator(); securityIterator.hasNext();)
            {
                SecurityEntry securityEntry = (SecurityEntry) securityIterator.next();
                if (securityEntry.getName().equals("wide_open") == true)
                {
                    entryFound = true;
                    SecurityReference securityReference = securityEntry.getSecurityRef();
                    assertNotNull("Security entry 'wide_open' has a SecurityReference", securityReference);
                    assertEquals("Got parent", "admin_only", securityReference.getParent());
                }
            }
            assertTrue("Found wide_open security entry", entryFound);

            // Test the use_only entry
            entryFound = false;
            for (securityIterator = securityEntries.iterator(); securityIterator.hasNext();)
            {
                SecurityEntry securityEntry = (SecurityEntry) securityIterator.next();
                if (securityEntry.getName().equals("user_only") == true)
                {
                    entryFound = true;
                    SecurityReference securityReference = securityEntry.getSecurityRef();
                    assertNull("Security entry 'user_open' has no SecurityReference", securityReference);
                }
            }
            assertEquals("Found user_only security entry", true, entryFound);
        }
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

                System.out.println("debug name  = " + names.nextElement());
            }
            boolean testAdd = true;
            if (testAdd)
            {           
                SecurityEntry entry = (SecurityEntry)Registry.createEntry(Registry.SECURITY);
                entry.setName("test");
                entry.setDescription("description");
                entry.setTitle("The Title");
                entry.grantRoleAccess("*", "admin");
                entry.grantGroupAccess("view", "sales");
                entry.grantGroupAccess("edit", "sales");
                entry.grantGroupAccess("edit", "marketing");
                entry.grantGroupAccess("edit", "accounting");

                assertSimpleConstraints(entry);
                   
                Registry.addEntry(Registry.SECURITY, (RegistryEntry)entry);
            }
            SecurityEntry se = (SecurityEntry)Registry.getEntry(Registry.SECURITY, "test");
            assertSimpleConstraints(se);
           
            SecurityEntry se2 = (SecurityEntry)Registry.getEntry(Registry.SECURITY, "test");
            assertSimpleConstraints(se2);
            se2.revokeGroupAccess("edit", "accounting");
            se2.grantGroupAccess("view", "accounting");
           
            Registry.saveEntry(Registry.SECURITY, (RegistryEntry)se2);
            Registry.removeEntry(Registry.SECURITY, "test");
           
        }
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

   
    private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(SecurityDbEntryPeer.class.getName());
   
    public static SecurityEntry lookupSecurityEntry(String entryName)
    {
        SecurityEntry se = null;
        try
        {
            SecurityDbEntry sde = lookup(entryName);
            if(sde != null)
            {
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

    }
   
    public static SecurityEntry mapDatabaseToEntry(SecurityDbEntry sde)
    throws TorqueException
    {
        SecurityEntry se = new BaseSecurityEntry(sde.getId());           
        se.setName(sde.getName());
        se.setTitle(sde.getTitle());
        se.setDescription(sde.getDescription());
       
        Iterator accesses = sde.getSecurityAccessDbEntrys().iterator();
        while (accesses.hasNext())
        {
            SecurityAccessDbEntry sade = (SecurityAccessDbEntry)accesses.next();
            SecurityAccess access = new BaseSecurityAccess(sade.getId());
            access.setAction(sade.getAction());
                           
            Iterator allows = sade.getSecurityAllowDbEntrys().iterator();
            while (allows.hasNext())
            {
                SecurityAllowDbEntry sa = (SecurityAllowDbEntry)allows.next();
                if (sa.getAllowType().equals(ALLOW_OWNER))
                {
                    SecurityAllow allow = new BaseSecurityAllowOwner(sa.getId());                   
                    allow.setOwner(true);
                    access.getOwnerAllows().add(allow);
                }
                else if (sa.getAllowType().equals(ALLOW_BOTH))
                {
                    SecurityAllow allow = new BaseSecurityAllow(sa.getId());
                   
                    allow.setRole(sa.getAllowValue());
                    allow.setGroup(sa.getAllowGroup());
                    access.getAllows().add(allow);               
                }
                else if (sa.getAllowType().equals(ALLOW_ROLE))
                {
                    SecurityAllow allow = new BaseSecurityAllow(sa.getId());
                   
                    allow.setRole(sa.getAllowValue());
                    access.getAllows().add(allow);
                }
                else if (sa.getAllowType().equals(ALLOW_GROUP))
                {
                    SecurityAllow allow = new BaseSecurityAllow(sa.getId());
                   
                    allow.setGroup(sa.getAllowValue());
                    access.getAllows().add(allow);
                }
                else
                {
                    SecurityAllow allow = new BaseSecurityAllow(sa.getId());                   
                    allow.setUser(sa.getAllowValue());
                    access.getAllows().add(allow);
                }                   
            }
            se.getAccesses().add(access);
        }
        return se;
    }
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

        try
        {
            Iterator result = SecurityDbEntryPeer.doSelect(new Criteria()).iterator();
            while (result.hasNext())
            {
                SecurityEntry se = mapDatabaseToEntry((SecurityDbEntry)result.next());
                extent.add(se);
            }
        }
        catch (TorqueException e)
        {
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

     * @param securityRef the security reference to check
     * @param action the jetspeed-action (view, edit, customize, delete...) for which permission is being checked.
     */
    private boolean checkPermission(JetspeedUser user, SecurityReference securityRef, String action, String owner)
    {
        SecurityEntry securityEntry = (SecurityEntry) Registry.getEntry( Registry.SECURITY, securityRef.getParent());
        if (securityEntry == null)
        {
            logger.warn("Security id " + securityRef.getParent() + " does not exist.  This was requested by the user " + user.getUserName());
            return false;
        }

        if (securityEntry.allowsUser(user.getUserName(), action, owner))
        {
            return true;
        }

        try
        {
      for( Iterator roles = JetspeedRoleManagement.getRoles(user.getUserName()); roles.hasNext();)
      {
        GroupRole grouprole = (GroupRole) roles.next();
        String groupname = grouprole.getGroup().getName();
        String rolename = grouprole.getRole().getName();
        if (securityEntry.allowsGroupRole(groupname, rolename, action))
          return true;         
      }

//            for( Iterator roles = JetspeedRoleManagement.getRoles(user.getUserName()); roles.hasNext();)
//            {
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

                portlets.setSkin(skin);

                // Set top level security ref
                if (groupmergeSecurityref != null)
                {
                    SecurityEntry entry =
                        (SecurityEntry) Registry.getEntry(
                            Registry.SECURITY,
                            groupmergeSecurityref);
                    if (entry != null)
                    {
                        SecurityReference ref = new BaseSecurityReference();
                        ref.setParent(entry.getName());
                        portlets.setSecurityRef(ref);
                    }
                }

                String mediaType = null;
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

     */
    public SecurityReference getDefaultSecurityRef(String type)
    {
        BaseSecurityReference result = null;

        SecurityEntry entry = null;

        String defaultRef = null;
        if (type.equals(Profiler.PARAM_USER))
        {
            defaultRef = this.defaultUserSecurityRef;
        }
        else if (type.equals(Profiler.PARAM_ANON))
        {
            defaultRef = this.defaultAnonSecurityRef;
        }
        else if (type.equals(Profiler.PARAM_ROLE))
        {
            defaultRef = this.defaultRoleSecurityRef;
        }
        else if (type.equals(Profiler.PARAM_GROUP))
        {
            defaultRef = this.defaultGroupSecurityRef;
        }

        if (defaultRef != null)
        {
            entry = (SecurityEntry) Registry.getEntry(Registry.SECURITY, defaultRef);
            if (logger.isDebugEnabled())
            {
                logger.debug(
                    "JetspeedPortalToolkit: default security for type: " + type + " is " + defaultRef);
            }
            if (entry != null)
            {
                result = new BaseSecurityReference();
                result.setParent(entry.getName());
                if (logger.isDebugEnabled())
                {
                    logger.debug(
                        "JetspeedPortalToolkit: default security for type: "
                            + type
                            + " was set to "
                            + entry.getName());
                }
            }
        }

        return result;
View Full Code Here

Examples of org.apache.jetspeed.om.registry.SecurityEntry

     * @param String newName Name to give the cloned entry
     * @return SecurityEntry The cloned entry.
     */
    public SecurityEntry cloneSecurityEntry(String original, String newName)
    {
        SecurityEntry baseEntry = getSecurityEntry(original);
        if (baseEntry != null)
        {
            SecurityEntry newEntry = cloneEntry(baseEntry);
            newEntry.setName(newName);
            return newEntry;
        }

        return null;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.