[MRM-1721] Chaining user manager implementations.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1419569 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-10 16:36:18 +00:00
parent 195d7ef627
commit 8534cdcb6a
6 changed files with 269 additions and 89 deletions

View File

@ -33,15 +33,18 @@ public class UserManagerImplementationInformation
private String descriptionKey;
private boolean readOnly;
public UserManagerImplementationInformation()
{
// no op
}
public UserManagerImplementationInformation( String beanId, String descriptionKey )
public UserManagerImplementationInformation( String beanId, String descriptionKey, boolean readOnly )
{
this.beanId = beanId;
this.descriptionKey = descriptionKey;
this.readOnly = readOnly;
}
public String getBeanId()
@ -64,6 +67,16 @@ public class UserManagerImplementationInformation
this.descriptionKey = descriptionKey;
}
public boolean isReadOnly()
{
return readOnly;
}
public void setReadOnly( boolean readOnly )
{
this.readOnly = readOnly;
}
@Override
public String toString()
{

View File

@ -116,6 +116,7 @@ public class DefaultArchivaRuntimeConfigurationService
UserManagerImplementationInformation information = new UserManagerImplementationInformation();
information.setBeanId( StringUtils.substringAfter( entry.getKey(), "#" ) );
information.setDescriptionKey( userManager.getDescriptionKey() );
information.setReadOnly( userManager.isReadOnly() );
informations.add( information );
}
}

View File

@ -31,13 +31,15 @@ import org.springframework.stereotype.Service;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author Olivier Lamy
* @since 1.4-M4
*/
@Service("userManager#archiva")
@Service( "userManager#archiva" )
public class ArchivaConfigurableUsersManager
extends ConfigurableUserManager
{
@ -48,7 +50,9 @@ public class ArchivaConfigurableUsersManager
@Inject
private ApplicationContext applicationContext;
private List<UserManager> userManagers;
private Map<String, UserManager> userManagerPerId;
private List<UserManagerListener> listeners = new ArrayList<UserManagerListener>();
@Override
public void initialize()
@ -59,12 +63,12 @@ public class ArchivaConfigurableUsersManager
archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration().getUserManagerImpls();
log.info( "use userManagerImpls: '{}'", userManagerImpls );
userManagers = new ArrayList<UserManager>( userManagerImpls.size() );
userManagerPerId = new LinkedHashMap<String, UserManager>( userManagerImpls.size() );
for ( String id : userManagerImpls )
{
UserManager userManagerImpl = applicationContext.getBean( "userManager#" + id, UserManager.class );
setUserManagerImpl( userManagerImpl );
userManagers.add( userManagerImpl );
userManagerPerId.put( id, userManagerImpl );
}
}
catch ( RepositoryAdminException e )
@ -78,20 +82,36 @@ public class ArchivaConfigurableUsersManager
@Override
public User addUser( User user )
{
return super.addUser( user ); //To change body of overridden methods use File | Settings | File Templates.
return userManagerPerId.get( user.getUserManagerId() ).addUser( user );
}
@Override
public void addUserUnchecked( User user )
{
super.addUserUnchecked( user ); //To change body of overridden methods use File | Settings | File Templates.
userManagerPerId.get( user.getUserManagerId() ).addUserUnchecked( user );
}
protected UserManager findFirstWritable()
{
for ( UserManager userManager : userManagerPerId.values() )
{
if ( !userManager.isReadOnly() )
{
return userManager;
}
}
return null;
}
@Override
public User createUser( String username, String fullName, String emailAddress )
{
return super.createUser( username, fullName,
emailAddress ); //To change body of overridden methods use File | Settings | File Templates.
UserManager userManager = findFirstWritable();
if ( userManager == null )
{
throw new RuntimeException( "impossible to find a writable userManager" );
}
return userManager.createUser( username, fullName, emailAddress );
}
@Override
@ -100,183 +120,276 @@ public class ArchivaConfigurableUsersManager
return super.createUserQuery(); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
public void deleteUser( Object principal )
throws UserNotFoundException
{
super.deleteUser( principal ); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
public void deleteUser( String username )
throws UserNotFoundException
{
super.deleteUser( username ); //To change body of overridden methods use File | Settings | File Templates.
UserManager userManager = findFirstWritable();
if ( userManager == null )
{
throw new RuntimeException( "impossible to find a writable userManager" );
}
userManager.deleteUser( username );
}
@Override
public void eraseDatabase()
{
super.eraseDatabase(); //To change body of overridden methods use File | Settings | File Templates.
for ( UserManager userManager : userManagerPerId.values() )
{
userManager.eraseDatabase();
}
}
@Override
public User findUser( String username )
throws UserNotFoundException
{
return super.findUser(
username ); //To change body of overridden methods use File | Settings | File Templates.
User user = null;
UserNotFoundException lastException = null;
for ( UserManager userManager : userManagerPerId.values() )
{
try
{
user = userManager.findUser( username );
if ( user != null )
{
return user;
}
}
catch ( UserNotFoundException e )
{
lastException = e;
}
}
if ( user == null )
{
throw lastException;
}
return user;
}
@Override
public User findUser( Object principal )
throws UserNotFoundException
{
return super.findUser(
principal ); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
public User getGuestUser()
throws UserNotFoundException
{
return super.getGuestUser(); //To change body of overridden methods use File | Settings | File Templates.
User user = null;
UserNotFoundException lastException = null;
for ( UserManager userManager : userManagerPerId.values() )
{
try
{
user = userManager.getGuestUser();
if ( user != null )
{
return user;
}
}
catch ( UserNotFoundException e )
{
lastException = e;
}
}
if ( user == null )
{
throw lastException;
}
return user;
}
@Override
public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
{
return super.findUsersByEmailKey( emailKey,
orderAscending ); //To change body of overridden methods use File | Settings | File Templates.
List<User> users = new ArrayList<User>();
for ( UserManager userManager : userManagerPerId.values() )
{
List<User> found = userManager.findUsersByEmailKey( emailKey, orderAscending );
if ( found != null )
{
users.addAll( found );
}
}
return users;
}
@Override
public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
{
return super.findUsersByFullNameKey( fullNameKey,
orderAscending ); //To change body of overridden methods use File | Settings | File Templates.
List<User> users = new ArrayList<User>();
for ( UserManager userManager : userManagerPerId.values() )
{
List<User> found = userManager.findUsersByFullNameKey( fullNameKey, orderAscending );
if ( found != null )
{
users.addAll( found );
}
}
return users;
}
@Override
public List<User> findUsersByQuery( UserQuery query )
{
return super.findUsersByQuery(
query ); //To change body of overridden methods use File | Settings | File Templates.
List<User> users = new ArrayList<User>();
for ( UserManager userManager : userManagerPerId.values() )
{
List<User> found = userManager.findUsersByQuery( query );
if ( found != null )
{
users.addAll( found );
}
}
return users;
}
@Override
public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
{
return super.findUsersByUsernameKey( usernameKey,
orderAscending ); //To change body of overridden methods use File | Settings | File Templates.
List<User> users = new ArrayList<User>();
for ( UserManager userManager : userManagerPerId.values() )
{
List<User> found = userManager.findUsersByUsernameKey( usernameKey, orderAscending );
if ( found != null )
{
users.addAll( found );
}
}
return users;
}
@Override
public String getId()
{
return super.getId(); //To change body of overridden methods use File | Settings | File Templates.
return null;
}
@Override
public List<User> getUsers()
{
return super.getUsers(); //To change body of overridden methods use File | Settings | File Templates.
List<User> users = new ArrayList<User>();
for ( UserManager userManager : userManagerPerId.values() )
{
List<User> found = userManager.getUsers();
if ( found != null )
{
users.addAll( found );
}
}
return users;
}
@Override
public List<User> getUsers( boolean orderAscending )
{
return super.getUsers(
orderAscending ); //To change body of overridden methods use File | Settings | File Templates.
List<User> users = new ArrayList<User>();
for ( UserManager userManager : userManagerPerId.values() )
{
List<User> found = userManager.getUsers( orderAscending );
if ( found != null )
{
users.addAll( found );
}
}
return users;
}
@Override
public boolean isReadOnly()
{
return super.isReadOnly(); //To change body of overridden methods use File | Settings | File Templates.
//olamy: must be it depends :-)
return true;
}
@Override
public User updateUser( User user )
throws UserNotFoundException
{
return super.updateUser( user ); //To change body of overridden methods use File | Settings | File Templates.
return userManagerPerId.get( user.getUserManagerId() ).updateUser( user );
}
@Override
public User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException
{
return super.updateUser( user,
passwordChangeRequired ); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
public boolean userExists( Object principal )
{
return super.userExists(
principal ); //To change body of overridden methods use File | Settings | File Templates.
return userManagerPerId.get( user.getUserManagerId() ).updateUser( user, passwordChangeRequired );
}
@Override
public void setUserManagerImpl( UserManager userManagerImpl )
{
super.setUserManagerImpl(
userManagerImpl ); //To change body of overridden methods use File | Settings | File Templates.
log.error( "setUserManagerImpl cannot be used in this implementation" );
}
@Override
public void addUserManagerListener( UserManagerListener listener )
{
super.addUserManagerListener(
listener ); //To change body of overridden methods use File | Settings | File Templates.
this.listeners.add( listener );
}
@Override
public void removeUserManagerListener( UserManagerListener listener )
{
super.removeUserManagerListener(
listener ); //To change body of overridden methods use File | Settings | File Templates.
this.listeners.remove( listener );
}
@Override
protected void fireUserManagerInit( boolean freshDatabase )
{
super.fireUserManagerInit(
freshDatabase ); //To change body of overridden methods use File | Settings | File Templates.
for ( UserManagerListener listener : listeners )
{
listener.userManagerInit( freshDatabase );
}
}
@Override
protected void fireUserManagerUserAdded( User addedUser )
{
super.fireUserManagerUserAdded(
addedUser ); //To change body of overridden methods use File | Settings | File Templates.
for ( UserManagerListener listener : listeners )
{
listener.userManagerUserAdded( addedUser );
}
}
@Override
protected void fireUserManagerUserRemoved( User removedUser )
{
super.fireUserManagerUserRemoved(
removedUser ); //To change body of overridden methods use File | Settings | File Templates.
for ( UserManagerListener listener : listeners )
{
listener.userManagerUserRemoved( removedUser );
}
}
@Override
protected void fireUserManagerUserUpdated( User updatedUser )
{
super.fireUserManagerUserUpdated(
updatedUser ); //To change body of overridden methods use File | Settings | File Templates.
for ( UserManagerListener listener : listeners )
{
listener.userManagerUserUpdated( updatedUser );
}
}
@Override
public User createGuestUser()
{
return super.createGuestUser(); //To change body of overridden methods use File | Settings | File Templates.
return findFirstWritable().createGuestUser();
}
@Override
public boolean isFinalImplementation()
{
return super.isFinalImplementation(); //To change body of overridden methods use File | Settings | File Templates.
return false;
}
public String getDescriptionKey()

View File

@ -1167,7 +1167,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
configurationPropertiesEntries=[];
}
return new ArchivaRuntimeConfiguration(data.userManagerImpl,mapLdapConfiguration(data.ldapConfiguration),data.migratedFromRedbackConfiguration,
return new ArchivaRuntimeConfiguration(data.userManagerImpls,mapLdapConfiguration(data.ldapConfiguration),data.migratedFromRedbackConfiguration,
configurationPropertiesEntries);
}
@ -1215,9 +1215,53 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
}
ArchivaRuntimeConfigurationViewModel=function(archivaRuntimeConfiguration,userManagerImplementationInformations){
var self=this;
this.archivaRuntimeConfiguration=ko.observable(archivaRuntimeConfiguration);
this.userManagerImplementationInformations=ko.observable(userManagerImplementationInformations);
var self=this;
this.usedUserManagerImpls=ko.observableArray([]);
findUserManagerImplementationInformation=function(id){
for(var i= 0;i<self.userManagerImplementationInformations().length;i++){
$.log(id+""+self.userManagerImplementationInformations()[i].beanId);
if(id==self.userManagerImplementationInformations()[i].beanId){
return self.userManagerImplementationInformations()[i];
}
}
}
for(var i= 0;i<archivaRuntimeConfiguration.userManagerImpls().length;i++){
var id=archivaRuntimeConfiguration.userManagerImpls()[i];
$.log("id:"+id);
var userManagerImplementationInformation=findUserManagerImplementationInformation(id);
if(userManagerImplementationInformation!=null){
this.usedUserManagerImpls.push(userManagerImplementationInformation);
}
}
isUsedUserManagerImpl=function(userManagerImplementationInformation){
for(var i=0;i<self.usedUserManagerImpls().length;i++){
if(self.usedUserManagerImpls()[i].beanId==userManagerImplementationInformation.beanId){
return true;
}
}
return false;
}
this.availableUserManagerImpls=ko.observableArray([]);
for(var i=0;i<self.userManagerImplementationInformations().length;i++){
if(!isUsedUserManagerImpl(self.userManagerImplementationInformations()[i])){
self.availableUserManagerImpls.push(self.userManagerImplementationInformations()[i]);
}
}
userManagerImplMoved=function(arg){
$.log("userManagerImplMoved:"+arg.sourceIndex+" to " + arg.targetIndex);
//self.usedUserManagerImpls().push(self.availableUserManagerImpls()[arg.sourceIndex]);
}
saveArchivaRuntimeConfiguration=function(){
$.log("saveArchivaRuntimeConfiguration");
@ -1250,10 +1294,11 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
}
}
UserManagerImplementationInformation=function(beanId,descriptionKey){
UserManagerImplementationInformation=function(beanId,descriptionKey,readOnly){
this.beanId=beanId;
this.descriptionKey=descriptionKey;
this.description= $.i18n.prop(descriptionKey);
this.readOnly=readOnly;
}
mapUserManagerImplementationInformations=function(data){
@ -1266,7 +1311,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
if(data==null){
return null;
}
return new UserManagerImplementationInformation(data.beanId,data.descriptionKey);
return new UserManagerImplementationInformation(data.beanId,data.descriptionKey,data.readOnly);
}
displayRuntimeConfiguration=function(){
@ -1286,7 +1331,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
var archivaRuntimeConfiguration = mapArchivaRuntimeConfiguration(data);
var archivaRuntimeConfigurationViewModel =
new ArchivaRuntimeConfigurationViewModel(archivaRuntimeConfiguration,userManagerImplementationInformations);
mainContent.html( $( "#runtime-configuration-main" ).tmpl( ) );
mainContent.html( $( "#runtime-configuration-main" ).tmpl() );
ko.applyBindings(archivaRuntimeConfigurationViewModel,$("#runtime-configuration-content" ).get(0));
activatePopoverDoc();
}

View File

@ -224,7 +224,6 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra
for(var i=0;i<self.proxyConnectorRule.proxyConnectors().length;i++){
if(self.proxyConnectorRule.proxyConnectors()[i].sourceRepoId()==sourceRepoId &&
self.proxyConnectorRule.proxyConnectors()[i].targetRepoId()==targetRepoId){
$.log("found");
proxyConnectorToRemove=self.proxyConnectorRule.proxyConnectors()[i];
}
}

View File

@ -744,7 +744,7 @@
<div style="min-height: 40px"
data-bind="sortable: {template: 'statistics-repositories-order-tmpl',data:availableRepositories}">
</div>
</div>
</div>
</div>
</div>
<div class="span6 well">
@ -842,9 +842,9 @@
</script>
<script id="statistics-repositories-order-tmpl" type="text/html">
<div class="well draggable-item">
${$data}
</div>
<div class="well draggable-item">
${$data}
</div>
</script>
<script id="report-health" type="text/html">
@ -904,20 +904,23 @@
<div class="tab-content">
<div class="tab-pane active" id="redback-runtime-general-content">
<div class="well">
<form class="form-horizontal" id="runtime-configuration-form-id">
<fieldset id="form-runtime-configuration">
<div class="control-group">
<label for="userManagerImpl" class="control-label">
${$.i18n.prop('runtime-configuration.usermanager.label')}
</label>
<div class="controls">
<select id="userManagerImpl"
data-bind="options: userManagerImplementationInformations,optionsValue: 'beanId', optionsText: 'description', value: archivaRuntimeConfiguration().userManagerImpl, optionsCaption: 'Choose...'"></select>
</div>
<div class="row-fluid">
<div class="span4 dotted">
<h5></h5>
<hr/>
<div style="min-height: 40px" id="user-mananagers-sortables-choosed"
data-bind="sortable: { template: 'redback-runtime-general-content-usermanagers', data:usedUserManagerImpls}">
</div>
</fieldset>
</form>
</div>
<div class="span4 dotted">
<h5></h5>
<hr/>
<div style="min-height: 40px"id="user-mananagers-sortables-availables"
data-bind="sortable: {template: 'redback-runtime-general-content-usermanagers',data:availableUserManagerImpls}">
</div>
</div>
</div>
</div>
</div>
@ -1033,3 +1036,9 @@
</div>
</script>
<script id="redback-runtime-general-content-usermanagers" type="text/html">
<div class="well draggable-item">
${$data.description}
</div>
</script>