moving configuration keys to a constant class

git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1417537 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-05 17:21:51 +00:00
parent 498776efeb
commit f66c4d295a
17 changed files with 137 additions and 98 deletions

View File

@ -23,6 +23,7 @@ import org.apache.archiva.redback.authentication.AuthenticationConstants;
import org.apache.archiva.redback.common.ldap.UserMapper; import org.apache.archiva.redback.common.ldap.UserMapper;
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory; import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
import org.apache.archiva.redback.configuration.UserConfiguration; import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.archiva.redback.authentication.AuthenticationDataSource; import org.apache.archiva.redback.authentication.AuthenticationDataSource;
import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationException;
@ -83,9 +84,9 @@ public class LdapBindAuthenticator
{ {
PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s; PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
if ( !config.getBoolean( "ldap.bind.authenticator.enabled" ) || ( if ( !config.getBoolean( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED ) || (
!config.getBoolean( "ldap.bind.authenticator.allowEmptyPasswords", false ) && StringUtils.isEmpty( !config.getBoolean( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ALLOW_EMPTY_PASSWORDS, false )
source.getPassword() ) ) ) && StringUtils.isEmpty( source.getPassword() ) ) )
{ {
return new AuthenticationResult( false, source.getPrincipal(), null ); return new AuthenticationResult( false, source.getPrincipal(), null );
} }

View File

@ -35,7 +35,7 @@ import java.util.Date;
/** /**
* @author <a href="jesse@codehaus.org"> jesse * @author <a href="jesse@codehaus.org"> jesse
*/ */
@Service( "userMapper#ldap" ) @Service("userMapper#ldap")
public class LdapUserMapper public class LdapUserMapper
implements UserMapper implements UserMapper
{ {
@ -80,7 +80,7 @@ public class LdapUserMapper
int maxResultCount = 0; int maxResultCount = 0;
@Inject @Inject
@Named( value = "userConfiguration" ) @Named(value = "userConfiguration")
private UserConfiguration userConf; private UserConfiguration userConf;
@PostConstruct @PostConstruct
@ -97,7 +97,7 @@ public class LdapUserMapper
userObjectClass = userObjectClass =
userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_OBJECT_CLASS, userObjectClass ); userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_OBJECT_CLASS, userObjectClass );
userFilter = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_FILTER, userFilter ); userFilter = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_FILTER, userFilter );
maxResultCount = userConf.getInt( "ldap.config.max.result.count", maxResultCount ); maxResultCount = userConf.getInt( UserConfigurationKeys.LDAP_MAX_RESULT_COUNT, maxResultCount );
} }
public Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged ) public Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )

View File

@ -76,12 +76,12 @@ public class ConfigurableLdapConnectionFactory
{ {
configuration = new LdapConnectionConfiguration(); configuration = new LdapConnectionConfiguration();
configuration.setHostname( userConf.getString( UserConfigurationKeys.LDAP_HOSTNAME, hostname ) ); configuration.setHostname( userConf.getString( UserConfigurationKeys.LDAP_HOSTNAME, hostname ) );
configuration.setPort( userConf.getInt( "ldap.config.port", port ) ); configuration.setPort( userConf.getInt( UserConfigurationKeys.LDAP_PORT, port ) );
configuration.setSsl( userConf.getBoolean( "ldap.config.ssl", ssl ) ); configuration.setSsl( userConf.getBoolean( UserConfigurationKeys.LDAP_SSL, ssl ) );
configuration.setBaseDn( userConf.getConcatenatedList( "ldap.config.base.dn", baseDn ) ); configuration.setBaseDn( userConf.getConcatenatedList( UserConfigurationKeys.LDAP_BASEDN, baseDn ) );
configuration.setContextFactory( configuration.setContextFactory(
userConf.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY, contextFactory ) ); userConf.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY, contextFactory ) );
configuration.setBindDn( userConf.getConcatenatedList( "ldap.config.bind.dn", bindDn ) ); configuration.setBindDn( userConf.getConcatenatedList( UserConfigurationKeys.LDAP_BINDDN, bindDn ) );
configuration.setPassword( userConf.getString( UserConfigurationKeys.LDAP_PASSWORD, password ) ); configuration.setPassword( userConf.getString( UserConfigurationKeys.LDAP_PASSWORD, password ) );
configuration.setAuthenticationMethod( configuration.setAuthenticationMethod(
userConf.getString( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, authenticationMethod ) ); userConf.getString( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, authenticationMethod ) );

View File

@ -176,7 +176,6 @@ public class DefaultUserConfiguration
public String getConcatenatedList( String key, String defaultValue ) public String getConcatenatedList( String key, String defaultValue )
{ {
String concatenatedList;
List<String> list = getList( key ); List<String> list = getList( key );
if ( !list.isEmpty() ) if ( !list.isEmpty() )
{ {
@ -189,14 +188,11 @@ public class DefaultUserConfiguration
} }
s.append( value ); s.append( value );
} }
concatenatedList = s.toString(); log.debug( "getList for key {} return {}", key, s.toString() );
return s.toString();
} }
else log.debug( "getList for key {} return {}", key, defaultValue );
{ return defaultValue;
concatenatedList = defaultValue;
}
return concatenatedList;
} }
/** /**

View File

@ -45,18 +45,30 @@ public interface UserConfigurationKeys
String REMEMBER_ME_DOMAIN = "security.rememberme.domain"; String REMEMBER_ME_DOMAIN = "security.rememberme.domain";
String REMEMBER_ME_ENABLED = "security.rememberme.enabled";
String SIGNON_DOMAIN = "security.signon.domain"; String SIGNON_DOMAIN = "security.signon.domain";
String SIGNON_PATH = "security.signon.path"; String SIGNON_PATH = "security.signon.path";
String SIGNON_TIMEOUT = "security.signon.timeout";
String LDAP_HOSTNAME = "ldap.config.hostname"; String LDAP_HOSTNAME = "ldap.config.hostname";
String LDAP_PORT = "ldap.config.port";
String LDAP_SSL = "ldap.config.ssl";
String LDAP_CONTEX_FACTORY = "ldap.config.context.factory"; String LDAP_CONTEX_FACTORY = "ldap.config.context.factory";
String LDAP_PASSWORD = "ldap.config.password"; String LDAP_PASSWORD = "ldap.config.password";
String LDAP_AUTHENTICATION_METHOD = "ldap.config.authentication.method"; String LDAP_AUTHENTICATION_METHOD = "ldap.config.authentication.method";
String LDAP_BASEDN = "ldap.config.base.dn";
String LDAP_BINDDN = "ldap.config.bind.dn";
String APPLICATION_URL = "application.url"; String APPLICATION_URL = "application.url";
String EMAIL_URL_PATH = "email.url.path"; String EMAIL_URL_PATH = "email.url.path";
@ -72,4 +84,57 @@ public interface UserConfigurationKeys
String LDAP_MAPPER_USER_ATTRIBUTE_OBJECT_CLASS = "ldap.config.mapper.attribute.user.object.class"; String LDAP_MAPPER_USER_ATTRIBUTE_OBJECT_CLASS = "ldap.config.mapper.attribute.user.object.class";
String LDAP_MAPPER_USER_ATTRIBUTE_FILTER = "ldap.config.mapper.attribute.user.filter"; String LDAP_MAPPER_USER_ATTRIBUTE_FILTER = "ldap.config.mapper.attribute.user.filter";
String LDAP_MAX_RESULT_COUNT = "ldap.config.max.result.count";
String LDAP_BIND_AUTHENTICATOR_ENABLED = "ldap.bind.authenticator.enabled";
String LDAP_BIND_AUTHENTICATOR_ALLOW_EMPTY_PASSWORDS = "ldap.bind.authenticator.allowEmptyPasswords";
String PASSWORD_RETENTION_COUNT = "security.policy.password.previous.count";
String LOGIN_ATTEMPT_COUNT = "security.policy.allowed.login.attempt";
String PASSWORD_EXPIRATION_ENABLED = "security.policy.password.expiration.enabled";
String PASSWORD_EXPIRATION = "security.policy.password.expiration.days";
String UNLOCKABLE_ACCOUNTS = "security.policy.unlockable.accounts";
String EMAIL_VALIDATION_TIMEOUT = "email.validation.timeout";
String EMAIL_VALIDATION_REQUIRED = "email.validation.required";
String REMEMBERME_TIMEOUT = "security.rememberme.timeout";
String ALPHA_COUNT_MIN = "security.policy.password.rule.alphacount.minimum";
String ALPHA_COUNT_VIOLATION = "user.password.violation.alpha";
String CHARACTER_LENGTH_MIN = "security.policy.password.rule.characterlength.minimum";
String CHARACTER_LENGTH_MAX = "security.policy.password.rule.characterlength.maximum";
String CHARACTER_LENGTH_MISCONFIGURED_VIOLATION = "user.password.violation.length.misconfigured";
String CHARACTER_LENGTH_VIOLATION = "user.password.violation.length";
String MINIMUM = "security.policy.password.rule.numericalcount.minimum";
String NUMERICAL_COUNT_VIOLATION = "user.password.violation.numeric";
String POLICY_PASSWORD_RULE_ALPHANUMERIC_ENABLED = "security.policy.password.rule.alphanumeric.enabled";
String POLICY_PASSWORD_RULE_ALPHACOUNT_ENABLED = "security.policy.password.rule.alphacount.enabled";
String POLICY_PASSWORD_RULE_CHARACTERLENGTH_ENABLED = "security.policy.password.rule.characterlength.enabled";
String POLICY_PASSWORD_RULE_MUSTHAVE_ENABLED = "security.policy.password.rule.musthave.enabled";
String POLICY_PASSWORD_RULE_NUMERICALCOUNT_ENABLED = "security.policy.password.rule.numericalcount.enabled";
String POLICY_PASSWORD_RULE_REUSE_ENABLED = "security.policy.password.rule.reuse.enabled";
String POLICY_PASSWORD_RULE_NOWHITTESPACE_ENABLED = "security.policy.password.rule.nowhitespace.enabled";
} }

View File

@ -33,7 +33,6 @@ import javax.inject.Named;
* DefaultUserConfigurationTest * DefaultUserConfigurationTest
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
@RunWith( SpringJUnit4ClassRunner.class ) @RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } ) @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
@ -41,7 +40,8 @@ public class DefaultUserConfigurationTest
extends TestCase extends TestCase
{ {
@Inject @Named(value = "test") @Inject
@Named( value = "test" )
UserConfiguration config; UserConfiguration config;
private void assertEmpty( String str ) private void assertEmpty( String str )
@ -100,8 +100,9 @@ public class DefaultUserConfigurationTest
@Test @Test
public void testConcatenatedList() public void testConcatenatedList()
{ {
assertEquals( "uid=brett,dc=codehaus,dc=org", config.getConcatenatedList( "ldap.bind.dn", null ) ); assertEquals( "uid=brett,dc=codehaus,dc=org",
assertEquals( "dc=codehaus,dc=org", config.getConcatenatedList( "ldap.base.dn", null ) ); config.getConcatenatedList( UserConfigurationKeys.LDAP_BINDDN, null ) );
assertEquals( "dc=codehaus,dc=org", config.getConcatenatedList( UserConfigurationKeys.LDAP_BASEDN, null ) );
assertEquals( "foo", config.getConcatenatedList( "short.list", null ) ); assertEquals( "foo", config.getConcatenatedList( "short.list", null ) );
assertEquals( "bar,baz", config.getConcatenatedList( "no.list", "bar,baz" ) ); assertEquals( "bar,baz", config.getConcatenatedList( "no.list", "bar,baz" ) );
} }

View File

@ -41,45 +41,34 @@ import java.util.List;
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/ */
@Service( "userSecurityPolicy" ) @Service("userSecurityPolicy")
public class DefaultUserSecurityPolicy public class DefaultUserSecurityPolicy
implements UserSecurityPolicy implements UserSecurityPolicy
{ {
private static final String ENABLEMENT_KEY = "UserSecurityPolicy" + ":ENABLED"; private static final String ENABLEMENT_KEY = "UserSecurityPolicy" + ":ENABLED";
public static final String PASSWORD_RETENTION_COUNT = "security.policy.password.previous.count"; private Logger log = LoggerFactory.getLogger( getClass() );
public static final String LOGIN_ATTEMPT_COUNT = "security.policy.allowed.login.attempt";
public static final String PASSWORD_EXPIRATION_ENABLED = "security.policy.password.expiration.enabled";
public static final String PASSWORD_EXPIRATION = "security.policy.password.expiration.days";
public static final String UNLOCKABLE_ACCOUNTS = "security.policy.unlockable.accounts";
private static final Logger log = LoggerFactory.getLogger( DefaultUserSecurityPolicy.class );
private PasswordRule defaultPasswordRule = new MustHavePasswordRule(); private PasswordRule defaultPasswordRule = new MustHavePasswordRule();
@Inject @Inject
@Named( value = "userConfiguration" ) @Named(value = "userConfiguration")
private UserConfiguration config; private UserConfiguration config;
@Inject @Inject
@Named( value = "passwordEncoder#sha256" ) @Named(value = "passwordEncoder#sha256")
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@Inject @Inject
@Named( value = "userValidationSettings" ) @Named(value = "userValidationSettings")
private UserValidationSettings userValidationSettings; private UserValidationSettings userValidationSettings;
@Inject @Inject
@Named( value = "cookieSettings#rememberMe" ) @Named(value = "cookieSettings#rememberMe")
private CookieSettings rememberMeCookieSettings; private CookieSettings rememberMeCookieSettings;
@Inject @Inject
@Named( value = "cookieSettings#signon" ) @Named(value = "cookieSettings#signon")
private CookieSettings signonCookieSettings; private CookieSettings signonCookieSettings;
// TODO use something more generic to be able to do change about container // TODO use something more generic to be able to do change about container
@ -107,7 +96,7 @@ public class DefaultUserSecurityPolicy
// Component lifecycle // Component lifecycle
// --------------------------------------- // ---------------------------------------
// TODO move this to constructor // TODO move this to constructor
@SuppressWarnings( "unchecked" ) @SuppressWarnings("unchecked")
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
@ -141,11 +130,11 @@ public class DefaultUserSecurityPolicy
private void configurePolicy() private void configurePolicy()
{ {
this.previousPasswordsCount = config.getInt( PASSWORD_RETENTION_COUNT ); this.previousPasswordsCount = config.getInt( UserConfigurationKeys.PASSWORD_RETENTION_COUNT );
this.loginAttemptCount = config.getInt( LOGIN_ATTEMPT_COUNT ); this.loginAttemptCount = config.getInt( UserConfigurationKeys.LOGIN_ATTEMPT_COUNT );
this.passwordExpirationEnabled = config.getBoolean( PASSWORD_EXPIRATION_ENABLED ); this.passwordExpirationEnabled = config.getBoolean( UserConfigurationKeys.PASSWORD_EXPIRATION_ENABLED );
this.passwordExpirationDays = config.getInt( PASSWORD_EXPIRATION ); this.passwordExpirationDays = config.getInt( UserConfigurationKeys.PASSWORD_EXPIRATION );
this.unlockableAccounts = config.getList( UNLOCKABLE_ACCOUNTS ); this.unlockableAccounts = config.getList( UserConfigurationKeys.UNLOCKABLE_ACCOUNTS );
} }

View File

@ -62,8 +62,8 @@ public class DefaultUserValidationSettings
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
this.emailValidationRequired = config.getBoolean( "email.validation.required" ); this.emailValidationRequired = config.getBoolean( UserConfigurationKeys.EMAIL_VALIDATION_REQUIRED );
this.emailValidationTimeout = config.getInt( "email.validation.timeout" ); this.emailValidationTimeout = config.getInt( UserConfigurationKeys.EMAIL_VALIDATION_TIMEOUT );
this.emailSubject = config.getString( UserConfigurationKeys.EMAIL_VALIDATION_SUBJECT ); this.emailSubject = config.getString( UserConfigurationKeys.EMAIL_VALIDATION_SUBJECT );
} }
} }

View File

@ -44,9 +44,9 @@ public class RememberMeCookieSettings
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
this.cookieTimeout = config.getInt( "security.rememberme.timeout" ); this.cookieTimeout = config.getInt( UserConfigurationKeys.REMEMBERME_TIMEOUT );
this.domain = config.getString( UserConfigurationKeys.REMEMBER_ME_DOMAIN ); this.domain = config.getString( UserConfigurationKeys.REMEMBER_ME_DOMAIN );
this.path = config.getString( UserConfigurationKeys.REMEMBER_ME_PATH ); this.path = config.getString( UserConfigurationKeys.REMEMBER_ME_PATH );
this.enabled = config.getBoolean( "security.rememberme.enabled" ); this.enabled = config.getBoolean( UserConfigurationKeys.REMEMBER_ME_ENABLED );
} }
} }

View File

@ -38,7 +38,7 @@ public class SignonCookieSettings
public void initialize() public void initialize()
{ {
// cookie timeouts in the configuration settings is labeled to be in minutes, so adjust to minutes // cookie timeouts in the configuration settings is labeled to be in minutes, so adjust to minutes
cookieTimeout = config.getInt( "security.signon.timeout" ) * 60; cookieTimeout = config.getInt( UserConfigurationKeys.SIGNON_TIMEOUT ) * 60;
domain = config.getString( UserConfigurationKeys.SIGNON_DOMAIN ); domain = config.getString( UserConfigurationKeys.SIGNON_DOMAIN );
path = config.getString( UserConfigurationKeys.SIGNON_PATH ); path = config.getString( UserConfigurationKeys.SIGNON_PATH );
} }

View File

@ -16,6 +16,7 @@ package org.apache.archiva.redback.policy.rules;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
@ -25,7 +26,6 @@ import javax.annotation.PostConstruct;
/** /**
* Basic Password Rule. Checks that password only contains alpha-numeric characters. * Basic Password Rule. Checks that password only contains alpha-numeric characters.
*
*/ */
@Service("passwordRule#alpha-numeric") @Service("passwordRule#alpha-numeric")
public class AlphaNumericPasswordRule public class AlphaNumericPasswordRule
@ -56,6 +56,6 @@ public class AlphaNumericPasswordRule
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
enabled = config.getBoolean( "security.policy.password.rule.alphanumeric.enabled" ); enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_ALPHANUMERIC_ENABLED );
} }
} }

View File

@ -16,6 +16,7 @@ package org.apache.archiva.redback.policy.rules;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
@ -29,15 +30,11 @@ import javax.annotation.PostConstruct;
* alpha characters contained within. * alpha characters contained within.
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
@Service("passwordRule#alpha-count") @Service( "passwordRule#alpha-count" )
public class AlphaPasswordRule public class AlphaPasswordRule
extends AbstractPasswordRule extends AbstractPasswordRule
{ {
public static final String ALPHA_COUNT_MIN = "security.policy.password.rule.alphacount.minimum";
public static final String ALPHA_COUNT_VIOLATION = "user.password.violation.alpha";
private int minimumCount; private int minimumCount;
@ -95,15 +92,15 @@ public class AlphaPasswordRule
{ {
if ( countAlphaCharacters( user.getPassword() ) < this.minimumCount ) if ( countAlphaCharacters( user.getPassword() ) < this.minimumCount )
{ {
violations.addViolation( ALPHA_COUNT_VIOLATION, violations.addViolation( UserConfigurationKeys.ALPHA_COUNT_VIOLATION,
new String[]{String.valueOf( minimumCount )} ); //$NON-NLS-1$ new String[]{ String.valueOf( minimumCount ) } ); //$NON-NLS-1$
} }
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
enabled = config.getBoolean( "security.policy.password.rule.alphacount.enabled" ); enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_ALPHACOUNT_ENABLED );
this.minimumCount = config.getInt( ALPHA_COUNT_MIN ); this.minimumCount = config.getInt( UserConfigurationKeys.ALPHA_COUNT_MIN );
} }
} }

View File

@ -16,6 +16,7 @@ package org.apache.archiva.redback.policy.rules;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
@ -29,20 +30,11 @@ import javax.annotation.PostConstruct;
* {@link #setMaximumCharacters(int)} characters in length. * {@link #setMaximumCharacters(int)} characters in length.
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
@Service("passwordRule#character-length") @Service( "passwordRule#character-length" )
public class CharacterLengthPasswordRule public class CharacterLengthPasswordRule
extends AbstractPasswordRule extends AbstractPasswordRule
{ {
public static final String CHARACTER_LENGTH_MIN = "security.policy.password.rule.characterlength.minimum";
public static final String CHARACTER_LENGTH_MAX = "security.policy.password.rule.characterlength.maximum";
public static final String CHARACTER_LENGTH_MISCONFIGURED_VIOLATION =
"user.password.violation.length.misconfigured";
public static final String CHARACTER_LENGTH_VIOLATION = "user.password.violation.length";
public static final int DEFAULT_CHARACTER_LENGTH_MAX = 8; public static final int DEFAULT_CHARACTER_LENGTH_MAX = 8;
@ -81,8 +73,9 @@ public class CharacterLengthPasswordRule
{ {
/* this should caught up front during the configuration of the component */ /* this should caught up front during the configuration of the component */
// TODO: Throw runtime exception instead? // TODO: Throw runtime exception instead?
violations.addViolation( CHARACTER_LENGTH_MISCONFIGURED_VIOLATION, new String[]{ violations.addViolation( UserConfigurationKeys.CHARACTER_LENGTH_MISCONFIGURED_VIOLATION,
String.valueOf( minimumCharacters ), String.valueOf( maximumCharacters )} ); //$NON-NLS-1$ new String[]{ String.valueOf( minimumCharacters ),
String.valueOf( maximumCharacters ) } ); //$NON-NLS-1$
} }
String password = user.getPassword(); String password = user.getPassword();
@ -90,16 +83,17 @@ public class CharacterLengthPasswordRule
if ( StringUtils.isEmpty( password ) || password.length() < minimumCharacters || if ( StringUtils.isEmpty( password ) || password.length() < minimumCharacters ||
password.length() > maximumCharacters ) password.length() > maximumCharacters )
{ {
violations.addViolation( CHARACTER_LENGTH_VIOLATION, new String[]{String.valueOf( minimumCharacters ), violations.addViolation( UserConfigurationKeys.CHARACTER_LENGTH_VIOLATION,
String.valueOf( maximumCharacters )} ); //$NON-NLS-1$ new String[]{ String.valueOf( minimumCharacters ),
String.valueOf( maximumCharacters ) } ); //$NON-NLS-1$
} }
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
enabled = config.getBoolean( "security.policy.password.rule.characterlength.enabled" ); enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_CHARACTERLENGTH_ENABLED );
this.minimumCharacters = config.getInt( CHARACTER_LENGTH_MIN ); this.minimumCharacters = config.getInt( UserConfigurationKeys.CHARACTER_LENGTH_MIN );
this.maximumCharacters = config.getInt( CHARACTER_LENGTH_MAX ); this.maximumCharacters = config.getInt( UserConfigurationKeys.CHARACTER_LENGTH_MAX );
} }
} }

View File

@ -16,6 +16,7 @@ package org.apache.archiva.redback.policy.rules;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
@ -28,7 +29,6 @@ import javax.annotation.PostConstruct;
* Basic Password Rule, Checks for non-empty Passwords in non guest users. * Basic Password Rule, Checks for non-empty Passwords in non guest users.
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
@Service("passwordRule#must-have") @Service("passwordRule#must-have")
public class MustHavePasswordRule public class MustHavePasswordRule
@ -52,6 +52,6 @@ public class MustHavePasswordRule
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
enabled = config.getBoolean( "security.policy.password.rule.musthave.enabled" ); enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_MUSTHAVE_ENABLED );
} }
} }

View File

@ -16,6 +16,7 @@ package org.apache.archiva.redback.policy.rules;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
@ -29,15 +30,11 @@ import javax.annotation.PostConstruct;
* numerical characters contained within. * numerical characters contained within.
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
@Service("passwordRule#numerical-count") @Service( "passwordRule#numerical-count" )
public class NumericalPasswordRule public class NumericalPasswordRule
extends AbstractPasswordRule extends AbstractPasswordRule
{ {
public static final String MINIMUM = "security.policy.password.rule.numericalcount.minimum";
public static final String NUMERICAL_COUNT_VIOLATION = "user.password.violation.numeric";
private int minimumCount; private int minimumCount;
@ -95,15 +92,15 @@ public class NumericalPasswordRule
{ {
if ( countDigitCharacters( user.getPassword() ) < this.minimumCount ) if ( countDigitCharacters( user.getPassword() ) < this.minimumCount )
{ {
violations.addViolation( NUMERICAL_COUNT_VIOLATION, violations.addViolation( UserConfigurationKeys.NUMERICAL_COUNT_VIOLATION,
new String[]{String.valueOf( minimumCount )} ); //$NON-NLS-1$ new String[]{ String.valueOf( minimumCount ) } ); //$NON-NLS-1$
} }
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
enabled = config.getBoolean( "security.policy.password.rule.numericalcount.enabled" ); enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_NUMERICALCOUNT_ENABLED );
this.minimumCount = config.getInt( MINIMUM ); this.minimumCount = config.getInt( UserConfigurationKeys.MINIMUM );
} }
} }

View File

@ -16,6 +16,7 @@ package org.apache.archiva.redback.policy.rules;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
@ -30,7 +31,6 @@ import java.util.Iterator;
* the {@link User#getPreviousEncodedPasswords()} to ensure that a password is not reused. * the {@link User#getPreviousEncodedPasswords()} to ensure that a password is not reused.
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
@Service("passwordRule#reuse") @Service("passwordRule#reuse")
public class ReusePasswordRule public class ReusePasswordRule
@ -108,13 +108,13 @@ public class ReusePasswordRule
if ( hasReusedPassword( user, password ) ) if ( hasReusedPassword( user, password ) )
{ {
violations.addViolation( REUSE_VIOLATION, violations.addViolation( REUSE_VIOLATION,
new String[]{String.valueOf( getPreviousPasswordCount() )} ); //$NON-NLS-1$ new String[]{ String.valueOf( getPreviousPasswordCount() ) } ); //$NON-NLS-1$
} }
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
enabled = config.getBoolean( "security.policy.password.rule.reuse.enabled" ); enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_REUSE_ENABLED );
} }
} }

View File

@ -16,6 +16,7 @@ package org.apache.archiva.redback.policy.rules;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
@ -25,8 +26,6 @@ import javax.annotation.PostConstruct;
/** /**
* Basic Password Rule. Checks that password does not have whitespaces in it. * Basic Password Rule. Checks that password does not have whitespaces in it.
*
*
*/ */
@Service("passwordRule#no-whitespaces") @Service("passwordRule#no-whitespaces")
public class WhitespacePasswordRule public class WhitespacePasswordRule
@ -59,6 +58,6 @@ public class WhitespacePasswordRule
@PostConstruct @PostConstruct
public void initialize() public void initialize()
{ {
enabled = config.getBoolean( "security.policy.password.rule.nowhitespace.enabled" ); enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_NOWHITTESPACE_ENABLED );
} }
} }