From 3c6f8dc455d19f69dea8659d0cec71d9442fb3db Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 5 Dec 2012 12:56:48 +0000 Subject: [PATCH] moving configuration keys to a constant class git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1417396 13f79535-47bb-0310-9956-ffa450edef68 --- .../redback/common/ldap/LdapUserMapper.java | 17 ++++--- .../ConfigurableLdapConnectionFactory.java | 11 +++-- .../configuration/UserConfigurationKeys.java | 48 ++++++++++++++----- .../mail/VelocityMailGenerator.java | 5 +- .../configurable/ConfigurableUserManager.java | 2 +- 5 files changed, 55 insertions(+), 28 deletions(-) diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUserMapper.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUserMapper.java index 3add782ae..28e10390e 100644 --- a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUserMapper.java +++ b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUserMapper.java @@ -20,6 +20,7 @@ package org.apache.archiva.redback.common.ldap; */ import org.apache.archiva.redback.configuration.UserConfiguration; +import org.apache.archiva.redback.configuration.UserConfigurationKeys; import org.apache.archiva.redback.users.User; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; @@ -33,7 +34,6 @@ import java.util.Date; /** * @author jesse - * */ @Service( "userMapper#ldap" ) public class LdapUserMapper @@ -86,14 +86,17 @@ public class LdapUserMapper @PostConstruct public void initialize() { - emailAttribute = userConf.getString( "ldap.config.mapper.attribute.email", emailAttribute ); - fullNameAttribute = userConf.getString( "ldap.config.mapper.attribute.fullname", fullNameAttribute ); - passwordAttribute = userConf.getString( "ldap.config.mapper.attribute.password", passwordAttribute ); - userIdAttribute = userConf.getString( "ldap.config.mapper.attribute.user.id", userIdAttribute ); + emailAttribute = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_ATTRIBUTE_EMAIL, emailAttribute ); + fullNameAttribute = + userConf.getString( UserConfigurationKeys.LDAP_MAPPER_ATTRIBUTE_FULLNAME, fullNameAttribute ); + passwordAttribute = + userConf.getString( UserConfigurationKeys.LDAP_MAPPER_ATTRIBUTE_PASSWORD, passwordAttribute ); + userIdAttribute = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_ATTRIBUTE_ID, userIdAttribute ); userBaseDn = userConf.getConcatenatedList( "ldap.config.mapper.attribute.user.base.dn", userConf.getConcatenatedList( "ldap.config.base.dn", userBaseDn ) ); - userObjectClass = userConf.getString( "ldap.config.mapper.attribute.user.object.class", userObjectClass ); - userFilter = userConf.getString( "ldap.config.mapper.attribute.user.filter", userFilter ); + userObjectClass = + userConf.getString( UserConfigurationKeys.LDAP_MAPPER_ATTRIBUTE_OBJECT_CLASS, userObjectClass ); + userFilter = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_ATTRIBUTE_FILTER, userFilter ); maxResultCount = userConf.getInt( "ldap.config.max.result.count", maxResultCount ); } diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java index a3ac6f824..ebafd44fb 100644 --- a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java +++ b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java @@ -20,6 +20,7 @@ package org.apache.archiva.redback.common.ldap.connection; */ import org.apache.archiva.redback.configuration.UserConfiguration; +import org.apache.archiva.redback.configuration.UserConfigurationKeys; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; @@ -34,7 +35,6 @@ import java.util.Properties; /** * @author Trygve Laugstøl - * */ @Service( "ldapConnectionFactory#configurable" ) public class ConfigurableLdapConnectionFactory @@ -75,15 +75,16 @@ public class ConfigurableLdapConnectionFactory try { configuration = new LdapConnectionConfiguration(); - configuration.setHostname( userConf.getString( "ldap.config.hostname", hostname ) ); + configuration.setHostname( userConf.getString( UserConfigurationKeys.LDAP_HOSTNAME, hostname ) ); configuration.setPort( userConf.getInt( "ldap.config.port", port ) ); configuration.setSsl( userConf.getBoolean( "ldap.config.ssl", ssl ) ); configuration.setBaseDn( userConf.getConcatenatedList( "ldap.config.base.dn", baseDn ) ); - configuration.setContextFactory( userConf.getString( "ldap.config.context.factory", contextFactory ) ); + configuration.setContextFactory( + userConf.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY, contextFactory ) ); configuration.setBindDn( userConf.getConcatenatedList( "ldap.config.bind.dn", bindDn ) ); - configuration.setPassword( userConf.getString( "ldap.config.password", password ) ); + configuration.setPassword( userConf.getString( UserConfigurationKeys.LDAP_PASSWORD, password ) ); configuration.setAuthenticationMethod( - userConf.getString( "ldap.config.authentication.method", authenticationMethod ) ); + userConf.getString( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, authenticationMethod ) ); configuration.setExtraProperties( extraProperties ); } catch ( InvalidNameException e ) diff --git a/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/UserConfigurationKeys.java b/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/UserConfigurationKeys.java index 96b3f83c5..f00729b8b 100644 --- a/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/UserConfigurationKeys.java +++ b/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/UserConfigurationKeys.java @@ -24,30 +24,52 @@ package org.apache.archiva.redback.configuration; */ public interface UserConfigurationKeys { - static final String USER_MANAGER_IMPL = "user.manager.impl"; + String USER_MANAGER_IMPL = "user.manager.impl"; - static final String DEFAULT_ADMIN = "redback.default.admin"; + String DEFAULT_ADMIN = "redback.default.admin"; - static final String EMAIL_FROM_ADDRESS = "email.from.address"; + String EMAIL_FROM_ADDRESS = "email.from.address"; - static final String EMAIL_FROM_NAME = "email.from.name"; + String EMAIL_FROM_NAME = "email.from.name"; - static final String EMAIL_FEEDBACK_PATH = "email.feedback.path"; + String EMAIL_FEEDBACK_PATH = "email.feedback.path"; - static final String APPLICATION_TIMESTAMP = "application.timestamp"; + String APPLICATION_TIMESTAMP = "application.timestamp"; - static final String PASSWORD_ENCODER = "security.policy.password.encoder"; + String PASSWORD_ENCODER = "security.policy.password.encoder"; - static final String EMAIL_VALIDATION_SUBJECT = "email.validation.subject"; + String EMAIL_VALIDATION_SUBJECT = "email.validation.subject"; - static final String REMEMBER_ME_PATH = "security.rememberme.path"; + String REMEMBER_ME_PATH = "security.rememberme.path"; - static final String REMEMBER_ME_DOMAIN = "security.rememberme.domain"; + String REMEMBER_ME_DOMAIN = "security.rememberme.domain"; - static final String SIGNON_DOMAIN = "security.signon.domain"; + String SIGNON_DOMAIN = "security.signon.domain"; - static final String SIGNON_PATH = "security.signon.path"; + String SIGNON_PATH = "security.signon.path"; - static final String USER_MANAGER_IMPL = "user.manager.impl"; + String LDAP_HOSTNAME = "ldap.config.hostname"; + + String LDAP_CONTEX_FACTORY = "ldap.config.context.factory"; + + String LDAP_PASSWORD = "ldap.config.password"; + + String LDAP_AUTHENTICATION_METHOD = "ldap.config.authentication.method"; + + String APPLICATION_URL = "application.url"; + + String EMAIL_URL_PATH = "email.url.path"; + + String LDAP_MAPPER_ATTRIBUTE_EMAIL = "ldap.config.mapper.attribute.email"; + + String LDAP_MAPPER_ATTRIBUTE_FULLNAME = "ldap.config.mapper.attribute.fullname"; + + String LDAP_MAPPER_ATTRIBUTE_PASSWORD = "ldap.config.mapper.attribute.password"; + + String LDAP_MAPPER_ATTRIBUTE_ID = "ldap.config.mapper.attribute.user.id"; + + String LDAP_MAPPER_ATTRIBUTE_OBJECT_CLASS = "ldap.config.mapper.attribute.user.object.class"; + + String LDAP_MAPPER_ATTRIBUTE_FILTER = "ldap.config.mapper.attribute.user.filter"; } diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/mail/VelocityMailGenerator.java b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/mail/VelocityMailGenerator.java index 26ed81fc4..1db1a464f 100644 --- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/mail/VelocityMailGenerator.java +++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/mail/VelocityMailGenerator.java @@ -94,7 +94,7 @@ public class VelocityMailGenerator { VelocityContext context = new VelocityContext(); - context.put( "applicationUrl", config.getString( "application.url", appUrl ) ); + context.put( "applicationUrl", config.getString( UserConfigurationKeys.APPLICATION_URL, appUrl ) ); String feedback = config.getString( UserConfigurationKeys.EMAIL_FEEDBACK_PATH ); @@ -108,7 +108,8 @@ public class VelocityMailGenerator context.put( "feedback", feedback ); } - context.put( "urlPath", config.getString( "email.url.path", "security/login!login.action" ) ); + context.put( "urlPath", + config.getString( UserConfigurationKeys.EMAIL_URL_PATH, "security/login!login.action" ) ); context.put( "authkey", authkey.getKey() ); diff --git a/redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java b/redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java index 01d105202..d4a3a3616 100644 --- a/redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java +++ b/redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java @@ -52,7 +52,7 @@ public class ConfigurableUserManager @PostConstruct public void initialize() { - String userManagerRole = config.getString(); + String userManagerRole = config.getString( UserConfigurationKeys.USER_MANAGER_IMPL ); if ( userManagerRole == null ) { -- 2.39.5