[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 String descriptionKey;
private boolean readOnly;
public UserManagerImplementationInformation() public UserManagerImplementationInformation()
{ {
// no op // no op
} }
public UserManagerImplementationInformation( String beanId, String descriptionKey ) public UserManagerImplementationInformation( String beanId, String descriptionKey, boolean readOnly )
{ {
this.beanId = beanId; this.beanId = beanId;
this.descriptionKey = descriptionKey; this.descriptionKey = descriptionKey;
this.readOnly = readOnly;
} }
public String getBeanId() public String getBeanId()
@ -64,6 +67,16 @@ public class UserManagerImplementationInformation
this.descriptionKey = descriptionKey; this.descriptionKey = descriptionKey;
} }
public boolean isReadOnly()
{
return readOnly;
}
public void setReadOnly( boolean readOnly )
{
this.readOnly = readOnly;
}
@Override @Override
public String toString() public String toString()
{ {

View File

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

View File

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

View File

@ -1167,7 +1167,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
configurationPropertiesEntries=[]; configurationPropertiesEntries=[];
} }
return new ArchivaRuntimeConfiguration(data.userManagerImpl,mapLdapConfiguration(data.ldapConfiguration),data.migratedFromRedbackConfiguration, return new ArchivaRuntimeConfiguration(data.userManagerImpls,mapLdapConfiguration(data.ldapConfiguration),data.migratedFromRedbackConfiguration,
configurationPropertiesEntries); configurationPropertiesEntries);
} }
@ -1215,9 +1215,53 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
} }
ArchivaRuntimeConfigurationViewModel=function(archivaRuntimeConfiguration,userManagerImplementationInformations){ ArchivaRuntimeConfigurationViewModel=function(archivaRuntimeConfiguration,userManagerImplementationInformations){
var self=this;
this.archivaRuntimeConfiguration=ko.observable(archivaRuntimeConfiguration); this.archivaRuntimeConfiguration=ko.observable(archivaRuntimeConfiguration);
this.userManagerImplementationInformations=ko.observable(userManagerImplementationInformations); 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(){ saveArchivaRuntimeConfiguration=function(){
$.log("saveArchivaRuntimeConfiguration"); $.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.beanId=beanId;
this.descriptionKey=descriptionKey; this.descriptionKey=descriptionKey;
this.description= $.i18n.prop(descriptionKey); this.description= $.i18n.prop(descriptionKey);
this.readOnly=readOnly;
} }
mapUserManagerImplementationInformations=function(data){ mapUserManagerImplementationInformations=function(data){
@ -1266,7 +1311,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
if(data==null){ if(data==null){
return null; return null;
} }
return new UserManagerImplementationInformation(data.beanId,data.descriptionKey); return new UserManagerImplementationInformation(data.beanId,data.descriptionKey,data.readOnly);
} }
displayRuntimeConfiguration=function(){ displayRuntimeConfiguration=function(){
@ -1286,7 +1331,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
var archivaRuntimeConfiguration = mapArchivaRuntimeConfiguration(data); var archivaRuntimeConfiguration = mapArchivaRuntimeConfiguration(data);
var archivaRuntimeConfigurationViewModel = var archivaRuntimeConfigurationViewModel =
new ArchivaRuntimeConfigurationViewModel(archivaRuntimeConfiguration,userManagerImplementationInformations); new ArchivaRuntimeConfigurationViewModel(archivaRuntimeConfiguration,userManagerImplementationInformations);
mainContent.html( $( "#runtime-configuration-main" ).tmpl( ) ); mainContent.html( $( "#runtime-configuration-main" ).tmpl() );
ko.applyBindings(archivaRuntimeConfigurationViewModel,$("#runtime-configuration-content" ).get(0)); ko.applyBindings(archivaRuntimeConfigurationViewModel,$("#runtime-configuration-content" ).get(0));
activatePopoverDoc(); 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++){ for(var i=0;i<self.proxyConnectorRule.proxyConnectors().length;i++){
if(self.proxyConnectorRule.proxyConnectors()[i].sourceRepoId()==sourceRepoId && if(self.proxyConnectorRule.proxyConnectors()[i].sourceRepoId()==sourceRepoId &&
self.proxyConnectorRule.proxyConnectors()[i].targetRepoId()==targetRepoId){ self.proxyConnectorRule.proxyConnectors()[i].targetRepoId()==targetRepoId){
$.log("found");
proxyConnectorToRemove=self.proxyConnectorRule.proxyConnectors()[i]; proxyConnectorToRemove=self.proxyConnectorRule.proxyConnectors()[i];
} }
} }

View File

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