From: Olivier Lamy Date: Mon, 18 Feb 2013 09:28:48 +0000 (+0000) Subject: service to provide available rbacmanager implementations informations X-Git-Tag: archiva-1.4-M4~179 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8364c17d3a05e12da8ecc159c629047522d29f8a;p=archiva.git service to provide available rbacmanager implementations informations git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1447164 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java index 2e6f89182..416123b0a 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java @@ -44,50 +44,60 @@ public class TestRBACManager implements RBACManager public void initialize() { - //To change body of implemented methods use File | Settings | File Templates. + + } + + public boolean isFinalImplementation() + { + return false; + } + + public String getDescriptionKey() + { + return "archiva.redback.rbacmanager.test"; } public void addListener( RBACManagerListener listener ) { - //To change body of implemented methods use File | Settings | File Templates. + } public void removeListener( RBACManagerListener listener ) { - //To change body of implemented methods use File | Settings | File Templates. + } public Role createRole( String name ) { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } public boolean roleExists( String name ) { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } public boolean roleExists( Role role ) { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } public Role saveRole( Role role ) throws RbacObjectInvalidException, RbacManagerException { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } public void saveRoles( Collection roles ) throws RbacObjectInvalidException, RbacManagerException { - //To change body of implemented methods use File | Settings | File Templates. + } public Role getRole( String roleName ) throws RbacObjectNotFoundException, RbacManagerException { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } public Map getRoles( Collection roleNames ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/UserManagerImplementationInformation.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/UserManagerImplementationInformation.java index 17ba2400d..b53998aa7 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/UserManagerImplementationInformation.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/UserManagerImplementationInformation.java @@ -25,15 +25,11 @@ import java.io.Serializable; * @author Olivier Lamy * @since 1.4-M4 */ -@XmlRootElement ( name = "userManagerImplementationInformation" ) +@XmlRootElement(name = "userManagerImplementationInformation") public class UserManagerImplementationInformation + extends AbstractImplementationInformation implements Serializable { - private String beanId; - - private String descriptionKey; - - private boolean readOnly; public UserManagerImplementationInformation() { @@ -42,77 +38,7 @@ public class UserManagerImplementationInformation public UserManagerImplementationInformation( String beanId, String descriptionKey, boolean readOnly ) { - this.beanId = beanId; - this.descriptionKey = descriptionKey; - this.readOnly = readOnly; - } - - public String getBeanId() - { - return beanId; - } - - public void setBeanId( String beanId ) - { - this.beanId = beanId; + super( beanId, descriptionKey, readOnly ); } - public String getDescriptionKey() - { - return descriptionKey; - } - - public void setDescriptionKey( String descriptionKey ) - { - this.descriptionKey = descriptionKey; - } - - public boolean isReadOnly() - { - return readOnly; - } - - public void setReadOnly( boolean readOnly ) - { - this.readOnly = readOnly; - } - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder(); - sb.append( "UserManagerImplementationInformation" ); - sb.append( "{beanId='" ).append( beanId ).append( '\'' ); - sb.append( ", descriptionKey='" ).append( descriptionKey ).append( '\'' ); - sb.append( '}' ); - return sb.toString(); - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( !( o instanceof UserManagerImplementationInformation ) ) - { - return false; - } - - UserManagerImplementationInformation that = (UserManagerImplementationInformation) o; - - if ( !beanId.equals( that.beanId ) ) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - return beanId.hashCode(); - } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RedbackRuntimeConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RedbackRuntimeConfigurationService.java index 68a0abd10..3573b7f61 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RedbackRuntimeConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RedbackRuntimeConfigurationService.java @@ -21,6 +21,7 @@ package org.apache.archiva.rest.api.services; import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration; import org.apache.archiva.admin.model.beans.LdapConfiguration; import org.apache.archiva.redback.authorization.RedbackAuthorization; +import org.apache.archiva.rest.api.model.RBACManagerImplementationInformation; import org.apache.archiva.rest.api.model.UserManagerImplementationInformation; import org.apache.archiva.security.common.ArchivaRoleConstants; @@ -55,13 +56,20 @@ public interface RedbackRuntimeConfigurationService Boolean updateRedbackRuntimeConfiguration( RedbackRuntimeConfiguration redbackRuntimeConfiguration ) throws ArchivaRestServiceException; - @Path("userManagerImplementationInformation") + @Path("userManagerImplementationInformations") @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION) List getUserManagerImplementationInformations() throws ArchivaRestServiceException; + @Path("rbacManagerImplementationInformations") + @GET + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION) + List getRbacManagerImplementationInformations() + throws ArchivaRestServiceException; + @Path( "checkLdapConnection" ) @GET diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java index 9a6df4237..b81f35771 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java @@ -33,7 +33,9 @@ import org.apache.archiva.redback.common.ldap.connection.LdapException; import org.apache.archiva.redback.components.cache.Cache; import org.apache.archiva.redback.policy.CookieSettings; import org.apache.archiva.redback.policy.PasswordRule; +import org.apache.archiva.redback.rbac.RBACManager; import org.apache.archiva.redback.users.UserManager; +import org.apache.archiva.rest.api.model.RBACManagerImplementationInformation; import org.apache.archiva.rest.api.model.UserManagerImplementationInformation; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.RedbackRuntimeConfigurationService; @@ -199,6 +201,34 @@ public class DefaultRedbackRuntimeConfigurationService return informations; } + public List getRbacManagerImplementationInformations() + throws ArchivaRestServiceException + { + Map beans = applicationContext.getBeansOfType( RBACManager.class ); + + if ( beans.isEmpty() ) + { + return Collections.emptyList(); + } + + List informations = + new ArrayList( beans.size() ); + + for ( Map.Entry entry : beans.entrySet() ) + { + UserManager userManager = applicationContext.getBean( entry.getKey(), UserManager.class ); + if ( userManager.isFinalImplementation() ) + { + RBACManagerImplementationInformation information = new RBACManagerImplementationInformation(); + information.setBeanId( StringUtils.substringAfter( entry.getKey(), "#" ) ); + information.setDescriptionKey( userManager.getDescriptionKey() ); + information.setReadOnly( userManager.isReadOnly() ); + informations.add( information ); + } + } + + return informations; + } public Boolean checkLdapConnection() throws ArchivaRestServiceException diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java index fd7d2e3f7..4f5ed5163 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java @@ -329,4 +329,15 @@ public class ArchivaRbacManager { log.warn( "eraseDatabase not implemented" ); } + + @Override + public boolean isFinalImplementation() + { + return false; + } + + public String getDescriptionKey() + { + return "archiva.redback.rbacmanager.archiva"; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/general-admin.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/general-admin.js index 9b0761b86..a859b91e8 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/general-admin.js +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/general-admin.js @@ -1217,7 +1217,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" RedbackRuntimeConfiguration=function(userManagerImpls,ldapConfiguration,migratedFromRedbackConfiguration,configurationPropertiesEntries - ,useUsersCache,cacheConfiguration){ + ,useUsersCache,cacheConfiguration,rbacManagerImpls){ $.log("new RedbackRuntimeConfiguration"); var self=this; this.modified=ko.observable(false); @@ -1226,6 +1226,9 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" this.userManagerImpls=ko.observableArray(userManagerImpls); this.userManagerImpls.subscribe(function(newValue){self.modified(true)}); + this.rbacManagerImpls=ko.observableArray(rbacManagerImpls); + this.rbacManagerImpls.subscribe(function(newValue){self.modified(true)}); + this.ldapConfiguration=ko.observable(ldapConfiguration); this.ldapConfiguration.subscribe(function(newValue){self.modified(true)}); @@ -1270,7 +1273,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" var redbackRuntimeConfiguration = new RedbackRuntimeConfiguration(data.userManagerImpls,ldapConfiguration,data.migratedFromRedbackConfiguration,[] - ,data.useUsersCache,mapCacheConfiguration(data.usersCacheConfiguration)); + ,data.useUsersCache,mapCacheConfiguration(data.usersCacheConfiguration),data.rbacManagerImpls); var configurationPropertiesEntries = data.configurationPropertiesEntries == null ? []: $.each(data.configurationPropertiesEntries,function(item){ @@ -1372,6 +1375,8 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" this.usedUserManagerImpls=ko.observableArray([]); + this.rbacManagerImpls=ko.observableArray([]); + this.modifiesLdapGroupMappings=ko.observableArray([]); this.allRoleNames=[]; @@ -1692,7 +1697,7 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" var mainContent = $("#main-content"); mainContent.html(mediumSpinnerImg()); - $.ajax("restServices/archivaServices/redbackRuntimeConfigurationService/userManagerImplementationInformation", { + $.ajax("restServices/archivaServices/redbackRuntimeConfigurationService/userManagerImplementationInformations", { type: "GET", dataType: 'json', success: function(data) { @@ -1706,7 +1711,9 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" new RedbackRuntimeConfigurationViewModel(redbackRuntimeConfiguration,userManagerImplementationInformations); var groups=[]; - + var useLdap = $.inArray("ldap",redbackRuntimeConfiguration.usedUserManagerImpls)>0 + ||$.inArray("ldap",redbackRuntimeConfiguration.rbacManagerImpls)>0; + $.log("useLdap:"+useLdap); // load ldap roles $.ajax("restServices/redbackServices/ldapGroupMappingService/ldapGroups", { type: "GET", @@ -1716,7 +1723,8 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" $.log("groups number:"+groups.length); redbackRuntimeConfiguration.ldapGroups=ko.observableArray(groups); } - } ).always( + } ) + .always( function() { $.log("complete");