portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r692497 [2/2] - in /portals/jetspeed-2/portal/branches/security-refactoring: ./ components/jetspeed-security/ components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ components/jetspeed-security/src/main/java/org/ap...
Date Fri, 05 Sep 2008 17:26:18 GMT
Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java?rev=692497&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java
Fri Sep  5 10:26:17 2008
@@ -0,0 +1,134 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.ldap;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import org.apache.jetspeed.security.mapping.SecurityEntityManager;
+import org.apache.jetspeed.security.mapping.model.Attribute;
+import org.apache.jetspeed.security.mapping.model.AttributeDef;
+import org.apache.jetspeed.security.mapping.model.Entity;
+
+/**
+ * @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
+ */
+public class BasicTestCases
+{
+
+    private final boolean debugMode;
+
+    SecurityEntityManager entityManager;
+
+    public BasicTestCases(SecurityEntityManager entityManager, boolean debugMode)
+    {
+        this.debugMode = debugMode;
+        this.entityManager = entityManager;
+    }
+
+    public void testFetchSingleEntity(SecurityEntityManager entityManager,
+            Entity sampleEntity) throws Exception
+    {
+        Entity resultUser = entityManager.getEntity(sampleEntity.getType(),
+                sampleEntity.getId());
+        TestCase.assertNotNull(resultUser);
+        printDebug(resultUser);
+        TestCase.assertEquals(true, resultUser.equals(sampleEntity));
+    }
+
+    public void testFetchAllEntities(int totalNrOfUsers) throws Exception
+    {
+        Collection<Entity> entities = entityManager.getAllEntities("user");
+        TestCase.assertNotNull(entities);
+        TestCase.assertEquals(totalNrOfUsers, entities.size());
+    }
+
+    public void testFetchRelatedEntities(String fromEntityType,
+            String toEntityType, String relationType, String fromEntityId,
+            Collection<Entity> expectedEntities) throws Exception
+    {
+        Entity randomUser = entityManager.getEntity(fromEntityType,
+                fromEntityId);
+        TestCase.assertNotNull(randomUser);
+        Collection<Entity> resultEntities = entityManager.getRelatedEntities(
+                randomUser, toEntityType, relationType);
+
+        basicEntityResultSetChecks(expectedEntities, resultEntities);
+    }
+
+    @SuppressWarnings("unchecked")
+    private void basicEntityResultSetChecks(
+            Collection<Entity> expectedEntities,
+            Collection<Entity> resultEntities)
+    {
+        TestCase.assertNotNull(resultEntities);
+        Set expectedSet = new HashSet(expectedEntities);
+        Set resultSet = new HashSet(resultEntities);
+        TestCase.assertEquals(true, expectedSet.equals(resultSet));
+    }
+
+    private void printDebug(Entity ent)
+    {
+        if (debugMode)
+        {
+            Set<AttributeDef> defs = ent.getAllowedAttributes();
+            for (AttributeDef attributeDef : defs)
+            {
+                Attribute attr = ent.getAttribute(attributeDef.getName());
+                if (attr != null)
+                {
+                    if (attr.getDefinition().isMultiValue())
+                    {
+                        System.out.println("Values for " + attr.getName()
+                                + " :");
+                        System.out.println("===");
+                        for (String val : attr.getValues())
+                        {
+                            System.out.println(val);
+                        }
+                        System.out.println("===");
+                    } else
+                    {
+                        System.out.print("Value for " + attr.getName() + " :");
+                        System.out.println(attr.getValue());
+                    }
+
+                }
+            }
+        }
+
+    }
+
+    private void printDebug(Collection<Entity> entities)
+    {
+        if (debugMode)
+        {
+            for (Iterator iterator = entities.iterator(); iterator.hasNext();)
+            {
+                Entity entity = (Entity) iterator.next();
+                System.out.println("================================");
+                System.out.println("Found " + entities.size() + " entities: ");
+                System.out.println("================================");
+            }
+        }
+
+    }
+
+}

Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java?rev=692497&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java
Fri Sep  5 10:26:17 2008
@@ -0,0 +1,150 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.ldap.setup1;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+import org.apache.jetspeed.security.mapping.ldap.AbstractLDAPTest;
+import org.apache.jetspeed.security.mapping.ldap.dao.DefaultLDAPEntityManager;
+import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO;
+import org.apache.jetspeed.security.mapping.ldap.dao.EntityRelationDAO;
+import org.apache.jetspeed.security.mapping.ldap.dao.LDAPEntityDAOConfiguration;
+import org.apache.jetspeed.security.mapping.ldap.dao.impl.AttributeBasedRelationDAO;
+import org.apache.jetspeed.security.mapping.ldap.dao.impl.SpringLDAPEntityDAO;
+import org.apache.jetspeed.security.mapping.ldap.filter.SimpleFilter;
+import org.apache.jetspeed.security.mapping.model.AttributeDef;
+import org.apache.jetspeed.security.mapping.model.impl.AttributeDefImpl;
+
+/**
+ * @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
+ */
+public abstract class AbstractSetup1LDAPTest extends AbstractLDAPTest
+{
+
+    public static final AttributeDefImpl CN_DEF = new AttributeDefImpl("cn");
+
+    public static final AttributeDefImpl UID_DEF = new AttributeDefImpl("uid");
+
+    public static final AttributeDefImpl GIVEN_NAME_DEF = new AttributeDefImpl(
+            "givenName");;
+
+    public static final AttributeDefImpl LAST_NAME_DEF = new AttributeDefImpl(
+            "lastname");;
+
+    public static final AttributeDefImpl DESCRIPTION_ATTR_DEF = new AttributeDefImpl(
+            "description");
+
+    protected Set<AttributeDef> userAttrDefs;
+
+    protected Set<AttributeDef> roleAttrDefs;
+
+    protected AttributeBasedRelationDAO hasRoleDAO;
+
+    public Resource[] initializationData()
+    {
+        final ClassPathResource ldapPersonInfo = new ClassPathResource(
+                "resources/setup1.ldif", getClass());
+        return new Resource[]
+        { ldapPersonInfo};
+    }
+
+    @Override
+    public void internalSetUp() throws Exception
+    {
+
+        Set<AttributeDef> basicAttrDefs = new HashSet<AttributeDef>();
+        basicAttrDefs.add(UID_DEF);
+        basicAttrDefs.add(CN_DEF);
+
+        // setting up user DAO
+        userAttrDefs = new HashSet<AttributeDef>();
+        userAttrDefs.addAll(basicAttrDefs);
+        userAttrDefs.add(GIVEN_NAME_DEF);
+
+        userSearchConfig = new LDAPEntityDAOConfiguration();
+        userSearchConfig.setBaseDN("");
+        userSearchConfig
+                .setBaseFilter(new SimpleFilter("(objectClass=person)"));
+        userSearchConfig.setLdapIdAttribute("uid");
+        userSearchConfig.setAttributeDefinitions(userAttrDefs);
+        userSearchConfig.setEntityType("user");
+
+        SpringLDAPEntityDAO userDAO = new SpringLDAPEntityDAO();
+        userDAO.setLdapTemplate(ldapTemplate);
+        userDAO.setConfiguration(userSearchConfig);
+
+        // setting up role DAO
+
+        roleAttrDefs = new HashSet<AttributeDef>();
+        roleAttrDefs.addAll(basicAttrDefs);
+        roleAttrDefs.add(DESCRIPTION_ATTR_DEF);
+
+        LDAPEntityDAOConfiguration roleSearchConfig = new LDAPEntityDAOConfiguration();
+        roleSearchConfig.setBaseDN("");
+        roleSearchConfig.setBaseFilter(new SimpleFilter(
+                "(objectClass=groupOfUniqueNames)"));
+        roleSearchConfig.setLdapIdAttribute("cn");
+        roleSearchConfig.setAttributeDefinitions(roleAttrDefs);
+        roleSearchConfig.setEntityType("role");
+
+        SpringLDAPEntityDAO roleDAO = new SpringLDAPEntityDAO();
+        roleDAO.setLdapTemplate(ldapTemplate);
+        roleDAO.setConfiguration(roleSearchConfig);
+
+        Map<String, EntityDAO> daos = new HashMap<String, EntityDAO>();
+        daos.put("user", userDAO);
+        daos.put("role", roleDAO);
+
+        entityManager = new DefaultLDAPEntityManager();
+        entityManager.setEntityDAOs(daos);
+
+        // relation DAOs
+        Collection<EntityRelationDAO> relationDaos = new ArrayList<EntityRelationDAO>();
+
+        // hasRole relation DAO
+        hasRoleDAO = new AttributeBasedRelationDAO();
+        hasRoleDAO.setLdapTemplate(ldapTemplate);
+        hasRoleDAO.setRelationAttribute("uniqueMember");
+        // use attribute on target entity (of "role" type); user IDs are stored
+        // in a multi-valued attribute on roles.
+        hasRoleDAO.setUseFromEntityAttribute(false);
+        hasRoleDAO.setRelationType("hasRole");
+        hasRoleDAO.setFromEntityType("user");
+        hasRoleDAO.setToEntityType("role");
+        hasRoleDAO.setAttributeContainsInternalId(true);
+        relationDaos.add(hasRoleDAO);
+
+        entityManager.setEntityRelationDAOs(relationDaos);
+
+    }
+
+    @Override
+    protected void internaltearDown() throws Exception
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java?rev=692497&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java
Fri Sep  5 10:26:17 2008
@@ -0,0 +1,66 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.ldap.setup1;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.jetspeed.security.mapping.model.Entity;
+import org.apache.jetspeed.security.mapping.model.impl.EntityImpl;
+
+/**
+ * @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
+ */
+public class UserTests extends AbstractSetup1LDAPTest
+{
+
+    public void testSingleUser() throws Exception
+    {
+        EntityImpl sampleUser = new EntityImpl("user", "jsmith", userAttrDefs);
+        sampleUser
+                .setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
+        sampleUser.setAttribute(GIVEN_NAME_DEF.getName(), "Joe Smith");
+        sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
+        sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+        basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
+    }
+
+    public void testFetchRolesForUserByRoleAttribute() throws Exception
+    {
+        EntityImpl role1 = new EntityImpl("role", "Role1", roleAttrDefs);
+        role1.setInternalId("cn=Role1, o=sevenSeas");
+        role1.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "Role 1");
+        role1.setAttribute(CN_DEF.getName(), "Role1");
+
+        EntityImpl role3 = new EntityImpl("role", "Role3", roleAttrDefs);
+        role3.setInternalId("cn=Role3, o=sevenSeas");
+        role3.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "Role 3");
+        role3.setAttribute(CN_DEF.getName(), "Role3");
+
+        Collection<Entity> resultSet = new ArrayList<Entity>();
+        resultSet.add(role1);
+        resultSet.add(role3);
+        basicTestCases.testFetchRelatedEntities("user", "role", "hasRole",
+                "jsmith", resultSet);
+    }
+
+    @Override
+    protected void internaltearDown() throws Exception
+    {
+    }
+
+}

Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/resources/setup1.ldif
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/resources/setup1.ldif?rev=692497&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/resources/setup1.ldif
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/resources/setup1.ldif
Fri Sep  5 10:26:17 2008
@@ -0,0 +1,184 @@
+dn: o=sevenSeas
+objectClass: top
+objectClass: organization
+o: sevenSeas
+
+dn: ou=OrgUnit1,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: OrgUnit1
+
+dn: ou=OrgUnit2,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: OrgUnit2
+
+dn: ou=OrgUnit3,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: OrgUnit3
+
+dn: ou=People,ou=OrgUnit1,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: People
+
+dn: ou=Groups,ou=OrgUnit1,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: Groups
+
+dn: ou=Roles,ou=OrgUnit1,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: Roles
+
+dn: ou=People,ou=OrgUnit2,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: People
+
+dn: ou=Groups,ou=OrgUnit2,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: Groups
+
+dn: ou=Roles,ou=OrgUnit2,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: Roles
+
+dn: ou=People,ou=OrgUnit3,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: People
+
+dn: ou=Groups,ou=OrgUnit3,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: Groups
+
+dn: ou=Roles,ou=OrgUnit3,o=sevenSeas
+objectClass: top
+objectClass: organizationalUnit
+ou: Roles
+
+dn: cn=Group1,o=sevenSeas
+objectClass: top
+objectClass: groupOfUniqueNames
+cn: Group1
+uniqueMember: cn=admin,ou=People,ou=OrgUnit1
+
+dn: cn=Group2,o=sevenSeas
+objectClass: top
+objectClass: groupOfUniqueNames
+cn: Group2
+uniqueMember: cn=admin,ou=People,ou=OrgUnit1
+
+dn: cn=Group3,o=sevenSeas
+objectClass: top
+objectClass: groupOfUniqueNames
+cn: Group3
+uniqueMember: cn=admin,ou=People,ou=OrgUnit1
+
+dn: cn=Role1,o=sevenSeas
+objectClass: top
+objectClass: groupOfUniqueNames
+cn: Role1
+description: Role 1
+uniqueMember: cn=OrgUnit2User1,ou=People,ou=OrgUnit2,o=sevenSeas
+uniqueMember: cn=jsmith,ou=People,ou=OrgUnit3,o=sevenSeas
+uniqueMember: cn=OrgUnit2User2,ou=People,ou=OrgUnit2,o=sevenSeas
+
+dn: cn=Role2,o=sevenSeas
+objectClass: top
+objectClass: groupOfUniqueNames
+cn: Role2
+uniqueMember: cn=OrgUnit2User2,ou=People,ou=OrgUnit2,o=sevenSeas
+uniqueMember: cn=OrgUnit2User1,ou=People,ou=OrgUnit2,o=sevenSeas
+
+dn: cn=Role3,o=sevenSeas
+objectClass: top
+objectClass: groupOfUniqueNames
+cn: Role3
+description: Role 3
+uniqueMember: cn=jsmith,ou=People,ou=OrgUnit3,o=sevenSeas
+
+dn: cn=admin,o=sevenSeas
+objectClass: top
+objectClass: groupOfUniqueNames
+cn: admin
+uniqueMember: uid=adminuser,o=sevenSeas
+
+dn: cn=manager,o=sevenSeas
+objectClass: top
+objectClass: groupOfUniqueNames
+cn: manager
+uniqueMember: uid=admin,ou=People,ou=OrgUnit1,o=sevenSeas
+
+dn: cn=OrgUnit1User1,ou=People,ou=OrgUnit1,o=sevenSeas
+objectClass: top
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+cn: OrgUnit1User1
+givenName: OrgUnit1User1
+sn: OrgUnit1User1
+uid: OrgUnit1User1
+userPassword:: eA==
+
+dn: cn=OrgUnit1User2,ou=People,ou=OrgUnit1,o=sevenSeas
+objectClass: top
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+cn: OrgUnit1User2
+givenName: OrgUnit1User2
+sn: OrgUnit1User2
+uid: OrgUnit1User2
+userPassword:: eA==
+
+dn: cn=OrgUnit2User1,ou=People,ou=OrgUnit2,o=sevenSeas
+objectClass: top
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+cn: OrgUnit2User1
+givenName: OrgUnit2User1
+sn: OrgUnit2User1
+uid: OrgUnit2User1
+userPassword:: eA==
+
+dn: cn=OrgUnit2User2,ou=People,ou=OrgUnit2,o=sevenSeas
+objectClass: top
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+cn: OrgUnit2User2
+givenName: OrgUnit2User2
+sn: OrgUnit2User2
+uid: OrgUnit2User2
+userPassword:: eA==
+
+dn: cn=OrgUnit3User1,ou=People,ou=OrgUnit3,o=sevenSeas
+objectClass: top
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+cn: OrgUnit3User1
+givenName: OrgUnit3User1
+sn: OrgUnit3User1
+uid: OrgUnit3User1
+userPassword:: eA==
+
+dn: cn=jsmith,ou=People,ou=OrgUnit3,o=sevenSeas
+objectClass: top
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+cn: jsmith
+givenName: Joe Smith
+sn: jsmith
+uid: jsmith
+userPassword:: eA==
+

Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java?rev=692497&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java
Fri Sep  5 10:26:17 2008
@@ -0,0 +1,152 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.ldap.setup2;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+import org.apache.jetspeed.security.mapping.ldap.AbstractLDAPTest;
+import org.apache.jetspeed.security.mapping.ldap.dao.DefaultLDAPEntityManager;
+import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO;
+import org.apache.jetspeed.security.mapping.ldap.dao.EntityRelationDAO;
+import org.apache.jetspeed.security.mapping.ldap.dao.LDAPEntityDAOConfiguration;
+import org.apache.jetspeed.security.mapping.ldap.dao.impl.AttributeBasedRelationDAO;
+import org.apache.jetspeed.security.mapping.ldap.dao.impl.SpringLDAPEntityDAO;
+import org.apache.jetspeed.security.mapping.ldap.filter.SimpleFilter;
+import org.apache.jetspeed.security.mapping.model.AttributeDef;
+import org.apache.jetspeed.security.mapping.model.impl.AttributeDefImpl;
+
+/**
+ * @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
+ */
+public abstract class AbstractSetup2LDAPTest extends AbstractLDAPTest
+{
+
+    public static final AttributeDefImpl CN_DEF = new AttributeDefImpl("cn");
+
+    public static final AttributeDefImpl UID_DEF = new AttributeDefImpl("uid");
+
+    public static final AttributeDefImpl GIVEN_NAME_DEF = new AttributeDefImpl(
+            "givenName");;
+
+    public static final AttributeDefImpl J2_ROLE_DEF = new AttributeDefImpl(
+            "j2-role",true); // multi-valued attribute
+
+    public static final AttributeDefImpl DESCRIPTION_ATTR_DEF = new AttributeDefImpl(
+            "description");
+
+    
+    protected Set<AttributeDef> userAttrDefs;
+
+    protected Set<AttributeDef> roleAttrDefs;
+
+    protected AttributeBasedRelationDAO hasRoleDAO;
+
+    public Resource[] initializationData()
+    {
+        final ClassPathResource ldapPersonInfo = new ClassPathResource(
+                "resources/setup2.ldif", getClass());
+        return new Resource[]
+        { ldapPersonInfo};
+    }
+
+    @Override
+    public void internalSetUp() throws Exception
+    {
+
+        Set<AttributeDef> basicAttrDefs = new HashSet<AttributeDef>();
+        basicAttrDefs.add(UID_DEF);
+        basicAttrDefs.add(CN_DEF);
+
+        // setting up user DAO
+        userAttrDefs = new HashSet<AttributeDef>();
+        userAttrDefs.addAll(basicAttrDefs);
+        userAttrDefs.add(GIVEN_NAME_DEF);
+        userAttrDefs.add(J2_ROLE_DEF);
+
+        userSearchConfig = new LDAPEntityDAOConfiguration();
+        userSearchConfig.setBaseDN("");
+        userSearchConfig.setBaseFilter(new SimpleFilter(
+                "(objectClass=jetspeed-2-user)"));
+        userSearchConfig.setLdapIdAttribute("uid");
+        userSearchConfig.setAttributeDefinitions(userAttrDefs);
+        userSearchConfig.setEntityType("user");
+
+        SpringLDAPEntityDAO userDAO = new SpringLDAPEntityDAO();
+        userDAO.setLdapTemplate(ldapTemplate);
+        userDAO.setConfiguration(userSearchConfig);
+
+        // setting up role DAO
+
+        roleAttrDefs = new HashSet<AttributeDef>();
+        roleAttrDefs.addAll(basicAttrDefs);
+        roleAttrDefs.add(DESCRIPTION_ATTR_DEF);
+
+        LDAPEntityDAOConfiguration roleSearchConfig = new LDAPEntityDAOConfiguration();
+        roleSearchConfig.setBaseDN("");
+        roleSearchConfig.setBaseFilter(new SimpleFilter(
+                "(objectClass=jetspeed-2-role)"));
+        roleSearchConfig.setLdapIdAttribute("uid");
+        roleSearchConfig.setAttributeDefinitions(roleAttrDefs);
+        roleSearchConfig.setEntityType("role");
+
+        SpringLDAPEntityDAO roleDAO = new SpringLDAPEntityDAO();
+        roleDAO.setLdapTemplate(ldapTemplate);
+        roleDAO.setConfiguration(roleSearchConfig);
+
+        Map<String, EntityDAO> daos = new HashMap<String, EntityDAO>();
+        daos.put("user", userDAO);
+        daos.put("role", roleDAO);
+
+        entityManager = new DefaultLDAPEntityManager();
+        entityManager.setEntityDAOs(daos);
+
+        // relation DAOs
+        Collection<EntityRelationDAO> relationDaos = new ArrayList<EntityRelationDAO>();
+
+        // hasRole relation DAO
+        // use attribute on from entity (of "user" type); user IDs are stored
+        // in the "j2-role" attribute
+        hasRoleDAO = new AttributeBasedRelationDAO();
+        hasRoleDAO.setLdapTemplate(ldapTemplate);
+        hasRoleDAO.setRelationAttribute("j2-role");
+        hasRoleDAO.setUseFromEntityAttribute(true);
+        hasRoleDAO.setRelationType("hasRole");
+        hasRoleDAO.setFromEntityType("user");
+        hasRoleDAO.setToEntityType("role");
+        hasRoleDAO.setAttributeContainsInternalId(false);
+        relationDaos.add(hasRoleDAO);
+
+        entityManager.setEntityRelationDAOs(relationDaos);
+
+    }
+
+    @Override
+    protected void internaltearDown() throws Exception
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/UserTests.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/UserTests.java?rev=692497&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/UserTests.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/UserTests.java
Fri Sep  5 10:26:17 2008
@@ -0,0 +1,69 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.ldap.setup2;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.jetspeed.security.mapping.model.Entity;
+import org.apache.jetspeed.security.mapping.model.impl.EntityImpl;
+
+
+/**
+ * @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
+ */
+
+public class UserTests extends AbstractSetup2LDAPTest
+{
+
+    public void testSingleUser() throws Exception
+    {
+        EntityImpl sampleUser = new EntityImpl("user", "someManager", userAttrDefs);
+        sampleUser
+                .setInternalId("cn=someManager, ou=People, ou=rootOrg, o=sevenSeas");
+        sampleUser.setAttribute(GIVEN_NAME_DEF.getName(), "Some Manager");
+        sampleUser.setAttribute(UID_DEF.getName(), "someManager");
+        sampleUser.setAttribute(CN_DEF.getName(), "someManager");
+        Collection<String> roles = new ArrayList<String>();
+        roles.add("manager");
+        roles.add("user");
+        sampleUser.setAttribute(J2_ROLE_DEF.getName(), roles);
+        basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
+    }
+
+    public void testFetchRolesForUserByRoleAttribute() throws Exception
+    {
+        EntityImpl managerRole = new EntityImpl("role", "manager", roleAttrDefs);
+        managerRole.setInternalId("cn=manager,ou=Roles,ou=rootOrg,o=sevenSeas");
+        managerRole.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "Manager Role");
+        managerRole.setAttribute(CN_DEF.getName(), "manager");
+        managerRole.setAttribute(UID_DEF.getName(), "manager");
+
+        EntityImpl userRole = new EntityImpl("role", "Role3", roleAttrDefs);
+        userRole.setInternalId("cn=user,ou=Roles,ou=rootOrg,o=sevenSeas");
+        userRole.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "User Role");
+        userRole.setAttribute(CN_DEF.getName(), "user");
+        userRole.setAttribute(UID_DEF.getName(), "user");
+
+        Collection<Entity> resultSet = new ArrayList<Entity>();
+        resultSet.add(managerRole);
+        resultSet.add(userRole);
+        basicTestCases.testFetchRelatedEntities("user", "role", "hasRole",
+                "someManager", resultSet);
+    }
+}

Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/resources/setup2.ldif
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/resources/setup2.ldif?rev=692497&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/resources/setup2.ldif
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/resources/setup2.ldif
Fri Sep  5 10:26:17 2008
@@ -0,0 +1,278 @@
+dn: o=sevenSeas
+objectClass: top
+objectClass: organization
+o: sevenSeas
+
+dn: ou=rootOrg,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+ou: rootOrg
+
+dn: ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+ou: People
+
+dn: ou=Groups,ou=rootOrg,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+ou: Groups
+
+dn: ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+ou: Roles
+
+dn: cn=accounting,ou=Groups,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-group
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: accounting
+j2-classname: accounting
+uid: accounting
+uniqueMember: uid=accounting
+
+dn: cn=engineering,ou=Groups,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-group
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: engineering
+j2-classname: engineering
+uid: engineering
+uniqueMember: uid=engineering
+
+dn: cn=marketing,ou=Groups,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-group
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: marketing
+j2-classname: marketing
+uid: marketing
+uniqueMember: uid=marketing
+
+dn: cn=admin,ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-role
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: admin
+j2-classname: admin
+uid: admin
+uniqueMember: uid=admin
+
+dn: cn=manager,ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-role
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: manager
+description: Manager Role
+j2-classname: manager
+uid: manager
+uniqueMember: uid=manager
+
+dn: cn=user,ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-role
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: user
+description: User Role
+j2-classname: user
+uid: user
+uniquemember: uid=user
+uniquemember: uid=admin
+uniquemember: uid=manager
+uniquemember: uid=local
+
+dn: cn=guest,ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-role
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: guest
+j2-classname: guest
+uid: guest
+uniquemember: uid=guest
+
+dn: cn=subsite,ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-role
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: subsite
+j2-classname: subsite
+uid: subsite
+uniquemember: uid=subsite
+
+dn: cn=subsite2,ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-role
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: subsite2
+j2-classname: subsite2
+uid: subsite2
+uniquemember: uid=subsite
+
+dn: cn=dev,ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-role
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: dev
+j2-classname: dev
+uid: dev
+uniquemember: uid=dev
+
+dn: cn=devmgr,ou=Roles,ou=rootOrg,o=sevenSeas
+objectClass: jetspeed-2-role
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: devmgr
+j2-classname: devmgr
+uid: devmgr
+uniquemember: uid=devmgr
+
+dn: cn=admin,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: admin
+givenname: Admin
+j2-role: admin
+j2-role: manager
+j2-role: user
+sn: admin
+uid: admin
+userpassword:: c2VjcmV0
+
+dn: cn=someManager,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: someManager
+givenname: Some Manager
+j2-role: manager
+j2-role: user
+sn: someManager
+uid: someManager
+userpassword:: c2VjcmV0
+
+dn: cn=user,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: user
+givenname: User
+j2-role: user
+sn: user
+uid: user
+userpassword:: c2VjcmV0
+
+dn: cn=local,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: local
+givenname: Local
+j2-role: user
+sn: local
+uid: local
+userpassword:: c2VjcmV0
+
+dn: cn=sublocal,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: sublocal
+givenname: sublocal
+j2-role: user
+sn: sublocal
+uid: sublocal
+userpassword:: c2VjcmV0
+
+dn: cn=tomcat,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: tomcat
+givenname: tomcat
+sn: tomcat
+uid: tomcat
+userpassword:: c2VjcmV0
+
+dn: cn=jetspeed,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: jetspeed
+givenname: jetspeed
+j2-role: manager
+sn: jetspeed
+uid: jetspeed
+userpassword:: c2VjcmV0
+
+dn: cn=guest,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: guest
+givenname: guest
+sn: guest
+uid: guest
+userpassword:: c2VjcmV0
+
+dn: cn=subsite,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: subsite
+givenname: subsite
+j2-role: subsite
+j2-role: subsite2
+j2-role: user
+sn: subsite
+uid: subsite
+userpassword:: c2VjcmV0
+
+dn: cn=subsite2,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: subsite2
+givenname: subsite2
+j2-role: subsite
+j2-role: subsite2
+j2-role: user
+sn: subsite2
+uid: subsite2
+userpassword:: c2VjcmV0
+
+dn: cn=devmgr,ou=People,ou=rootOrg,o=sevenSeas
+objectClass: organizationalPerson
+objectClass: person
+objectClass: jetspeed-2-user
+objectClass: inetOrgPerson
+objectClass: top
+cn: devmgr
+givenname: devmgr
+j2-role: devmgr
+j2-role: dev
+j2-role: user
+sn: devmgr
+uid: devmgr
+userpassword:: c2VjcmV0
\ No newline at end of file

Modified: portals/jetspeed-2/portal/branches/security-refactoring/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/pom.xml?rev=692497&r1=692496&r2=692497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/pom.xml (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/pom.xml Fri Sep  5 10:26:17 2008
@@ -319,8 +319,9 @@
     <rome.version>0.8</rome.version>
     <saxpath.version>1.0-FCS</saxpath.version>
     <spring.version>2.5.2</spring.version>
+    <spring.ldap.version>1.2.1</spring.ldap.version>
     <spring.portlet.version>2.0.6</spring.portlet.version>
-    <spring.modules.version>2.0-rc2</spring.modules.version>
+    <spring.modules.version>2.0-rc2</spring.modules.version>    
     <taglibs-random.version>1.0.2</taglibs-random.version>
     <taglibs-request.version>1.0.1</taglibs-request.version>
     <taglibs-standard.version>1.1.2</taglibs-standard.version>
@@ -619,6 +620,11 @@
         <artifactId>spring</artifactId>
         <version>${spring.version}</version>
       </dependency>
+      <dependency>      
+        <artifactId>spring-ldap</artifactId>
+        <groupId>org.springframework.ldap</groupId>
+        <version>${spring.ldap.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-portlet</artifactId>



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message