1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing, software12* 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 and15* limitations under the License.16*/17packageorg.apache.jetspeed.security.spi.impl;
1819import org.apache.jetspeed.security.PasswordCredential;
20import org.apache.jetspeed.security.SecurityException;
21import org.apache.jetspeed.security.om.InternalCredential;
22import org.apache.jetspeed.security.spi.CredentialPasswordEncoder;
23import org.apache.jetspeed.security.spi.CredentialPasswordValidator;
24import org.apache.jetspeed.security.spi.PasswordCredentialProvider;
2526/***27 * <p>28 * DefaultPasswordCredentialProvider29 * </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 */34publicclassDefaultPasswordCredentialProvider implements PasswordCredentialProvider
35 {
36private CredentialPasswordValidator validator;
37private CredentialPasswordEncoder encoder;
3839publicDefaultPasswordCredentialProvider()
40 {
41this(newDefaultCredentialPasswordValidator(),null);
42 }
4344publicDefaultPasswordCredentialProvider(CredentialPasswordValidator validator, CredentialPasswordEncoder encoder)
45 {
46this.validator = validator;
47this.encoder = encoder;
48 }
4950/***51 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getPasswordCredentialClass()52 */53public Class getPasswordCredentialClass()
54 {
55return DefaultPasswordCredentialImpl.class;
56 }
5758/***59 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getValidator()60 */61public CredentialPasswordValidator getValidator()
62 {
63return validator;
64 }
6566/***67 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getEncoder()68 */69public CredentialPasswordEncoder getEncoder()
70 {
71return encoder;
72 }
7374/***75 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#create(java.lang.String, java.lang.String)76 */77public PasswordCredential create(String userName, String password) throws SecurityException
78 {
79 validator.validate(password);
80 PasswordCredential pc;
81if ( encoder != null )
82 {
83 pc = newDefaultPasswordCredentialImpl(userName, encoder.encode(userName, password).toCharArray());
84 }
85else86 {
87 pc = newDefaultPasswordCredentialImpl(userName, password.toCharArray());
88 }
89return pc;
90 }
9192/***93 * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#create(java.lang.String, org.apache.jetspeed.security.om.InternalCredential)94 */95public PasswordCredential create(String userName, InternalCredential credential) throws SecurityException
96 {
97returnnewDefaultPasswordCredentialImpl(userName, credential);
98 }
99 }