]> source.dussan.org Git - archiva.git/commitdiff
service to provide available rbacmanager implementations informations
authorOlivier Lamy <olamy@apache.org>
Mon, 18 Feb 2013 09:28:48 +0000 (09:28 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 18 Feb 2013 09:28:48 +0000 (09:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1447164 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/UserManagerImplementationInformation.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RedbackRuntimeConfigurationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/general-admin.js

index 2e6f89182a62a2513ad0bcaab6c0e3759ecffe77..416123b0ab37d28b115d91321d3ba61cbd206526 100644 (file)
@@ -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<Role> 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<String, Role> getRoles( Collection<String> roleNames )
index 17ba2400d50d26d795c425ab250f83dd44d4bca2..b53998aa70b0e9b9edc911069ec5899947ab8f74 100644 (file)
@@ -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();
-    }
 }
index 68a0abd103c91f7c5a4051ddef0c76c23f1cd3d4..3573b7f61aaefd00f8ee5713295024d9b3a7c123 100644 (file)
@@ -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<UserManagerImplementationInformation> getUserManagerImplementationInformations()
         throws ArchivaRestServiceException;
 
+    @Path("rbacManagerImplementationInformations")
+    @GET
+    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    List<RBACManagerImplementationInformation> getRbacManagerImplementationInformations()
+        throws ArchivaRestServiceException;
+
 
     @Path( "checkLdapConnection" )
     @GET
index 9a6df42378f865ae0237e3529c7f376a0f70b737..b81f35771008c55fd8592b6119456b548dd06892 100644 (file)
@@ -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<RBACManagerImplementationInformation> getRbacManagerImplementationInformations()
+        throws ArchivaRestServiceException
+    {
+        Map<String, RBACManager> beans = applicationContext.getBeansOfType( RBACManager.class );
+
+        if ( beans.isEmpty() )
+        {
+            return Collections.emptyList();
+        }
+
+        List<RBACManagerImplementationInformation> informations =
+            new ArrayList<RBACManagerImplementationInformation>( beans.size() );
+
+        for ( Map.Entry<String, RBACManager> 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
index fd7d2e3f76513e9cd4aa29bc35543b78b936eee3..4f5ed5163ab62d1d4392dc144c848351f7325fac 100644 (file)
@@ -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";
+    }
 }
index 9b0761b86880a2a6b970d0de64efed77fb5e1d6d..a859b91e8ce4264af823b3882bcbcc957b12b3b2 100644 (file)
@@ -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");