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 org.apache.jetspeed.security.PasswordCredential;
20 import org.apache.jetspeed.security.SecurityException;
21 import org.apache.jetspeed.security.om.InternalCredential;
22 import org.apache.jetspeed.security.spi.CredentialPasswordEncoder;
23 import org.apache.jetspeed.security.spi.CredentialPasswordValidator;
24 import org.apache.jetspeed.security.spi.PasswordCredentialProvider;
25
26 /***
27 * <p>
28 * DefaultPasswordCredentialProvider
29 * </p>
30 *
31 * @author <a href="mailto:ate@apache.org">Ate Douma</a>
32 * @version $Id: DefaultPasswordCredentialProvider.java 516448 2007-03-09 16:25:47Z ate $
33 */
34 public class DefaultPasswordCredentialProvider implements PasswordCredentialProvider
35 {
36 private CredentialPasswordValidator validator;
37 private CredentialPasswordEncoder encoder;
38
39 public DefaultPasswordCredentialProvider()
40 {
41 this(new DefaultCredentialPasswordValidator(),null);
42 }
43
44 public DefaultPasswordCredentialProvider(CredentialPasswordValidator validator, CredentialPasswordEncoder encoder)
45 {
46 this.validator = validator;
47 this.encoder = encoder;
48 }
49
50 /***
51 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getPasswordCredentialClass()
52 */
53 public Class getPasswordCredentialClass()
54 {
55 return DefaultPasswordCredentialImpl.class;
56 }
57
58 /***
59 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getValidator()
60 */
61 public CredentialPasswordValidator getValidator()
62 {
63 return validator;
64 }
65
66 /***
67 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getEncoder()
68 */
69 public CredentialPasswordEncoder getEncoder()
70 {
71 return encoder;
72 }
73
74 /***
75 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#create(java.lang.String, java.lang.String)
76 */
77 public PasswordCredential create(String userName, String password) throws SecurityException
78 {
79 validator.validate(password);
80 PasswordCredential pc;
81 if ( encoder != null )
82 {
83 pc = new DefaultPasswordCredentialImpl(userName, encoder.encode(userName, password).toCharArray());
84 }
85 else
86 {
87 pc = new DefaultPasswordCredentialImpl(userName, password.toCharArray());
88 }
89 return pc;
90 }
91
92 /***
93 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#create(java.lang.String, org.apache.jetspeed.security.om.InternalCredential)
94 */
95 public PasswordCredential create(String userName, InternalCredential credential) throws SecurityException
96 {
97 return new DefaultPasswordCredentialImpl(userName, credential);
98 }
99 }