1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.spi.impl;
18
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
21
22 import org.apache.jetspeed.security.InvalidPasswordException;
23 import org.apache.jetspeed.security.SecurityException;
24 import org.apache.jetspeed.security.spi.CredentialPasswordValidator;
25
26 /***
27 * <p>
28 * DefaultCredentialPasswordValidator
29 * </p>
30 *
31 * @author <a href="mailto:ate@apache.org">Ate Douma</a>
32 * @version $Id: DefaultCredentialPasswordValidator.java 601032 2007-12-04 18:45:55Z taylor $
33 */
34 public class DefaultCredentialPasswordValidator implements CredentialPasswordValidator
35 {
36 private String passwordPattern;
37 private boolean strictPassword = false;
38
39
40
41
42
43 private final static String defaultPasswordPattern = "[^.*(?=.{6,})(?=.*//d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$]";
44
45 public DefaultCredentialPasswordValidator(String passwordPattern)
46 {
47 this.passwordPattern = passwordPattern;
48 this.strictPassword = true;
49 }
50 public DefaultCredentialPasswordValidator()
51 {
52 strictPassword = false;
53 }
54
55 /***
56 * @see org.apache.jetspeed.security.spi.CredentialPasswordValidator#validate(java.lang.String)
57 */
58 public void validate(String clearTextPassword) throws SecurityException
59 {
60 if (strictPassword)
61 {
62 Pattern p = Pattern.compile(passwordPattern);
63
64 Matcher m = p.matcher(clearTextPassword);
65 if(!m.matches())
66 throw new InvalidPasswordException();
67 }
68 else
69 {
70 if ( clearTextPassword == null || clearTextPassword.length() == 0)
71 throw new InvalidPasswordException();
72 }
73
74 }
75 }