portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r450369 [3/3] - in /portals/jetspeed-2/trunk: components/security-schema/src/main/schema/ components/security/etc/ components/security/src/java/org/apache/jetspeed/security/spi/impl/ components/security/src/java/org/apache/jetspeed/security...
Date Wed, 27 Sep 2006 07:49:19 GMT
Added: portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-atz.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-atz.xml?view=auto&rev=450369
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-atz.xml
(added)
+++ portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-atz.xml
Wed Sep 27 00:49:17 2006
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<!--
+Copyright 2004 The Apache Software Foundation
+
+Licensed 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.
+-->
+<beans>
+
+  <!-- ************** Security SPI Handlers ************** -->  
+  <!-- Security SPI: RoleSecurityHandler -->
+  <bean id="org.apache.jetspeed.security.spi.RoleSecurityHandler" 
+    	   class="org.apache.jetspeed.security.spi.impl.LdapRoleSecurityHandler">  	   
+  	   <constructor-arg ><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapRoleDaoImpl"/></constructor-arg>
+  </bean>
+  
+  <!-- Security SPI: GroupSecurityHandler -->
+  <bean id="org.apache.jetspeed.security.spi.GroupSecurityHandler" 
+  	   class="org.apache.jetspeed.security.spi.impl.LdapGroupSecurityHandler"
+  >  	   
+  	   <constructor-arg ><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapGroupDaoImpl"/></constructor-arg>
+  </bean>
+
+  <bean id="org.apache.jetspeed.security.spi.impl.ldap.LdapGroupDaoImpl" 
+  	   class="org.apache.jetspeed.security.spi.impl.ldap.LdapGroupDaoImpl"
+  >  	
+  <constructor-arg ><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapBindingConfig"/></constructor-arg>
  
+  </bean>
+  
+  <bean id="org.apache.jetspeed.security.spi.impl.ldap.LdapRoleDaoImpl" 
+  	   class="org.apache.jetspeed.security.spi.impl.ldap.LdapRoleDaoImpl"
+  >  	
+  <constructor-arg ><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapBindingConfig"/></constructor-arg>
  
+  </bean>
+  
+
+  
+  <!-- Security SPI: SecurityMappingHandler -->
+  <bean id="org.apache.jetspeed.security.spi.SecurityMappingHandler" 
+    	class="org.apache.jetspeed.security.spi.impl.LdapSecurityMappingHandler"
+  >	
+  	   <constructor-arg index="0"><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao"/></constructor-arg>
  
+  	   <constructor-arg index="1"><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapGroupDaoImpl"/></constructor-arg>
  
+  	   <constructor-arg index="2"><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapRoleDaoImpl"/></constructor-arg>
+
+  	   <!-- Default role hierarchy strategy is by generalization.  Add contructor-arg to
change the strategy. -->
+  	   <!-- Default group hierarchy strategy is by generalization.  Add contructor-arg
to change the strategy. -->
+  </bean>
+  
+</beans>

Added: portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-ldap-atn.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-ldap-atn.xml?view=auto&rev=450369
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-ldap-atn.xml
(added)
+++ portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-ldap-atn.xml
Wed Sep 27 00:49:17 2006
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<!--
+Copyright 2004 The Apache Software Foundation
+
+Licensed 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.
+-->
+<beans>
+
+  <!-- ************** Security SPI Handlers ************** -->
+  <!-- Security SPI: LdapUserCredentialDao -->
+  <bean id="org.apache.jetspeed.security.spi.impl.ldap.LdapUserCredentialDao" 
+       class="org.apache.jetspeed.security.spi.impl.ldap.LdapUserCredentialDaoImpl"
+  >       
+       <constructor-arg index="0"><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapBindingConfig"/></constructor-arg>
      
+  </bean>
+  
+  <!-- Security SPI: LdapPrincipalDao -->
+  <bean id="org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao" 
+       class="org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDaoImpl"
+  >       
+       <constructor-arg index="0"><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapBindingConfig"/></constructor-arg>
      
+  </bean>
+  
+  <!-- Security SPI: CredentialHandler -->
+  <bean id="org.apache.jetspeed.security.spi.CredentialHandler" 
+       class="org.apache.jetspeed.security.spi.impl.LdapCredentialHandler"
+  >       
+       <constructor-arg ><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapUserCredentialDao"/></constructor-arg>
   
+  </bean>
+  
+  <!-- Security SPI: UserSecurityHandler -->
+  <bean id="org.apache.jetspeed.security.spi.UserSecurityHandler" 
+  	   class="org.apache.jetspeed.security.spi.impl.LdapUserSecurityHandler"
+  >  	   
+  	   <constructor-arg ><ref bean="org.apache.jetspeed.security.spi.impl.ldap.LdapUserPrincipalDao"/></constructor-arg>
	   
+  </bean>
+
+</beans>

Added: portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-ldap.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-ldap.xml?view=auto&rev=450369
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-ldap.xml
(added)
+++ portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi-ldap.xml
Wed Sep 27 00:49:17 2006
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<!--
+Copyright 2004 The Apache Software Foundation
+
+Licensed 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.
+-->
+<beans>
+
+  <!-- ************** Ldap Configuration ************** -->
+  <bean id="org.apache.jetspeed.security.spi.impl.ldap.LdapBindingConfig"
+      class="org.apache.jetspeed.security.spi.impl.ldap.LdapBindingConfig">
+      <!-- The LDAP initial context factory. -->
+      <constructor-arg index="0"><value>com.sun.jndi.ldap.LdapCtxFactory</value></constructor-arg>
+      <!-- The LDAP server name. -->
+      <constructor-arg index="1"><value>localhost</value></constructor-arg>
+      <!-- The LDAP server port. -->
+      <constructor-arg index="2"><value>389</value></constructor-arg>
+      <!-- The LDAP server default dn suffix. -->
+      <constructor-arg index="3"><value></value></constructor-arg>
+      <!-- The LDAP server root context. -->
+      <constructor-arg index="4"><value>o=sevenSeas</value></constructor-arg>
+      <!-- The LDAP server root dn. -->
+      <constructor-arg index="5"><value>cn=Directory Manager</value></constructor-arg>
+      <!-- The LDAP server root password. -->
+      <constructor-arg index="6"><value>adminmanager</value></constructor-arg>
+      <!-- The roles filter. -->
+      <constructor-arg index="7"><value>(&amp;(objectclass=ldapsubentry)
(objectclass=nsroledefinition))</value></constructor-arg>
+      <!-- The groups filter. -->
+      <constructor-arg index="8"><value>(objectClass=groupOfUniqueNames)</value></constructor-arg>
+      <!-- The user filter. -->
+      <constructor-arg index="9"><value>(objectclass=inetorgperson)</value></constructor-arg>
+      <!-- The userAuthenticationFiler. -->
+      <constructor-arg index="10"><value>(&amp;(uid=%u)(objectclass=inetorgperson))</value></constructor-arg>
+      <!-- The roleMembershipAttributes. -->
+      <constructor-arg index="11"><value></value></constructor-arg>
+      <!-- The userRoleMembershipAttributes. -->
+      <constructor-arg index="12"><value>nsroledn</value></constructor-arg>
+      <!-- The groupMembershipAttributes. -->
+      <constructor-arg index="13"><value>uniqueMember</value></constructor-arg>
+      <!-- The userGroupMembershipAttributes. -->
+      <constructor-arg index="14"><value></value></constructor-arg>
+      <!-- The groupMembershipForRoleAttributes. -->
+      <constructor-arg index="15"><value>uniqueMember</value></constructor-arg>
+      <!-- The roleGroupMembershipForRoleAttributes. -->
+      <constructor-arg index="16"><value></value></constructor-arg>
     
+           <!-- The defaultSearchBase. -->
+      <constructor-arg index="17"><value>o=sevenSeas</value></constructor-arg>
+      <!-- The roleFilterBase. -->
+      <constructor-arg index="18"><value></value></constructor-arg>
+      <!-- The groupFilterBase. -->
+      <constructor-arg index="19"><value></value></constructor-arg>
+      <!-- The userFilterBase. -->
+      <constructor-arg index="20"><value>ou=People,ou=OrgUnit1</value></constructor-arg>
+
+      <!-- The roleObjectClasses. -->
+      <constructor-arg index="21"><value>top,ldapsubentry,nsroledefinition,nssimpleroledefinition,nsmanagedroledefinition</value></constructor-arg>
+      <!-- The groupObjectClasses. -->
+      <constructor-arg index="22"><value>top,groupofuniquenames</value></constructor-arg>
+      <!-- The userObjectClasses. -->
+      <constructor-arg index="23"><value>top,person,organizationalPerson,inetorgperson</value></constructor-arg>
+
+
+      <!-- The roleIdAttribute. -->
+      <constructor-arg index="24"><value>cn</value></constructor-arg>
+      <!-- The groupIdAttribute. -->
+      <constructor-arg index="25"><value>cn</value></constructor-arg>
+	  <!-- The userIdAttribute. -->
+      <constructor-arg index="26"><value>uid</value></constructor-arg>
+      
+  </bean>
+
+</beans>

Added: portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi.xml?view=auto&rev=450369
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi.xml
(added)
+++ portals/jetspeed-2/trunk/components/security/src/test/JETSPEED-INF/directory/config/sunds/security-spi.xml
Wed Sep 27 00:49:17 2006
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<!--
+Copyright 2004 The Apache Software Foundation
+
+Licensed 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.
+-->
+<beans>
+
+  <!-- ************** Security SPI Handlers ************** -->
+  <!-- Security SPI: CommonQueries -->
+  <bean id="org.apache.jetspeed.security.spi.impl.SecurityAccessImpl" 
+  	   class="org.apache.jetspeed.security.spi.impl.SecurityAccessImpl"
+  	   init-method="init"
+  >  	   
+  	   <constructor-arg ><value>JETSPEED-INF/ojb/security_repository.xml</value></constructor-arg>
 	   
+  </bean>
+  
+  <bean id="org.apache.jetspeed.security.spi.SecurityAccess" parent="baseTransactionProxy"

+		name="SecurityCommonQueries" >
+		<property name="proxyInterfaces">
+			<value>org.apache.jetspeed.security.spi.SecurityAccess</value>
+		</property>
+		<property name="target">
+			<ref bean="org.apache.jetspeed.security.spi.impl.SecurityAccessImpl"/>
+		</property>
+		<property name="transactionAttributes">
+			<props>				
+				<prop key="remove*">PROPAGATION_REQUIRED</prop>
+				<prop key="set*">PROPAGATION_REQUIRED</prop>
+				<prop key="*">PROPAGATION_SUPPORTS</prop>
+			</props>
+		</property>
+   </bean>
+
+</beans>

Modified: portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/AbstractLdapTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/AbstractLdapTest.java?view=diff&rev=450369&r1=450368&r2=450369
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/AbstractLdapTest.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/AbstractLdapTest.java
Wed Sep 27 00:49:17 2006
@@ -30,6 +30,8 @@
 import org.apache.jetspeed.security.spi.impl.LdapUserSecurityHandler;
 import org.apache.jetspeed.security.spi.impl.ldap.LdapBindingConfig;
 import org.apache.jetspeed.security.spi.impl.ldap.LdapGroupDaoImpl;
+import org.apache.jetspeed.security.spi.impl.ldap.LdapMemberShipDaoImpl;
+import org.apache.jetspeed.security.spi.impl.ldap.LdapMembershipDao;
 import org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDao;
 import org.apache.jetspeed.security.spi.impl.ldap.LdapRoleDaoImpl;
 import org.apache.jetspeed.security.spi.impl.ldap.LdapUserCredentialDao;
@@ -73,27 +75,29 @@
     
     /** The {@link LdapGroupDao}. */
     LdapPrincipalDao ldapRoleDao;    
+    
+    LdapMembershipDao ldapMembershipDao;
 
     /** Random seed. */
     Random rand = new Random(System.currentTimeMillis());
 
     /** Group uid. */
-    protected String gpUid1;
+    protected String gpUid1 = "group1";
 
     /** Group uid. */
-    protected String gpUid2;
+    protected String gpUid2 = "group2";
     
     /** Role uid. */
-    protected String roleUid1;
+    protected String roleUid1 = "role1";
 
     /** Role uid. */
-    protected String roleUid2;    
+    protected String roleUid2 = "role2";    
 
     /** User uid. */
-    protected String uid1;
+    protected String uid1 = "user1";
 
     /** User uid. */
-    protected String uid2;
+    protected String uid2 = "user2";
 
     /** The test password. */
     protected String password = "fred";
@@ -104,7 +108,7 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-        LdapBindingConfig ldapConfig = new LdapBindingConfig();
+        LdapBindingConfig ldapConfig = new LdapBindingConfig("apacheds");
         ldapCredDao = new LdapUserCredentialDaoImpl(ldapConfig);
         ldapPrincipalDao = new LdapUserPrincipalDaoImpl(ldapConfig);
 
@@ -112,20 +116,21 @@
         crHandler = new LdapCredentialHandler(ldapCredDao);
         LdapDataHelper.setUserSecurityHandler(userHandler);
         LdapDataHelper.setCredentialHandler(crHandler);
-        uid1 = Integer.toString(rand.nextInt());
-        uid2 = Integer.toString(rand.nextInt());
+//        uid1 = Integer.toString(rand.nextInt());
+//        uid2 = Integer.toString(rand.nextInt());
         
         ldapGroupDao = new LdapGroupDaoImpl(ldapConfig);
         ldapRoleDao = new LdapRoleDaoImpl(ldapConfig);
+        ldapMembershipDao = new LdapMemberShipDaoImpl(ldapConfig);
         grHandler = new LdapGroupSecurityHandler(ldapGroupDao);
         roleHandler = new LdapRoleSecurityHandler(ldapRoleDao);
         LdapDataHelper.setGroupSecurityHandler(grHandler);
         LdapDataHelper.setRoleSecurityHandler(roleHandler);
-        gpUid1 = Integer.toString(rand.nextInt());
-        gpUid2 = Integer.toString(rand.nextInt());
-        
-        roleUid1 = Integer.toString(rand.nextInt());
-        roleUid2 = Integer.toString(rand.nextInt());        
+//        gpUid1 = Integer.toString(rand.nextInt());
+//        gpUid2 = Integer.toString(rand.nextInt());
+//        
+//        roleUid1 = Integer.toString(rand.nextInt());
+//        roleUid2 = Integer.toString(rand.nextInt());        
         
         secHandler = new LdapSecurityMappingHandler(ldapPrincipalDao, ldapGroupDao, ldapRoleDao);
     }

Modified: portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapGroupSecurityHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapGroupSecurityHandler.java?view=diff&rev=450369&r1=450368&r2=450369
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapGroupSecurityHandler.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapGroupSecurityHandler.java
Wed Sep 27 00:49:17 2006
@@ -51,7 +51,11 @@
     public void testGetGroupPrincipal() throws Exception
     {
         String fullPath = (new GroupPrincipalImpl(gpUid1)).getFullPath();
-        assertNotNull("Group was not found.", grHandler.getGroupPrincipal(fullPath));
+        //GroupPrincipal groupPrincipal = grHandler.getGroupPrincipal(fullPath);
+        GroupPrincipal groupPrincipal = grHandler.getGroupPrincipal(gpUid1);
+        assertNotNull("Group was not found.", groupPrincipal);
+        assertEquals(gpUid1,groupPrincipal.getName());
+        assertEquals(fullPath,groupPrincipal.getFullPath());
     }
 
     /**
@@ -60,6 +64,17 @@
     public void testAddDuplicateGroupPrincipal() throws Exception
     {
         grHandler.setGroupPrincipal(new GroupPrincipalImpl(gpUid1));
+        List groups = grHandler.getGroupPrincipals("");
+        assertEquals(1,groups.size());
+    }
+    
+    /**
+     * @throws Exception
+     */
+    public void testGetNonExistingGroupPrincipal() throws Exception
+    {
+        GroupPrincipal group = grHandler.getGroupPrincipal(gpUid1 + "FAKE");
+        assertNull(group);
     }
 
     /**
@@ -69,7 +84,10 @@
     {
         GroupPrincipal gp = new GroupPrincipalImpl(gpUid1);
         grHandler.removeGroupPrincipal(gp);
-        assertNull("Group was found and should have been removed.", grHandler.getGroupPrincipal(gp.getFullPath()));
+        GroupPrincipal groupPrincipal = grHandler.getGroupPrincipal(gp.getFullPath());
+        assertNull("Group was found and should have been removed.", groupPrincipal);
+        List groups = grHandler.getGroupPrincipals("");
+        assertEquals(0,groups.size());        
     }
 
     /**
@@ -79,8 +97,9 @@
     {
         String localUid = Integer.toString(rand.nextInt()).toString();
         GroupPrincipal localPrin = new GroupPrincipalImpl(localUid);
-
         grHandler.removeGroupPrincipal(localPrin);
+        List groups = grHandler.getGroupPrincipals("");
+        assertEquals(1,groups.size());
     }
 
     /**

Added: portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapRoleSecurityHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapRoleSecurityHandler.java?view=auto&rev=450369
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapRoleSecurityHandler.java
(added)
+++ portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapRoleSecurityHandler.java
Wed Sep 27 00:49:17 2006
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ *
+ * Licensed 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.spi.ldap;
+
+import java.util.List;
+
+import org.apache.jetspeed.security.RolePrincipal;
+import org.apache.jetspeed.security.impl.RolePrincipalImpl;
+
+/**
+ * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>, <a
+ *         href="mailto:dlestrat@apache.org">David Le Strat</a>
+ */
+public class TestLdapRoleSecurityHandler extends AbstractLdapTest
+{
+
+    /**
+     * @see org.apache.jetspeed.security.spi.ldap.AbstractLdapTest#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        LdapDataHelper.seedRoleData(roleUid1);
+    }
+
+    /**
+     * @see org.apache.jetspeed.security.spi.ldap.AbstractLdapTest#tearDown()
+     */
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        LdapDataHelper.removeRoleData(roleUid1);
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testGetRolePrincipal() throws Exception
+    {
+        String fullPath = (new RolePrincipalImpl(roleUid1)).getFullPath();
+        //RolePrincipal rolePrincipal = grHandler.getRolePrincipal(fullPath);
+        RolePrincipal rolePrincipal = roleHandler.getRolePrincipal(roleUid1);
+        assertNotNull("Role was not found.", rolePrincipal);
+        assertEquals(roleUid1,rolePrincipal.getName());
+        assertEquals(fullPath,rolePrincipal.getFullPath());
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testAddDuplicateRolePrincipal() throws Exception
+    {
+    	roleHandler.setRolePrincipal(new RolePrincipalImpl(roleUid1));
+        List roles = roleHandler.getRolePrincipals("");
+        assertEquals(1,roles.size());
+    }
+    
+    /**
+     * @throws Exception
+     */
+    public void testGetNonExistingRolePrincipal() throws Exception
+    {
+        RolePrincipal role = roleHandler.getRolePrincipal(roleUid1 + "FAKE");
+        assertNull(role);
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testRemoveExistantUserPrincipal() throws Exception
+    {
+        RolePrincipal gp = new RolePrincipalImpl(roleUid1);
+        roleHandler.removeRolePrincipal(gp);
+        RolePrincipal rolePrincipal = roleHandler.getRolePrincipal(gp.getFullPath());
+        assertNull("Role was found and should have been removed.", rolePrincipal);
+        List roles = roleHandler.getRolePrincipals("");
+        assertEquals(0,roles.size());        
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testRemoveNonExistantUserPrincipal() throws Exception
+    {
+        String localUid = Integer.toString(rand.nextInt()).toString();
+        RolePrincipal localPrin = new RolePrincipalImpl(localUid);
+        roleHandler.removeRolePrincipal(localPrin);
+        List roles = roleHandler.getRolePrincipals("");
+        assertEquals(1,roles.size());
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testGetRolePrincipals() throws Exception
+    {
+        try
+        {
+            LdapDataHelper.seedRoleData(gpUid2);
+            assertTrue("getUserPrincipals should have returned more than one user.", roleHandler.getRolePrincipals("*")
+                    .size() > 1);
+
+            String fullPath = (new RolePrincipalImpl(roleUid1)).getFullPath();
+            List roles = roleHandler.getRolePrincipals(fullPath);
+            assertTrue("getRolePrincipals should have returned one role.", roles.size() ==
1);
+            assertTrue("List should have consisted of RolePrincipal objects.", roles.get(0)
instanceof RolePrincipal);
+
+            String localUid = Integer.toString(rand.nextInt()).toString();
+            assertTrue("getRolePrincipals should not have found any roles with the specified
filter.", roleHandler
+                    .getRolePrincipals(new RolePrincipalImpl(localUid).getFullPath()).isEmpty());
+        }
+        finally
+        {
+            LdapDataHelper.removeRoleData(gpUid2);
+        }
+    }
+
+}

Modified: portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapSecurityMappingHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapSecurityMappingHandler.java?view=diff&rev=450369&r1=450368&r2=450369
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapSecurityMappingHandler.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/spi/ldap/TestLdapSecurityMappingHandler.java
Wed Sep 27 00:49:17 2006
@@ -16,6 +16,8 @@
 package org.apache.jetspeed.security.spi.ldap;
 
 
+import java.util.Set;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.security.GroupPrincipal;
@@ -23,6 +25,7 @@
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.impl.GroupPrincipalImpl;
 import org.apache.jetspeed.security.impl.RolePrincipalImpl;
+import org.apache.jetspeed.security.impl.UserPrincipalImpl;
 import org.apache.jetspeed.security.spi.SecurityMappingHandler;
 
 /**
@@ -79,6 +82,8 @@
         LdapDataHelper.removeGroupData(gpUid2);
         LdapDataHelper.removeUserData(uid1);
         LdapDataHelper.removeUserData(uid2);
+        LdapDataHelper.removeRoleData(roleUid1);
+        LdapDataHelper.removeRoleData(roleUid2);
     }
 
     /**
@@ -90,12 +95,18 @@
     {
         secHandler.setUserPrincipalInGroup(uid1, gp1.getName());
         secHandler.setUserPrincipalInGroup(uid2, gp1.getName());
-
         String fullPathName = new GroupPrincipalImpl(gpUid1).getName();
         logger.debug("Group full path name from testGetUserPrincipalsInGroup()[" + fullPathName
+ "]");
-        assertEquals("The user should have been in two groups.", 2, secHandler.getUserPrincipalsInGroup(fullPathName)
-                .size());
+        Set userPrincipals = secHandler.getUserPrincipalsInGroup(fullPathName);
+        //assertTrue(userPrincipals.contains(new UserPrincipalImpl("uid=" + uid1 + ",ou=People,ou=OrgUnit1")));
+        //assertTrue(userPrincipals.contains(new UserPrincipalImpl("uid=" + uid2 + ",ou=People,ou=OrgUnit1")));
+        assertTrue(userPrincipals.contains(new UserPrincipalImpl(uid1)));
+        assertTrue(userPrincipals.contains(new UserPrincipalImpl(uid2)));
+        
+        assertEquals("The user should have been in two groups.", 2, userPrincipals.size());
     }
+    
+
 
     /**
      * Adds 1 user to 2 groups, and checks its presence in both groups
@@ -109,6 +120,19 @@
         assertEquals("The user should have been in two groups.", 2, secHandler.getGroupPrincipals(uid1).size());
         
     }
+    
+
+    /**
+     * Adds 1 user to 2 groups, and checks its presence in both groups
+     * @throws Exception
+     */
+    public void testGetUserPrincipalInGroup() throws Exception
+    {
+        secHandler.setUserPrincipalInGroup(uid1, gp1.getName());
+        secHandler.setUserPrincipalInGroup(uid1, gp2.getName());
+        secHandler.setUserPrincipalInRole(uid1, ro1.getName());
+        assertEquals(2, secHandler.getGroupPrincipals(uid1).size());
+    }    
 
     /**
      * @throws Exception
@@ -175,9 +199,49 @@
 
         String fullPathName = new RolePrincipalImpl(roleUid1).getName();
         logger.debug("Role full path name from testGetUserPrincipalsInRole()[" + fullPathName
+ "]");
-        assertEquals("The user should have been in two roles.", 2, secHandler.getUserPrincipalsInRole(fullPathName)
-                .size());
+        Set userPrincipals = secHandler.getUserPrincipalsInRole(fullPathName);
+        assertTrue(userPrincipals.contains(new UserPrincipalImpl(uid1)));
+        assertTrue(userPrincipals.contains(new UserPrincipalImpl(uid2)));
+        assertEquals("The user should have been in two roles.", 2, userPrincipals.size());
     }
+    
+    /**
+     * Adds 2 users to a group and checks their presence in the group
+     * 
+     * @throws Exception
+     */
+    public void testGetRolePrincipalInGroup() throws Exception
+    {
+        secHandler.setRolePrincipalInGroup(gpUid1, ro1.getName());
+        secHandler.setRolePrincipalInGroup(gpUid1, ro2.getName());
+        secHandler.setRolePrincipalInGroup(gpUid2, ro1.getName());
+
+
+        String fullPathName = new RolePrincipalImpl(roleUid1).getName();
+        logger.debug("Role full path name from testGetUserPrincipalsInRole()[" + fullPathName
+ "]");
+        assertEquals("The group should have 2 roles.", 2, secHandler.getRolePrincipalsInGroup(gpUid1).size());
+        assertEquals("The group should have 1 role.", 1, secHandler.getRolePrincipalsInGroup(gpUid2).size());
+    } 
+    
+    /**
+     * Adds 2 users to a group and checks their presence in the group
+     * 
+     * @throws Exception
+     */
+    public void testGetRolePrincipalInGroup2() throws Exception
+    {
+        secHandler.setRolePrincipalInGroup(gpUid1, ro1.getName());
+        secHandler.setRolePrincipalInGroup(gpUid2, ro1.getName());
+        secHandler.setUserPrincipalInRole(uid1, ro1.getName());
+        secHandler.setUserPrincipalInRole(uid1, ro2.getName());
+        String fullPathName = new RolePrincipalImpl(gpUid1).getName();
+        logger.debug("Role full path name from testGetUserPrincipalsInRole()[" + fullPathName
+ "]");
+        assertEquals("The group should have contained 1 role.", 1, secHandler.getRolePrincipalsInGroup(gpUid1)
+                .size());
+        assertEquals("The group should have contained 1 role.", 1, secHandler.getRolePrincipalsInGroup(gpUid1)
+                .size());
+        
+    }     
 
     /**
      * Adds 1 user to 2 roles, and checks its presence in both roles
@@ -187,10 +251,28 @@
     {
         secHandler.setUserPrincipalInRole(uid1, ro1.getName());
         secHandler.setUserPrincipalInRole(uid1, ro2.getName());
-
-        assertEquals("The user should have been in two roles.", 2, secHandler.getRolePrincipals(uid1).size());
+        Set rolePrinciples = secHandler.getRolePrincipals(uid1);
+        assertEquals("The user should have been in two roles.", 2, rolePrinciples.size());
+        assertTrue(rolePrinciples.contains(ro1));
+        assertTrue(rolePrinciples.contains(ro2));
         
     }
+    
+    /**
+     * Adds 1 user to 2 roles & 1 group, and checks its presence in both roles
+     * @throws Exception
+     */
+    public void testSetUserPrincipalInRole2() throws Exception
+    {
+        secHandler.setUserPrincipalInRole(uid1, ro1.getName());
+        secHandler.setUserPrincipalInRole(uid1, ro2.getName());
+        secHandler.setUserPrincipalInGroup(uid1, gp1.getName());
+        Set rolePrinciples = secHandler.getRolePrincipals(uid1);
+        assertEquals("The user should have been in two roles.", 2, rolePrinciples.size());
+        assertTrue(rolePrinciples.contains(ro1));
+        assertTrue(rolePrinciples.contains(ro2));
+        
+    }    
 
     /**
      * @throws Exception
@@ -208,6 +290,8 @@
         secHandler.removeUserPrincipalInRole(uid1, ro2.getName());
         assertEquals("The user should have been in two roles.", 0, secHandler.getRolePrincipals(uid1).size());
     }
+    
+   
 
     /**
      * @throws Exception

Modified: portals/jetspeed-2/trunk/etc/apacheds/apacheds-server.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/etc/apacheds/apacheds-server.xml?view=diff&rev=450369&r1=450368&r2=450369
==============================================================================
--- portals/jetspeed-2/trunk/etc/apacheds/apacheds-server.xml (original)
+++ portals/jetspeed-2/trunk/etc/apacheds/apacheds-server.xml Wed Sep 27 00:49:17 2006
@@ -68,7 +68,6 @@
         <bean class="org.apache.ldap.server.schema.bootstrap.NisSchema"/>
         <bean class="org.apache.ldap.server.schema.bootstrap.SystemSchema"/>
         <bean class="org.apache.ldap.server.schema.bootstrap.ApachednsSchema"/>
-        <bean class="org.apache.jetspeed.security.ldap.JetspeedSchema"/>
       </set>
     </property>
     

Modified: portals/jetspeed-2/trunk/maven-plugin/plugin.jelly
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/maven-plugin/plugin.jelly?view=diff&rev=450369&r1=450368&r2=450369
==============================================================================
--- portals/jetspeed-2/trunk/maven-plugin/plugin.jelly (original)
+++ portals/jetspeed-2/trunk/maven-plugin/plugin.jelly Wed Sep 27 00:49:17 2006
@@ -829,7 +829,7 @@
       <arg value="-silent"/>
       <arg value="true"/>
       <arg value="-trace"/>
-      <arg value="false"/>
+      <arg value="true"/>
     </java>
   </goal>
     
@@ -923,7 +923,6 @@
     <echo file="target/apacheds/logs/apacheds.log">${maven.start.ldap.message}</echo>
     <java classname="org.apache.ldap.server.ServerMain" fork="yes">
       <classpath>
-        <pathelement path="${maven.repo.local}/${plugin.groupId}/jars/jetspeed-security-schema-${jetspeed.version}.jar"/>
         <pathelement path="${plugin.getDependencyPath('directory:apacheds-main')}"/>
       </classpath>
       <arg value="${org.apache.jetspeed.plugin.ldap.conf}"/>



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