fix NPE and add alias

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1417978 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-06 16:23:47 +00:00
parent 2aa866124d
commit 75f17a0d8b
2 changed files with 283 additions and 43 deletions

View File

@ -29,6 +29,7 @@ import org.apache.archiva.configuration.IndeterminateConfigurationException;
import org.apache.archiva.configuration.RedbackRuntimeConfiguration;
import org.apache.archiva.redback.components.registry.RegistryException;
import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.archiva.redback.configuration.UserConfigurationException;
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
@ -36,15 +37,16 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
/**
* @author Olivier Lamy
* @since 1.4-M4
*/
@Service("archivaRuntimeConfigurationAdmin#default")
@Service( "userConfiguration#archiva" )
public class DefaultArchivaRuntimeConfigurationAdmin
extends AbstractRepositoryAdmin
implements ArchivaRuntimeConfigurationAdmin
implements ArchivaRuntimeConfigurationAdmin, UserConfiguration
{
@Inject
@ -53,9 +55,10 @@ public class DefaultArchivaRuntimeConfigurationAdmin
@PostConstruct
public void initialize()
throws RepositoryAdminException
throws UserConfigurationException
{
try
{
ArchivaRuntimeConfiguration archivaRuntimeConfiguration = getArchivaRuntimeConfiguration();
// migrate or not data from redback
if ( !archivaRuntimeConfiguration.isMigratedFromRedbackConfiguration() )
@ -80,11 +83,14 @@ public class DefaultArchivaRuntimeConfigurationAdmin
archivaLdapConfiguration.setHostName(
userConfiguration.getString( UserConfigurationKeys.LDAP_HOSTNAME, null ) );
archivaLdapConfiguration.setPort( userConfiguration.getInt( UserConfigurationKeys.LDAP_PORT, -1 ) );
archivaLdapConfiguration.setSsl( userConfiguration.getBoolean( UserConfigurationKeys.LDAP_SSL, false ) );
archivaLdapConfiguration.setBaseDn( userConfiguration.getConcatenatedList( "ldap.config.base.dn", null ) );
archivaLdapConfiguration.setSsl(
userConfiguration.getBoolean( UserConfigurationKeys.LDAP_SSL, false ) );
archivaLdapConfiguration.setBaseDn(
userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_BASEDN, null ) );
archivaLdapConfiguration.setContextFactory(
userConfiguration.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY, null ) );
archivaLdapConfiguration.setBindDn( userConfiguration.getConcatenatedList( "ldap.config.bind.dn", null ) );
archivaLdapConfiguration.setBindDn(
userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_BINDDN, null ) );
archivaLdapConfiguration.setPassword(
userConfiguration.getString( UserConfigurationKeys.LDAP_PASSWORD, null ) );
archivaLdapConfiguration.setAuthenticationMethod(
@ -93,12 +99,16 @@ public class DefaultArchivaRuntimeConfigurationAdmin
archivaRuntimeConfiguration.setMigratedFromRedbackConfiguration( true );
updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
}
}
}
catch ( RepositoryAdminException e )
{
throw new UserConfigurationException( e.getMessage(), e );
}
}
public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
throws RepositoryAdminException
{
return build( getArchivaConfiguration().getConfiguration().getRedbackRuntimeConfiguration() );
}
@ -132,4 +142,233 @@ public class DefaultArchivaRuntimeConfigurationAdmin
{
return new BeanReplicator().replicateBean( archivaRuntimeConfiguration, RedbackRuntimeConfiguration.class );
}
// wrapper for UserConfiguration to intercept values (and store it not yet migrated
public String getString( String key )
{
if ( UserConfigurationKeys.USER_MANAGER_IMPL.equals( key ) )
{
return getArchivaRuntimeConfiguration().getUserManagerImpl();
}
ArchivaRuntimeConfiguration conf = getArchivaRuntimeConfiguration();
if ( conf.getConfigurationProperties().containsKey( key ) )
{
return conf.getConfigurationProperties().get( key );
}
String value = userConfiguration.getString( key );
if ( value == null )
{
return null;
}
conf.getConfigurationProperties().put( key, value );
try
{
updateArchivaRuntimeConfiguration( conf );
}
catch ( RepositoryAdminException e )
{
log.error( "fail to save ArchivaRuntimeConfiguration: {}", e.getMessage(), e );
throw new RuntimeException( e.getMessage(), e );
}
return value;
}
public String getString( String key, String defaultValue )
{
if ( UserConfigurationKeys.LDAP_HOSTNAME.equals( key ) )
{
return getArchivaRuntimeConfiguration().getArchivaLdapConfiguration().getHostName();
}
if ( UserConfigurationKeys.LDAP_CONTEX_FACTORY.equals( key ) )
{
return getArchivaRuntimeConfiguration().getArchivaLdapConfiguration().getContextFactory();
}
if ( UserConfigurationKeys.LDAP_PASSWORD.equals( key ) )
{
return getArchivaRuntimeConfiguration().getArchivaLdapConfiguration().getPassword();
}
if ( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD.equals( key ) )
{
return getArchivaRuntimeConfiguration().getArchivaLdapConfiguration().getAuthenticationMethod();
}
ArchivaRuntimeConfiguration conf = getArchivaRuntimeConfiguration();
if ( conf.getConfigurationProperties().containsKey( key ) )
{
return conf.getConfigurationProperties().get( key );
}
String value = userConfiguration.getString( key, defaultValue );
if ( value == null )
{
return null;
}
conf.getConfigurationProperties().put( key, value );
try
{
updateArchivaRuntimeConfiguration( conf );
}
catch ( RepositoryAdminException e )
{
log.error( "fail to save ArchivaRuntimeConfiguration: {}", e.getMessage(), e );
throw new RuntimeException( e.getMessage(), e );
}
return value;
}
public int getInt( String key )
{
ArchivaRuntimeConfiguration conf = getArchivaRuntimeConfiguration();
if ( conf.getConfigurationProperties().containsKey( key ) )
{
return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
}
int value = userConfiguration.getInt( key );
conf.getConfigurationProperties().put( key, Integer.toString( value ) );
try
{
updateArchivaRuntimeConfiguration( conf );
}
catch ( RepositoryAdminException e )
{
log.error( "fail to save ArchivaRuntimeConfiguration: {}", e.getMessage(), e );
throw new RuntimeException( e.getMessage(), e );
}
return value;
}
public int getInt( String key, int defaultValue )
{
if ( UserConfigurationKeys.LDAP_PORT.equals( key ) )
{
return getArchivaRuntimeConfiguration().getArchivaLdapConfiguration().getPort();
}
ArchivaRuntimeConfiguration conf = getArchivaRuntimeConfiguration();
if ( conf.getConfigurationProperties().containsKey( key ) )
{
return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
}
int value = userConfiguration.getInt( key, defaultValue );
conf.getConfigurationProperties().put( key, Integer.toString( value ) );
try
{
updateArchivaRuntimeConfiguration( conf );
}
catch ( RepositoryAdminException e )
{
log.error( "fail to save ArchivaRuntimeConfiguration: {}", e.getMessage(), e );
throw new RuntimeException( e.getMessage(), e );
}
return value;
}
public boolean getBoolean( String key )
{
ArchivaRuntimeConfiguration conf = getArchivaRuntimeConfiguration();
if ( conf.getConfigurationProperties().containsKey( key ) )
{
return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
}
boolean value = userConfiguration.getBoolean( key );
conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
try
{
updateArchivaRuntimeConfiguration( conf );
}
catch ( RepositoryAdminException e )
{
log.error( "fail to save ArchivaRuntimeConfiguration: {}", e.getMessage(), e );
throw new RuntimeException( e.getMessage(), e );
}
return value;
}
public boolean getBoolean( String key, boolean defaultValue )
{
if ( UserConfigurationKeys.LDAP_SSL.equals( key ) )
{
return getArchivaRuntimeConfiguration().getArchivaLdapConfiguration().isSsl();
}
ArchivaRuntimeConfiguration conf = getArchivaRuntimeConfiguration();
if ( conf.getConfigurationProperties().containsKey( key ) )
{
return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
}
boolean value = userConfiguration.getBoolean( key );
conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
try
{
updateArchivaRuntimeConfiguration( conf );
}
catch ( RepositoryAdminException e )
{
log.error( "fail to save ArchivaRuntimeConfiguration: {}", e.getMessage(), e );
throw new RuntimeException( e.getMessage(), e );
}
return value;
}
public List<String> getList( String key )
{
List<String> value = userConfiguration.getList( key );
ArchivaRuntimeConfiguration conf = getArchivaRuntimeConfiguration();
// TODO concat values
conf.getConfigurationProperties().put( key, "" );
try
{
updateArchivaRuntimeConfiguration( conf );
}
catch ( RepositoryAdminException e )
{
log.error( "fail to save ArchivaRuntimeConfiguration: {}", e.getMessage(), e );
throw new RuntimeException( e.getMessage(), e );
}
return value;
}
public String getConcatenatedList( String key, String defaultValue )
{
if ( UserConfigurationKeys.LDAP_BASEDN.equals( key ) )
{
return getArchivaRuntimeConfiguration().getArchivaLdapConfiguration().getBaseDn();
}
if ( UserConfigurationKeys.LDAP_BINDDN.equals( key ) )
{
return getArchivaRuntimeConfiguration().getArchivaLdapConfiguration().getBindDn();
}
return userConfiguration.getConcatenatedList( key, defaultValue );
}
}

View File

@ -21,7 +21,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
@ -31,6 +30,8 @@
<context:property-placeholder location="classpath:application.properties"/>
<alias name="userConfiguration#archiva" alias="userConfiguration#default" />
<bean id="loggerManager" class="org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager"
init-method="initialize"/>
@ -139,7 +140,7 @@
<alias name="userManager#archiva" alias="userManager#configurable"/>
<bean name="ldapConnectionFactory" class="org.apache.archiva.redback.common.ldap.connection.ConfigurableLdapConnectionFactory">
<property name="userConf" ref="userConfiguration"/>
<property name="userConf" ref="userConfiguration#default"/>
</bean>
<!-- <component>