]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1714] using LDAP can be configurable with the ui
authorOlivier Lamy <olamy@apache.org>
Fri, 23 Nov 2012 18:35:43 +0000 (18:35 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 23 Nov 2012 18:35:43 +0000 (18:35 +0000)
add a rest service which return available userManager implementation.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1413021 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaRuntimeConfigurationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaRuntimeConfigurationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaRuntimeConfigurationServiceTest.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java

index 1b3e6b35665e3541c29773dc396015d0c5789158..f67f4aed88b8dc5029957846fd080566a5ac8ef3 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.archiva.rest.api.services;
 
 import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
 import org.apache.archiva.redback.authorization.RedbackAuthorization;
+import org.apache.archiva.rest.api.model.UserManagerImplementationInformation;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
 
 import javax.ws.rs.Consumes;
@@ -28,6 +29,7 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import java.util.List;
 
 /**
  * @author Olivier Lamy
@@ -50,4 +52,11 @@ public interface ArchivaRuntimeConfigurationService
     @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
     Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
         throws ArchivaRestServiceException;
+
+    @Path ( "userManagerImplementationInformation" )
+    @GET
+    @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    List<UserManagerImplementationInformation> getUserManagerImplementationInformations()
+        throws ArchivaRestServiceException;
 }
index e8727f87bcc89f4432cf5e71c3c0e778e9fd9168..df0b6eeb7d48e7edc3918e7306d3bb8b53fbf125 100644 (file)
@@ -22,13 +22,19 @@ import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
 import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
 import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.rest.api.model.UserManagerImplementationInformation;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
 import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService;
 import org.apache.commons.lang.StringUtils;
+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.Collections;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Olivier Lamy
@@ -43,9 +49,12 @@ public class DefaultArchivaRuntimeConfigurationService
     private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
 
     @Inject
-    @Named ( value = "userManager#archiva" )
+    @Named ( value = "userManager#configurable" )
     private UserManager userManager;
 
+    @Inject
+    private ApplicationContext applicationContext;
+
     public ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
         throws ArchivaRestServiceException
     {
@@ -66,7 +75,7 @@ public class DefaultArchivaRuntimeConfigurationService
         {
             // has user manager impl changed ?
             boolean userManagerChanged = !StringUtils.equals( archivaRuntimeConfiguration.getUserManagerImpl(),
-                                                             archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfigurationAdmin().getUserManagerImpl() );
+                                                              archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfigurationAdmin().getUserManagerImpl() );
             archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
 
             if ( userManagerChanged )
@@ -84,6 +93,35 @@ public class DefaultArchivaRuntimeConfigurationService
         }
 
     }
+
+    public List<UserManagerImplementationInformation> getUserManagerImplementationInformations()
+        throws ArchivaRestServiceException
+    {
+
+        Map<String, UserManager> beans = applicationContext.getBeansOfType( UserManager.class );
+
+        if ( beans.isEmpty() )
+        {
+            return Collections.emptyList();
+        }
+
+        List<UserManagerImplementationInformation> informations =
+            new ArrayList<UserManagerImplementationInformation>( beans.size() );
+
+        for ( Map.Entry<String, UserManager> entry : beans.entrySet() )
+        {
+            UserManager userManager = applicationContext.getBean( entry.getKey(), UserManager.class );
+            if ( userManager.isFinalImplementation() )
+            {
+                UserManagerImplementationInformation information = new UserManagerImplementationInformation();
+                information.setBeanId( StringUtils.substringAfter( entry.getKey(), "#" ) );
+                information.setDescriptionKey( userManager.getDescriptionKey() );
+                informations.add( information );
+            }
+        }
+
+        return informations;
+    }
 }
 
 
index 88225bf9318e3bb6bb603dd8cbd49d362ce8e961..80d7f79312be619096fc3cb9bd7b3c455fa9aca3 100644 (file)
@@ -19,8 +19,13 @@ package org.apache.archiva.rest.services;
  */
 
 import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
+import org.apache.archiva.rest.api.model.UserManagerImplementationInformation;
+import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService;
+import org.fest.assertions.api.Assertions;
 import org.junit.Test;
 
+import java.util.List;
+
 /**
  * @author Olivier Lamy
  */
@@ -51,8 +56,18 @@ public class ArchivaRuntimeConfigurationServiceTest
         archivaRuntimeConfiguration = getArchivaRuntimeConfigurationService().getArchivaRuntimeConfigurationAdmin();
         assertEquals( "foo", archivaRuntimeConfiguration.getUserManagerImpl() );
 
-
     }
 
 
+    @Test
+    public void usermanagersinformations()
+        throws Exception
+    {
+        ArchivaRuntimeConfigurationService service = getArchivaRuntimeConfigurationService();
+        List<UserManagerImplementationInformation> infos = service.getUserManagerImplementationInformations();
+        Assertions.assertThat( infos ).isNotNull().isNotEmpty().contains(
+            new UserManagerImplementationInformation( "jdo", null ) );
+
+    }
+
 }
index c12c138802a3d1c025728df8114a4f30f389bbf1..5a2a08e9b6be6e97ac8690b041e002d9e9f04603 100644 (file)
@@ -29,6 +29,7 @@ import javax.inject.Inject;
 
 /**
  * @author Olivier Lamy
+ * @since 1.4-M4
  */
 @Service ( "userManager#archiva" )
 public class ArchivaConfigurableUsersManager
@@ -60,4 +61,9 @@ public class ArchivaConfigurableUsersManager
             throw new RuntimeException( e.getMessage(), e );
         }
     }
+
+    public String getDescriptionKey()
+    {
+        return "archiva.redback.usermanager.configurable.archiva";
+    }
 }