private String groupsDn;
+ private String baseDn;
+
@PostConstruct
public void initialize()
{
this.ldapGroupClass = userConf.getString( UserConfigurationKeys.LDAP_GROUPS_CLASS, this.ldapGroupClass );
this.groupsDn = userConf.getString( UserConfigurationKeys.LDAP_GROUPS_BASEDN, this.groupsDn );
+
+ this.baseDn = userConf.getString( UserConfigurationKeys.LDAP_BASEDN, this.baseDn );
}
public String getLdapGroup( String role )
throws MappingException
{
// TODO caching and a filter with uid
+
List<String> allGroups = getAllGroups();
List<String> userGroups = new ArrayList<String>();
for ( String group : allGroups )
}
}
return userGroups;
+ /*
+ List<String> userGroups = new ArrayList<String>();
+
+ LdapConnection ldapConnection = null;
+
+ NamingEnumeration<SearchResult> namingEnumeration = null;
+ try
+ {
+ ldapConnection = ldapConnectionFactory.getConnection();
+
+ DirContext context = ldapConnection.getDirContext();
+
+ SearchControls searchControls = new SearchControls();
+
+ searchControls.setDerefLinkFlag( true );
+ searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+
+ //String filter =
+ // "(&(objectClass=" + getLdapGroupClass() + ") (uniquemember=uid" + username + "," + this.getGroupsDn()
+ // + "))";
+
+ String filter =
+ new StringBuilder().append( "(&" ).append( "(objectClass=" + getLdapGroupClass() + ")" ).append(
+ "(uniquemember=" ).append( "uid=" + username + "," + this.getBaseDn() ).append( ")" ).append(
+ ")" ).toString();
+
+ namingEnumeration = context.search( getGroupsDn(), filter, searchControls );
+
+ List<String> allMembers = new ArrayList<String>();
+
+ while ( namingEnumeration.hasMore() )
+ {
+ SearchResult searchResult = namingEnumeration.next();
+
+ Attribute uniqueMemberAttr = searchResult.getAttributes().get( "uniquemember" );
+
+ if ( uniqueMemberAttr != null )
+ {
+ NamingEnumeration<String> allMembersEnum = (NamingEnumeration<String>) uniqueMemberAttr.getAll();
+ while ( allMembersEnum.hasMore() )
+ {
+ String userName = allMembersEnum.next();
+ // uid=blabla we only want bla bla
+ userName = StringUtils.substringAfter( userName, "=" );
+ userName = StringUtils.substringBefore( userName, "," );
+ //log.debug( "found group for username {}: '{}", group, userName );
+
+ allMembers.add( userName );
+ }
+ close( allMembersEnum );
+ }
+
+
+ }
+
+ return userGroups;
+ }
+ catch ( LdapException e )
+ {
+ throw new MappingException( e.getMessage(), e );
+ }
+ catch ( NamingException e )
+ {
+ throw new MappingException( e.getMessage(), e );
+ }
+
+ finally
+ {
+ if ( ldapConnection != null )
+ {
+ ldapConnection.close();
+ }
+ close( namingEnumeration );
+ }
+ */
}
private void close( NamingEnumeration namingEnumeration )
{
this.ldapConnectionFactory = ldapConnectionFactory;
}
+
+ public String getBaseDn()
+ {
+ return baseDn;
+ }
+
+ public void setBaseDn( String baseDn )
+ {
+ this.baseDn = baseDn;
+ }
}
<context:component-scan
base-package="org.apache.archiva.redback.rbac.ldap"/>
- <bean name="cache#operations" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
- init-method="initialize">
- <property name="diskPersistent" value="false"/>
- <property name="eternal" value="false"/>
- <property name="maxElementsInMemory" value="1000"/>
- <property name="memoryEvictionPolicy" value="LRU"/>
- <property name="name" value="operations"/>
- <property name="timeToIdleSeconds" value="1800"/>
- <property name="timeToLiveSeconds" value="14400"/>
- </bean>
- <bean name="cache#permissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
- init-method="initialize">
- <property name="diskPersistent" value="false"/>
- <property name="eternal" value="false"/>
- <property name="maxElementsInMemory" value="1000"/>
- <property name="memoryEvictionPolicy" value="LRU"/>
- <property name="name" value="permissions"/>
- <property name="timeToIdleSeconds" value="1800"/>
- <property name="timeToLiveSeconds" value="14400"/>
- </bean>
-
- <bean name="cache#resources" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
- init-method="initialize">
- <property name="diskPersistent" value="false"/>
- <property name="eternal" value="false"/>
- <property name="maxElementsInMemory" value="1000"/>
- <property name="memoryEvictionPolicy" value="LRU"/>
- <property name="name" value="resources"/>
- <property name="timeToIdleSeconds" value="1800"/>
- <property name="timeToLiveSeconds" value="14400"/>
- </bean>
-
- <bean name="cache#roles" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
- init-method="initialize">
- <property name="diskPersistent" value="false"/>
- <property name="eternal" value="false"/>
- <property name="maxElementsInMemory" value="1000"/>
- <property name="memoryEvictionPolicy" value="LRU"/>
- <property name="name" value="roles"/>
- <property name="timeToIdleSeconds" value="1800"/>
- <property name="timeToLiveSeconds" value="14400"/>
- </bean>
-
- <bean name="cache#effectiveRoleSet" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
- init-method="initialize">
- <property name="diskPersistent" value="false"/>
- <property name="eternal" value="false"/>
- <property name="maxElementsInMemory" value="1000"/>
- <property name="memoryEvictionPolicy" value="LRU"/>
- <property name="name" value="effectiveRoleSet"/>
- <property name="timeToIdleSeconds" value="1800"/>
- <property name="timeToLiveSeconds" value="14400"/>
- </bean>
-
- <!-- ================================================================
- Caches with Short Term entries
- ================================================================ -->
-
- <bean name="cache#userAssignments" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
- init-method="initialize">
- <property name="diskPersistent" value="false"/>
- <property name="eternal" value="false"/>
- <property name="maxElementsInMemory" value="1000"/>
- <property name="memoryEvictionPolicy" value="LRU"/>
- <property name="name" value="userAssignments"/>
- <property name="timeToIdleSeconds" value="300"/>
- <property name="timeToLiveSeconds" value="600"/>
- </bean>
-
- <bean name="cache#userPermissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
- init-method="initialize">
- <property name="diskPersistent" value="false"/>
- <property name="eternal" value="false"/>
- <property name="maxElementsInMemory" value="1000"/>
- <property name="memoryEvictionPolicy" value="LRU"/>
- <property name="name" value="userPermissions"/>
- <property name="timeToIdleSeconds" value="300"/>
- <property name="timeToLiveSeconds" value="600"/>
- </bean>
</beans>
\ No newline at end of file
import javax.inject.Inject;
import javax.inject.Named;
+import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
passwordEncoder = new SHA1PasswordEncoder();
- groupSuffix = "dc=archiva,dc=apache,dc=org";
+ groupSuffix = apacheDs.addSimplePartition( "test", new String[]{ "archiva", "apache", "org" } ).getSuffix();
+
log.info( "groupSuffix: {}", groupSuffix );
- suffix = apacheDs.addSimplePartition( "test", new String[]{ "archiva", "apache", "org" } ).getSuffix();
+ suffix = "ou=People,dc=archiva,dc=apache,dc=org";
log.info( "DN Suffix: {}", suffix );
apacheDs.startServer();
+ BasicAttribute objectClass = new BasicAttribute( "objectClass" );
+ objectClass.add( "top" );
+ objectClass.add( "organizationalUnit" );
+
+ Attributes attributes = new BasicAttributes( true );
+ attributes.put( objectClass );
+ attributes.put( "organizationalUnitName", "foo" );
+ //attributes.put( "ou", "People" );
+
+ apacheDs.getAdminContext().createSubcontext( suffix, attributes );
+
clearManyUsers();
makeUsers();
context.unbind( createGroupDn( group.getKey() ) );
}
+ context.unbind( suffix );
+
apacheDs.stopServer();
super.tearDown();
<bean name="ldapRoleMapper#test" class="org.apache.archiva.redback.rbac.ldap.DefaultLdapRoleMapper">
<property name="groupsDn" value="dc=archiva,dc=apache,dc=org"/>
<property name="ldapGroupClass" value="groupOfUniqueNames"/>
+ <property name="baseDn" value="ou=People,dc=archiva,dc=apache,dc=org"/>
<property name="ldapConnectionFactory" ref="ldapConnectionFactory#configurable"/>
<property name="userConf" ref="userConfiguration#default"/>
</bean>
+
+
+
+
+
+
+ <bean name="cache#operations" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="operations"/>
+ <property name="timeToIdleSeconds" value="1800"/>
+ <property name="timeToLiveSeconds" value="14400"/>
+ </bean>
+
+ <bean name="cache#permissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="permissions"/>
+ <property name="timeToIdleSeconds" value="1800"/>
+ <property name="timeToLiveSeconds" value="14400"/>
+ </bean>
+
+ <bean name="cache#resources" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="resources"/>
+ <property name="timeToIdleSeconds" value="1800"/>
+ <property name="timeToLiveSeconds" value="14400"/>
+ </bean>
+
+ <bean name="cache#roles" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="roles"/>
+ <property name="timeToIdleSeconds" value="1800"/>
+ <property name="timeToLiveSeconds" value="14400"/>
+ </bean>
+
+ <bean name="cache#effectiveRoleSet" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="effectiveRoleSet"/>
+ <property name="timeToIdleSeconds" value="1800"/>
+ <property name="timeToLiveSeconds" value="14400"/>
+ </bean>
+
+ <!-- ================================================================
+ Caches with Short Term entries
+ ================================================================ -->
+
+ <bean name="cache#userAssignments" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="userAssignments"/>
+ <property name="timeToIdleSeconds" value="300"/>
+ <property name="timeToLiveSeconds" value="600"/>
+ </bean>
+
+ <bean name="cache#userPermissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="userPermissions"/>
+ <property name="timeToIdleSeconds" value="300"/>
+ <property name="timeToLiveSeconds" value="600"/>
+ </bean>
+
</beans>
\ No newline at end of file