diff options
author | Olivier Lamy <olamy@apache.org> | 2012-12-20 20:32:43 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-12-20 20:32:43 +0000 |
commit | b9f36bd6b9b02591eca216b0fa9a105f5eceab89 (patch) | |
tree | 27171f6f301e6806b05fbf44a0702d44018883af | |
parent | a86b4e4bacd187a5bc727f01b712abc26651ff49 (diff) | |
download | archiva-b9f36bd6b9b02591eca216b0fa9a105f5eceab89.tar.gz archiva-b9f36bd6b9b02591eca216b0fa9a105f5eceab89.zip |
implements a dynamic cache configurable tru the ui for ArchivaConfigurableUsersManager
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1424673 13f79535-47bb-0310-9956-ffa450edef68
6 files changed, 145 insertions, 13 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index 14237e7a4..6b4a6d9e3 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -1486,6 +1486,13 @@ <multiplicity>*</multiplicity> </association> </field> + <field> + <name>useUsersCache</name> + <description>flag to know if redback will use a cache to prevent searching users already found.</description> + <version>1.4.0+</version> + <type>boolean</type> + <defaultValue>false</defaultValue> + </field> </fields> </class> diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RedbackRuntimeConfiguration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RedbackRuntimeConfiguration.java index 882645e69..cda3d4d52 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RedbackRuntimeConfiguration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RedbackRuntimeConfiguration.java @@ -53,6 +53,12 @@ public class RedbackRuntimeConfiguration */ private List<PropertyEntry> configurationPropertiesEntries; + /** + * flag to know if redback will use a cache to prevent + * searching users already found. + */ + private boolean useUsersCache = false; + public RedbackRuntimeConfiguration() { // no op @@ -125,15 +131,28 @@ public class RedbackRuntimeConfiguration } } + public boolean isUseUsersCache() + { + return useUsersCache; + } + + public void setUseUsersCache( boolean useUsersCache ) + { + this.useUsersCache = useUsersCache; + } + @Override public String toString() { - return "RedbackRuntimeConfiguration{" + - "userManagerImpls=" + userManagerImpls + - ", ldapConfiguration=" + ldapConfiguration + - ", migratedFromRedbackConfiguration=" + migratedFromRedbackConfiguration + - ", configurationProperties=" + configurationProperties + - ", configurationPropertiesEntries=" + configurationPropertiesEntries + - '}'; + final StringBuilder sb = new StringBuilder(); + sb.append( "RedbackRuntimeConfiguration" ); + sb.append( "{userManagerImpls=" ).append( userManagerImpls ); + sb.append( ", ldapConfiguration=" ).append( ldapConfiguration ); + sb.append( ", migratedFromRedbackConfiguration=" ).append( migratedFromRedbackConfiguration ); + sb.append( ", configurationProperties=" ).append( configurationProperties ); + sb.append( ", configurationPropertiesEntries=" ).append( configurationPropertiesEntries ); + sb.append( ", useUsersCache=" ).append( useUsersCache ); + sb.append( '}' ); + return sb.toString(); } } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java index 65e465b9d..49a50a80c 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java @@ -20,6 +20,7 @@ package org.apache.archiva.web.security; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin; +import org.apache.archiva.redback.components.cache.Cache; import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.UserManager; import org.apache.archiva.redback.users.UserManagerException; @@ -31,6 +32,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import javax.inject.Inject; +import javax.inject.Named; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -55,6 +57,10 @@ public class ArchivaConfigurableUsersManager private List<UserManagerListener> listeners = new ArrayList<UserManagerListener>(); + @Inject + @Named( value = "cache#users" ) + private Cache usersCache; + @Override public void initialize() { @@ -80,11 +86,31 @@ public class ArchivaConfigurableUsersManager } } + protected boolean useUsersCache() + { + try + { + return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration().isUseUsersCache(); + } + catch ( RepositoryAdminException e ) + { + log.warn( "skip fail to get RedbackRuntimeConfiguration: {}, use false", e.getMessage(), e ); + return false; + } + } + @Override public User addUser( User user ) throws UserManagerException { - return userManagerPerId.get( user.getUserManagerId() ).addUser( user ); + user = userManagerPerId.get( user.getUserManagerId() ).addUser( user ); + + if ( useUsersCache() ) + { + usersCache.put( user.getUsername(), user ); + } + + return user; } @Override @@ -92,6 +118,11 @@ public class ArchivaConfigurableUsersManager throws UserManagerException { userManagerPerId.get( user.getUserManagerId() ).addUserUnchecked( user ); + + if ( useUsersCache() ) + { + usersCache.put( user.getUsername(), user ); + } } protected UserManager findFirstWritable() @@ -116,7 +147,12 @@ public class ArchivaConfigurableUsersManager log.warn( "cannot find writable user manager implementation, skip user creation" ); return null; } - return userManager.createUser( username, fullName, emailAddress ); + User user = userManager.createUser( username, fullName, emailAddress ); + if ( useUsersCache() ) + { + usersCache.put( user.getUsername(), user ); + } + return user; } @Override @@ -137,6 +173,10 @@ public class ArchivaConfigurableUsersManager return; } userManager.deleteUser( username ); + if ( useUsersCache() ) + { + usersCache.remove( username ); + } } @Override @@ -152,7 +192,17 @@ public class ArchivaConfigurableUsersManager public User findUser( String username ) throws UserManagerException { + User user = null; + if ( useUsersCache() ) + { + user = (User) usersCache.get( username ); + if ( user != null ) + { + return user; + } + + } UserManagerException lastException = null; for ( UserManager userManager : userManagerPerId.values() ) { @@ -161,6 +211,10 @@ public class ArchivaConfigurableUsersManager user = userManager.findUser( username ); if ( user != null ) { + if ( useUsersCache() ) + { + usersCache.put( username, user ); + } return user; } } @@ -191,6 +245,14 @@ public class ArchivaConfigurableUsersManager throws UserNotFoundException, UserManagerException { User user = null; + if ( useUsersCache() ) + { + user = (User) usersCache.get( GUEST_USERNAME ); + if ( user != null ) + { + return user; + } + } UserNotFoundException lastException = null; for ( UserManager userManager : userManagerPerId.values() ) { @@ -334,14 +396,28 @@ public class ArchivaConfigurableUsersManager public User updateUser( User user ) throws UserNotFoundException, UserManagerException { - return userManagerPerId.get( user.getUserManagerId() ).updateUser( user ); + user = userManagerPerId.get( user.getUserManagerId() ).updateUser( user ); + + if ( useUsersCache() ) + { + usersCache.put( user.getUsername(), user ); + } + + return user; } @Override public User updateUser( User user, boolean passwordChangeRequired ) throws UserNotFoundException, UserManagerException { - return userManagerPerId.get( user.getUserManagerId() ).updateUser( user, passwordChangeRequired ); + user = userManagerPerId.get( user.getUserManagerId() ).updateUser( user, passwordChangeRequired ); + + if ( useUsersCache() ) + { + usersCache.put( user.getUsername(), user ); + } + + return user; } @Override diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties index 2c267c600..33fcee7bf 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties @@ -630,5 +630,6 @@ redback.runtime.user-managers.impls.available=UserManager(s) availables redback.runtime.ldap.verified=Ldap connection verified. redback.runtime.ldap.checkModification=Verify LDAP changes. redback.runtime.ldap.checkServer=Verify LDAP configuration on server side. +redback.runtime.useUsersCache.label=Use a cache for users. diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js index 0fd5d946b..07ecea558 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js @@ -1151,7 +1151,9 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" } - RedbackRuntimeConfiguration=function(userManagerImpls,ldapConfiguration,migratedFromRedbackConfiguration,configurationPropertiesEntries){ + RedbackRuntimeConfiguration=function(userManagerImpls,ldapConfiguration,migratedFromRedbackConfiguration,configurationPropertiesEntries + ,useUsersCache){ + $.log("new RedbackRuntimeConfiguration"); var self=this; this.modified=ko.observable(false); this.modified.subscribe(function(newValue){$.log("RedbackRuntimeConfiguration modified")}); @@ -1164,12 +1166,16 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" this.migratedFromRedbackConfiguration=ko.observable(migratedFromRedbackConfiguration); + $.log("new RedbackRuntimeConfiguration before configurationPropertiesEntries mapping:"); + this.configurationPropertiesEntries=ko.observableArray(configurationPropertiesEntries?configurationPropertiesEntries:[]); this.configurationPropertiesEntries.subscribe(function(newValue){ self.modified(true); $.log("configurationPropertiesEntries modified") }); + $.log("new RedbackRuntimeConfiguration before configurationPropertiesEntries mapping done"); + this.findPropertyValue=function(key){ for(var i=0;i<self.configurationPropertiesEntries().length;i++){ if(self.configurationPropertiesEntries()[i].key==key){ @@ -1179,12 +1185,20 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" } } } + + this.useUsersCache=ko.observable(useUsersCache); + this.useUsersCache.subscribe(function(newValue){self.modified(true)}); } mapRedbackRuntimeConfiguration=function(data){ + $.log("mapRedbackRuntimeConfiguration"); + var ldapConfiguration=mapLdapConfiguration(data.ldapConfiguration); + $.log("mapLdapConfiguration done for "); + var redbackRuntimeConfiguration = - new RedbackRuntimeConfiguration(data.userManagerImpls,mapLdapConfiguration(data.ldapConfiguration),data.migratedFromRedbackConfiguration); + new RedbackRuntimeConfiguration(data.userManagerImpls,ldapConfiguration,data.migratedFromRedbackConfiguration,[],data.useUsersCache); + $.log("mapRedbackRuntimeConfiguration done"); var configurationPropertiesEntries = data.configurationPropertiesEntries == null ? []: $.each(data.configurationPropertiesEntries,function(item){ return new Entry(item.key, item.value,function(newValue){ redbackRuntimeConfiguration.modified(true); @@ -1242,6 +1256,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" } mapLdapConfiguration=function(data){ + $.log("mapLdapConfiguration"); if(data){ var extraPropertiesEntries = data.extraPropertiesEntries == null ? []: $.each(data.extraPropertiesEntries,function(item){ return new Entry(item.key, item.value); @@ -1249,6 +1264,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" if (!$.isArray(extraPropertiesEntries)){ extraPropertiesEntries=[]; } + $.log("mapLdapConfiguration done"); return new LdapConfiguration(data.hostName,data.port,data.ssl,data.baseDn,data.contextFactory,data.bindDn,data.password, data.authenticationMethod,extraPropertiesEntries); } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/general-admin.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/general-admin.html index 1c9cadbeb..d1f446a13 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/general-admin.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/general-admin.html @@ -905,6 +905,19 @@ <div class="tab-pane active" id="redback-runtime-general-content"> <div class="well"> <div class="row-fluid"> + <form class="form-horizontal" id="redback-runtime-general-form-id"> + <div class="control-group"> + <label for="redback-runtime-useUsersCache" class="control-label"> + ${$.i18n.prop('redback.runtime.useUsersCache.label')} + </label> + <div class="controls"> + <input type="checkbox" id="redback-runtime-useUsersCache" name="redback-runtime-useUsersCache" + data-bind="checked: redbackRuntimeConfiguration().useUsersCache"/> + </div> + </div> + </form> + </div> + <div class="row-fluid"> <div class="span4 dotted"> <h5>${$.i18n.prop('redback.runtime.user-managers.impls.choosed')}</h5> <div style="min-height: 40px" id="user-mananagers-sortables-choosed" |