1package org.apache.archiva.redback.policy.rules;
23/*4 * Copyright 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.apache.commons.lang.StringUtils;
24import org.springframework.stereotype.Service;
2526import javax.annotation.PostConstruct;
2728/**29 * Basic Password Rule, Checks for non-empty Passwords in non guest users.30 *31 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>32 */33 @Service("passwordRule#must-have")
34publicclassMustHavePasswordRule35extendsAbstractPasswordRule36 {
37publicstaticfinal String MISSING_PASSWORD_VIOLATION = "user.password.violation.missing";
3839publicvoid setUserSecurityPolicy( UserSecurityPolicy policy )
40 {
41// Ignore, policy not needed in this rule.42 }
4344publicvoid testPassword( PasswordRuleViolations violations, User user )
45 {
46if ( StringUtils.isEmpty( user.getPassword() ) )
47 {
48 violations.addViolation( MISSING_PASSWORD_VIOLATION ); //$NON-NLS-1$49 }
50 }
5152 @PostConstruct
53publicvoid initialize()
54 {
55 enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_MUSTHAVE_ENABLED );
56 }
57 }