@Inject
private LdapController ldapController;
+ @Inject
+ @Named( value = "cache#ldapRoles" )
+ private Cache<String, Role> rolesCache;
+
private boolean writableLdap = false;
+
@PostConstruct
public void initialize()
{
throws RbacManagerException
{
+ Role role = rolesCache.get( roleName );
+ if ( role != null )
+ {
+ return role;
+ }
LdapConnection ldapConnection = null;
DirContext context = null;
//verify it's a ldap group
{
throw new RbacManagerException( e.getMessage(), e );
}
- Role role = this.rbacImpl.getRole( roleName );
- return ( role == null ) ? new RoleImpl( roleName ) : role;
+ role = this.rbacImpl.getRole( roleName );
+ role = ( role == null ) ? new RoleImpl( roleName ) : role;
+
+ rolesCache.put( roleName, role );
+ return role;
}
public Map<String, Role> getRoles( Collection<String> roleNames )
{
throw new RbacPermanentException( "Unable to delete permanent role [" + role.getName() + "]" );
}
+ rolesCache.remove( role.getName() );
if ( writableLdap )
{
LdapConnection ldapConnection = null;
{
return false;
}
+ if ( rolesCache.get( name ) != null )
+ {
+ return true;
+ }
LdapConnection ldapConnection = null;
DirContext context = null;
try
{
ldapConnection = ldapConnectionFactory.getConnection();
context = ldapConnection.getDirContext();
+ if ( rolesCache.hasKey( name ) )
+ {
+ return true;
+ }
return ldapRoleMapper.hasRole( context, name );
}
catch ( MappingException e )
ldapConnection = ldapConnectionFactory.getConnection();
context = ldapConnection.getDirContext();
ldapRoleMapper.saveRole( role.getName(), context );
+
if ( !role.getChildRoleNames().isEmpty() )
{
for ( String roleName : role.getChildRoleNames() )
throw new RbacManagerException( e.getMessage(), e );
}
}
- return this.rbacImpl.saveRole( role );
+ role = this.rbacImpl.saveRole( role );
+ rolesCache.put( role.getName(), role );
+
+ return role;
//return new RoleImpl( role.getName(), role.getPermissions() );
}
<context:component-scan
base-package="org.apache.archiva.redback.rbac.ldap"/>
+ <bean name="cache#ldapRoles" 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="ldapRoles"/>
+ <property name="timeToIdleSeconds" value="300"/>
+ <property name="timeToLiveSeconds" value="600"/>
+ </bean>
+
</beans>
\ No newline at end of file