mirror of https://github.com/apache/archiva.git
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
This commit is contained in:
parent
a86b4e4bac
commit
b9f36bd6b9
|
@ -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>
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
||||
|
|
|
@ -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){
|
||||
var redbackRuntimeConfiguration =
|
||||
new RedbackRuntimeConfiguration(data.userManagerImpls,mapLdapConfiguration(data.ldapConfiguration),data.migratedFromRedbackConfiguration);
|
||||
$.log("mapRedbackRuntimeConfiguration");
|
||||
var ldapConfiguration=mapLdapConfiguration(data.ldapConfiguration);
|
||||
$.log("mapLdapConfiguration done for ");
|
||||
|
||||
var redbackRuntimeConfiguration =
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -904,6 +904,19 @@
|
|||
<div class="tab-content">
|
||||
<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>
|
||||
|
|
Loading…
Reference in New Issue