From f11ba97b41809509cd4ba5d7eb40ad8b9156350a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 23 Jan 2013 10:31:19 +0000 Subject: [PATCH] add some caching for userAssignement in LdapRbacManager git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1437326 13f79535-47bb-0310-9956-ffa450edef68 --- .../redback/rbac/ldap/LdapRbacManager.java | 28 +++++++++++++++++-- .../src/test/resources/spring-context.xml | 10 +------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java index 560e5387..8b0124de 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java @@ -106,8 +106,11 @@ public class LdapRbacManager @Named( value = "cache#ldapRoles" ) private Cache rolesCache; - private boolean writableLdap = false; + @Inject + @Named( value = "cache#userAssignments" ) + private Cache 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 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 diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml index 1c306918..1919f280 100755 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml @@ -108,15 +108,7 @@ - - - - - - - - +