]> source.dussan.org Git - archiva.git/commitdiff
add some caching for userAssignement in LdapRbacManager
authorOlivier Lamy <olamy@apache.org>
Wed, 23 Jan 2013 10:31:19 +0000 (10:31 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 23 Jan 2013 10:31:19 +0000 (10:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1437326 13f79535-47bb-0310-9956-ffa450edef68

redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java
redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml

index 560e5387de1b4badc0d60503030b9750e35fb210..8b0124de129c6745a5097dc925ab1397094608c4 100644 (file)
@@ -106,8 +106,11 @@ public class LdapRbacManager
     @Named( value = "cache#ldapRoles" )
     private Cache<String, Role> rolesCache;
 
-    private boolean writableLdap = false;
+    @Inject
+    @Named( value = "cache#userAssignments" )
+    private Cache<String, UserAssignment> userAssignmentsCache;
 
+    private boolean writableLdap = false;
 
     @PostConstruct
     public void initialize()
@@ -191,6 +194,7 @@ public class LdapRbacManager
             }
         }
         this.rolesCache.clear();
+        this.userAssignmentsCache.clear();
         this.rbacImpl.eraseDatabase();
     }
 
@@ -286,6 +290,7 @@ public class LdapRbacManager
             {
                 UserAssignment userAssignment = new UserAssignmentImpl( entry.getKey(), entry.getValue() );
                 userAssignments.add( userAssignment );
+                userAssignmentsCache.put( userAssignment.getPrincipal(), userAssignment );
             }
 
             return userAssignments;
@@ -575,6 +580,11 @@ public class LdapRbacManager
     public UserAssignment getUserAssignment( String username )
         throws RbacManagerException
     {
+        UserAssignment ua = userAssignmentsCache.get( username );
+        if ( ua != null )
+        {
+            return ua;
+        }
         LdapConnection ldapConnection = null;
         DirContext context = null;
         try
@@ -583,7 +593,11 @@ public class LdapRbacManager
             context = ldapConnection.getDirContext();
             List<String> roles = ldapRoleMapper.getRoles( username, context, getRealRoles() );
 
-            return new UserAssignmentImpl( username, roles );
+            ua = new UserAssignmentImpl( username, roles );
+
+            userAssignmentsCache.put( username, ua );
+
+            return ua;
         }
         catch ( MappingException e )
         {
@@ -778,12 +792,17 @@ public class LdapRbacManager
         throws RbacManagerException
     {
         // TODO ldap cannot or isWritable ldap ?
+        userAssignmentsCache.remove( username );
         this.rbacImpl.removeUserAssignment( username );
     }
 
     public void removeUserAssignment( UserAssignment userAssignment )
         throws RbacManagerException
     {
+        if ( userAssignment != null )
+        {
+            userAssignmentsCache.remove( userAssignment.getPrincipal() );
+        }
         // TODO ldap cannot or isWritable ldap ?
         this.rbacImpl.removeUserAssignment( userAssignment );
     }
@@ -977,6 +996,7 @@ public class LdapRbacManager
                 }
             }
 
+            userAssignmentsCache.put( userAssignment.getPrincipal(), userAssignment );
             return userAssignment;
         }
         catch ( UserManagerException e )
@@ -1000,6 +1020,10 @@ public class LdapRbacManager
 
     public boolean userAssignmentExists( String principal )
     {
+        if ( userAssignmentsCache.hasKey( principal ) )
+        {
+            return true;
+        }
         LdapConnection ldapConnection = null;
         DirContext context = null;
         try
index 1c306918d6a35876d5b044f99ccc8b26705f1292..1919f280210e1bb7cf79fc5e5ecd8c0389dcb370 100755 (executable)
     <property name="userPermissionsCache" ref="cache#userPermissions"/>
   </bean>
 
-  <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 name="cache#userAssignments" class="org.apache.archiva.redback.components.cache.impl.NoCacheCache">
   </bean>
 
   <bean name="cache#userPermissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"