mirror of https://github.com/apache/archiva.git
add a service to be able to check ldap configuration
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1421465 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fedd25bc10
commit
6ccf27b7d1
|
@ -19,12 +19,14 @@ 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.admin.model.beans.LdapConfiguration;
|
||||||
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.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;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
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;
|
||||||
|
@ -35,28 +37,44 @@ import java.util.List;
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 1.4-M4
|
* @since 1.4-M4
|
||||||
*/
|
*/
|
||||||
@Path ( "/archivaRuntimeConfigurationService/" )
|
@Path("/archivaRuntimeConfigurationService/")
|
||||||
public interface ArchivaRuntimeConfigurationService
|
public interface ArchivaRuntimeConfigurationService
|
||||||
{
|
{
|
||||||
@Path ( "archivaRuntimeConfiguration" )
|
@Path("archivaRuntimeConfiguration")
|
||||||
@GET
|
@GET
|
||||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
|
@RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
|
||||||
ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
|
ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
|
||||||
throws ArchivaRestServiceException;
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
@Path ( "archivaRuntimeConfiguration" )
|
@Path("archivaRuntimeConfiguration")
|
||||||
@PUT
|
@PUT
|
||||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@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" )
|
@Path("userManagerImplementationInformation")
|
||||||
@GET
|
@GET
|
||||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
|
@RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
|
||||||
List<UserManagerImplementationInformation> getUserManagerImplementationInformations()
|
List<UserManagerImplementationInformation> getUserManagerImplementationInformations()
|
||||||
throws ArchivaRestServiceException;
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
|
|
||||||
|
@Path( "checkLdapConnection" )
|
||||||
|
@GET
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
|
||||||
|
Boolean checkLdapConnection()
|
||||||
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
|
@Path( "checkLdapConnection" )
|
||||||
|
@POST
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
|
||||||
|
Boolean checkLdapConnection( LdapConfiguration ldapConfiguration )
|
||||||
|
throws ArchivaRestServiceException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,12 @@ package org.apache.archiva.rest.services;
|
||||||
|
|
||||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
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.beans.LdapConfiguration;
|
||||||
import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
|
import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
|
||||||
|
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
|
||||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration;
|
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration;
|
||||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
|
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
|
||||||
|
import org.apache.archiva.redback.common.ldap.connection.LdapException;
|
||||||
import org.apache.archiva.redback.policy.CookieSettings;
|
import org.apache.archiva.redback.policy.CookieSettings;
|
||||||
import org.apache.archiva.redback.policy.PasswordRule;
|
import org.apache.archiva.redback.policy.PasswordRule;
|
||||||
import org.apache.archiva.redback.users.UserManager;
|
import org.apache.archiva.redback.users.UserManager;
|
||||||
|
@ -35,17 +38,19 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import javax.naming.InvalidNameException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 1.4-M4
|
* @since 1.4-M4
|
||||||
*/
|
*/
|
||||||
@Service( "archivaRuntimeConfigurationService#rest" )
|
@Service("archivaRuntimeConfigurationService#rest")
|
||||||
public class DefaultArchivaRuntimeConfigurationService
|
public class DefaultArchivaRuntimeConfigurationService
|
||||||
extends AbstractRestService
|
extends AbstractRestService
|
||||||
implements ArchivaRuntimeConfigurationService
|
implements ArchivaRuntimeConfigurationService
|
||||||
|
@ -54,14 +59,14 @@ public class DefaultArchivaRuntimeConfigurationService
|
||||||
private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
|
private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "userManager#configurable" )
|
@Named(value = "userManager#configurable")
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "ldapConnectionFactory#configurable" )
|
@Named(value = "ldapConnectionFactory#configurable")
|
||||||
private LdapConnectionFactory ldapConnectionFactory;
|
private LdapConnectionFactory ldapConnectionFactory;
|
||||||
|
|
||||||
public ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
|
public ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
|
||||||
|
@ -154,6 +159,83 @@ public class DefaultArchivaRuntimeConfigurationService
|
||||||
|
|
||||||
return informations;
|
return informations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Boolean checkLdapConnection()
|
||||||
|
throws ArchivaRestServiceException
|
||||||
|
{
|
||||||
|
LdapConnection ldapConnection = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ldapConnection = ldapConnectionFactory.getConnection();
|
||||||
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
log.warn( "fail to get LdapConnection: {}", e.getMessage() );
|
||||||
|
throw new ArchivaRestServiceException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
|
||||||
|
if ( ldapConnection != null )
|
||||||
|
{
|
||||||
|
ldapConnection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean checkLdapConnection( LdapConfiguration ldapConfiguration )
|
||||||
|
throws ArchivaRestServiceException
|
||||||
|
{
|
||||||
|
LdapConnection ldapConnection = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LdapConnectionConfiguration ldapConnectionConfiguration =
|
||||||
|
new LdapConnectionConfiguration( ldapConfiguration.getHostName(), ldapConfiguration.getPort(),
|
||||||
|
ldapConfiguration.getBaseDn(), ldapConfiguration.getContextFactory(),
|
||||||
|
ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(),
|
||||||
|
ldapConfiguration.getAuthenticationMethod(),
|
||||||
|
toProperties( ldapConfiguration.getExtraProperties() ) );
|
||||||
|
|
||||||
|
ldapConnection = ldapConnectionFactory.getConnection( ldapConnectionConfiguration );
|
||||||
|
}
|
||||||
|
catch ( InvalidNameException e )
|
||||||
|
{
|
||||||
|
log.warn( "fail to get LdapConnection: {}", e.getMessage() );
|
||||||
|
throw new ArchivaRestServiceException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
log.warn( "fail to get LdapConnection: {}", e.getMessage() );
|
||||||
|
throw new ArchivaRestServiceException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
|
||||||
|
if ( ldapConnection != null )
|
||||||
|
{
|
||||||
|
ldapConnection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Properties toProperties( Map<String, String> map )
|
||||||
|
{
|
||||||
|
Properties properties = new Properties();
|
||||||
|
if ( map == null || map.isEmpty() )
|
||||||
|
{
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
for ( Map.Entry<String, String> entry : map.entrySet() )
|
||||||
|
{
|
||||||
|
properties.put( entry.getKey(), entry.getValue() );
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue