1package org.apache.archiva.redback.policy.rules;
23/*4 * Copyright 2001-2006 The Apache Software Foundation.5 *6 * Licensed under the Apache License, Version 2.0 (the "License");7 * you may not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819import org.apache.archiva.redback.configuration.UserConfigurationKeys;
20import org.apache.archiva.redback.policy.PasswordRuleViolations;
21import org.apache.archiva.redback.policy.UserSecurityPolicy;
22import org.apache.archiva.redback.users.User;
23import org.springframework.stereotype.Service;
2425import javax.annotation.PostConstruct;
2627/**28 * Basic Password Rule. Checks that password only contains alpha-numeric characters.29 */30 @Service("passwordRule#alpha-numeric")
31publicclassAlphaNumericPasswordRule32extendsAbstractPasswordRule33 {
34publicstaticfinal String ALPHANUM_VIOLATION = "user.password.violation.alphanum.only";
3536publicvoid setUserSecurityPolicy( UserSecurityPolicy policy )
37 {
38// Ignore, policy not needed in this rule.39 }
4041publicvoid testPassword( PasswordRuleViolations violations, User user )
42 {
43char[] password = user.getPassword().toCharArray();
4445for ( int i = 0; i < password.length; i++ )
46 {
47if ( !Character.isLetterOrDigit( password[i] ) )
48 {
49 violations.addViolation( ALPHANUM_VIOLATION );
50return;
51 }
52 }
53 }
5455// FIXME to constructor56 @PostConstruct
57publicvoid initialize()
58 {
59 enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_ALPHANUMERIC_ENABLED );
60 }
61 }