[MRM-1714] using LDAP can be configurable with the ui

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
This commit is contained in:
Olivier Lamy 2012-11-23 18:35:43 +00:00
parent 0144a7f6d7
commit 4affdc7bbd
4 changed files with 71 additions and 3 deletions

View File

@ -20,6 +20,7 @@ package org.apache.archiva.rest.api.services;
import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration; import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
import org.apache.archiva.redback.authorization.RedbackAuthorization; import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.rest.api.model.UserManagerImplementationInformation;
import org.apache.archiva.security.common.ArchivaRoleConstants; import org.apache.archiva.security.common.ArchivaRoleConstants;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -28,6 +29,7 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.List;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
@ -50,4 +52,11 @@ public interface ArchivaRuntimeConfigurationService
@RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration ) Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
throws ArchivaRestServiceException; throws ArchivaRestServiceException;
@Path ( "userManagerImplementationInformation" )
@GET
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
List<UserManagerImplementationInformation> getUserManagerImplementationInformations()
throws ArchivaRestServiceException;
} }

View 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.beans.ArchivaRuntimeConfiguration;
import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin; import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
import org.apache.archiva.redback.users.UserManager; 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.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService; import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
@ -43,9 +49,12 @@ public class DefaultArchivaRuntimeConfigurationService
private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin; private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
@Inject @Inject
@Named ( value = "userManager#archiva" ) @Named ( value = "userManager#configurable" )
private UserManager userManager; private UserManager userManager;
@Inject
private ApplicationContext applicationContext;
public ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin() public ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
throws ArchivaRestServiceException throws ArchivaRestServiceException
{ {
@ -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;
}
} }

View File

@ -19,8 +19,13 @@ package org.apache.archiva.rest.services;
*/ */
import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration; 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 org.junit.Test;
import java.util.List;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
*/ */
@ -51,8 +56,18 @@ public class ArchivaRuntimeConfigurationServiceTest
archivaRuntimeConfiguration = getArchivaRuntimeConfigurationService().getArchivaRuntimeConfigurationAdmin(); archivaRuntimeConfiguration = getArchivaRuntimeConfigurationService().getArchivaRuntimeConfigurationAdmin();
assertEquals( "foo", archivaRuntimeConfiguration.getUserManagerImpl() ); 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 ) );
}
} }

View File

@ -29,6 +29,7 @@ import javax.inject.Inject;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
* @since 1.4-M4
*/ */
@Service ( "userManager#archiva" ) @Service ( "userManager#archiva" )
public class ArchivaConfigurableUsersManager public class ArchivaConfigurableUsersManager
@ -60,4 +61,9 @@ public class ArchivaConfigurableUsersManager
throw new RuntimeException( e.getMessage(), e ); throw new RuntimeException( e.getMessage(), e );
} }
} }
public String getDescriptionKey()
{
return "archiva.redback.usermanager.configurable.archiva";
}
} }