This project has retired. For details please refer to its Attic page.
WhitespacePasswordRule xref
View Javadoc

1   package org.apache.archiva.redback.policy.rules;
2   
3   /*
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 at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * 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 and
16   * limitations under the License.
17   */
18  
19  import org.apache.archiva.redback.configuration.UserConfigurationKeys;
20  import org.apache.archiva.redback.policy.PasswordRuleViolations;
21  import org.apache.archiva.redback.policy.UserSecurityPolicy;
22  import org.apache.archiva.redback.users.User;
23  import org.springframework.stereotype.Service;
24  
25  import javax.annotation.PostConstruct;
26  
27  /**
28   * Basic Password Rule. Checks that password does not have whitespaces in it.
29   */
30  @Service("passwordRule#no-whitespaces")
31  public class WhitespacePasswordRule
32      extends AbstractPasswordRule
33  {
34      public static final String NO_WHITE_SPACE_VIOLATION = "user.password.violation.whitespace.detected";
35  
36      public void setUserSecurityPolicy( UserSecurityPolicy policy )
37      {
38          // Ignore, policy not needed in this rule.
39      }
40  
41      public void testPassword( PasswordRuleViolations violations, User user )
42      {
43          if ( user.getPassword() != null )
44          {
45              char[] password = user.getPassword().toCharArray();
46  
47              for ( int i = 0; i < password.length; i++ )
48              {
49                  if ( Character.isWhitespace( password[i] ) )
50                  {
51                      violations.addViolation( NO_WHITE_SPACE_VIOLATION );
52                      return;
53                  }
54              }
55          }
56      }
57  
58      @PostConstruct
59      public void initialize()
60      {
61          enabled = config.getBoolean( UserConfigurationKeys.POLICY_PASSWORD_RULE_NOWHITTESPACE_ENABLED );
62      }
63  }