01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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
35: PasswordCredentialProvider {
36: private CredentialPasswordValidator validator;
37: private CredentialPasswordEncoder encoder;
38:
39: public DefaultPasswordCredentialProvider() {
40: this (new DefaultCredentialPasswordValidator(), null);
41: }
42:
43: public DefaultPasswordCredentialProvider(
44: CredentialPasswordValidator validator,
45: CredentialPasswordEncoder encoder) {
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: return DefaultPasswordCredentialImpl.class;
55: }
56:
57: /**
58: * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getValidator()
59: */
60: public CredentialPasswordValidator getValidator() {
61: return validator;
62: }
63:
64: /**
65: * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getEncoder()
66: */
67: public CredentialPasswordEncoder getEncoder() {
68: return encoder;
69: }
70:
71: /**
72: * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#create(java.lang.String, java.lang.String)
73: */
74: public PasswordCredential create(String userName, String password)
75: throws SecurityException {
76: validator.validate(password);
77: PasswordCredential pc;
78: if (encoder != null) {
79: pc = new DefaultPasswordCredentialImpl(userName, encoder
80: .encode(userName, password).toCharArray());
81: } else {
82: pc = new DefaultPasswordCredentialImpl(userName, password
83: .toCharArray());
84: }
85: return pc;
86: }
87:
88: /**
89: * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#create(java.lang.String, org.apache.jetspeed.security.om.InternalCredential)
90: */
91: public PasswordCredential create(String userName,
92: InternalCredential credential) throws SecurityException {
93: return new DefaultPasswordCredentialImpl(userName, credential);
94: }
95: }
|