*/
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.rest.api.model.UserManagerImplementationInformation;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
* @author Olivier Lamy
* @since 1.4-M4
*/
-@Path ( "/archivaRuntimeConfigurationService/" )
+@Path("/archivaRuntimeConfigurationService/")
public interface ArchivaRuntimeConfigurationService
{
- @Path ( "archivaRuntimeConfiguration" )
+ @Path("archivaRuntimeConfiguration")
@GET
- @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
throws ArchivaRestServiceException;
- @Path ( "archivaRuntimeConfiguration" )
+ @Path("archivaRuntimeConfiguration")
@PUT
- @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
throws ArchivaRestServiceException;
- @Path ( "userManagerImplementationInformation" )
+ @Path("userManagerImplementationInformation")
@GET
- @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
List<UserManagerImplementationInformation> getUserManagerImplementationInformations()
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;
}
import org.apache.archiva.admin.model.RepositoryAdminException;
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.redback.common.ldap.connection.LdapConnection;
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.LdapException;
import org.apache.archiva.redback.policy.CookieSettings;
import org.apache.archiva.redback.policy.PasswordRule;
import org.apache.archiva.redback.users.UserManager;
import javax.inject.Inject;
import javax.inject.Named;
+import javax.naming.InvalidNameException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
/**
* @author Olivier Lamy
* @since 1.4-M4
*/
-@Service( "archivaRuntimeConfigurationService#rest" )
+@Service("archivaRuntimeConfigurationService#rest")
public class DefaultArchivaRuntimeConfigurationService
extends AbstractRestService
implements ArchivaRuntimeConfigurationService
private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
@Inject
- @Named( value = "userManager#configurable" )
+ @Named(value = "userManager#configurable")
private UserManager userManager;
@Inject
private ApplicationContext applicationContext;
@Inject
- @Named( value = "ldapConnectionFactory#configurable" )
+ @Named(value = "ldapConnectionFactory#configurable")
private LdapConnectionFactory ldapConnectionFactory;
public ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
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;
+ }
}