Package org.apache.jetspeed.om.registry

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


         *   </access>
         * </security-entry>
         */
        Registry.addEntry(Registry.SECURITY, (RegistryEntry) createSecurityEntry( "all_users-view_anon", null, "user", null, "*"));
        assertNotNull( "Getting all_users-view_anon security " , Registry.getEntry( Registry.SECURITY, "all_users-view_anon"));
        SecurityEntry secEntry = (SecurityEntry) Registry.getEntry( Registry.SECURITY, "all_users-view_anon");
        Vector accessVector = secEntry.getAccesses();
        assertEquals( "Getting number of accesses for all_users-view_anon", 1, accessVector.size());
        BaseSecurityAllow allowElement = new BaseSecurityAllow();
        allowElement.setRole("guest");
        Vector allowVector = new Vector();
        allowVector.addElement(allowElement);
        BaseSecurityAccess accessElement  = new BaseSecurityAccess();
        accessElement.setAction("view");
        accessElement.setAllows( allowVector );
        accessVector.addElement(accessElement);
        secEntry.setAccesses(accessVector);
        assertEquals( "Getting number of accesses for all_users-view_anon", 2, secEntry.getAccesses().size());
       
        // Verify users and their groups
        assertNotNull( "Getting admin user", JetspeedSecurity.getUser("admin"));
        assertTrue( "Admin user has Admin role", JetspeedRoleManagement.hasRole("admin","admin"));
        assertTrue( "Admin user has User role", JetspeedRoleManagement.hasRole("admin","user"));
View Full Code Here


   
    assertEquals( "Using RegistryAccessController",
    "org.apache.jetspeed.services.security.registry.RegistryAccessController",
    JetspeedResources.getString("services.PortalAccessController.classname"));

    SecurityEntry paav = createSecurityEntry( "powerusers_all-anon_view", "apache", "admin", null, "*");
    Registry.addEntry(Registry.SECURITY, (RegistryEntry) paav);
    assertNotNull( "Getting powerusers_all-anon_view" , Registry.getEntry( Registry.SECURITY, "powerusers_all-anon_view"));
   
    SecurityEntry secEntry = (SecurityEntry) Registry.getEntry( Registry.SECURITY, "powerusers_all-anon_view");
    Vector accessVector = secEntry.getAccesses();
   
    for (Iterator it = accessVector.iterator(); it.hasNext();)
    {
      SecurityAccess access = (SecurityAccess) it.next();
      System.out.println("Action:" + access.getAction().toString());
View Full Code Here

         *   </access>
         * </security-entry>
         */
        Registry.addEntry(Registry.SECURITY, (RegistryEntry) createSecurityEntry( "all_users-view_anon", null, "user", null, "*"));
        assertNotNull( "Getting all_users-view_anon security " , Registry.getEntry( Registry.SECURITY, "all_users-view_anon"));
        SecurityEntry secEntry = (SecurityEntry) Registry.getEntry( Registry.SECURITY, "all_users-view_anon");
        Vector accessVector = secEntry.getAccesses();
        assertEquals( "Getting number of accesses for all_users-view_anon", 1, accessVector.size());
        BaseSecurityAllow allowElement = new BaseSecurityAllow();
        allowElement.setRole("guest");
        Vector allowVector = new Vector();
        allowVector.addElement(allowElement);
        BaseSecurityAccess accessElement  = new BaseSecurityAccess();
        accessElement.setAction("view");
        accessElement.setAllows( allowVector );
        accessVector.addElement(accessElement);
        secEntry.setAccesses(accessVector);
        assertEquals( "Getting number of accesses for all_users-view_anon", 2, secEntry.getAccesses().size());
       
        // Verify users and their groups
        assertNotNull( "Getting admin user", JetspeedSecurity.getUser("admin"));
        assertTrue( "Admin user has Admin role", JetspeedRoleManagement.hasRole("admin","admin"));
        assertTrue( "Admin user has User role", JetspeedRoleManagement.hasRole("admin","user"));
View Full Code Here

   
    assertEquals( "Using RegistryAccessController",
    "org.apache.jetspeed.services.security.registry.RegistryAccessController",
    JetspeedResources.getString("services.PortalAccessController.classname"));

    SecurityEntry paav = createSecurityEntry( "powerusers_all-anon_view", "apache", "admin", null, "*");
    Registry.addEntry(Registry.SECURITY, (RegistryEntry) paav);
    assertNotNull( "Getting powerusers_all-anon_view" , Registry.getEntry( Registry.SECURITY, "powerusers_all-anon_view"));
   
    SecurityEntry secEntry = (SecurityEntry) Registry.getEntry( Registry.SECURITY, "powerusers_all-anon_view");
    Vector accessVector = secEntry.getAccesses();
   
    for (Iterator it = accessVector.iterator(); it.hasNext();)
    {
      SecurityAccess access = (SecurityAccess) it.next();
      System.out.println("Action:" + access.getAction().toString());
View Full Code Here

     * @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

     * @param SecurityEntry secEntry the entry to clone
     * @return SecurityEntry the cloned entry.
     */
    private static SecurityEntry cloneEntry(SecurityEntry secEntry)
    {
        SecurityEntry clonedEntry = null;
        try
        {
            ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(100);
            ObjectOutputStream objectoutputstream = new ObjectOutputStream(bytearrayoutputstream);
            objectoutputstream.writeObject(secEntry);
View Full Code Here

     * @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

     */
    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

            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

            // 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

TOP

Related Classes of org.apache.jetspeed.om.registry.SecurityEntry

Copyright © 2018 www.massapicom. 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.