%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.security.spi.impl.DefaultPasswordCredentialProvider |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * 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 PasswordCredentialProvider |
|
35 | { |
|
36 | private CredentialPasswordValidator validator; |
|
37 | private CredentialPasswordEncoder encoder; |
|
38 | ||
39 | public DefaultPasswordCredentialProvider() |
|
40 | { |
|
41 | 0 | this(new DefaultCredentialPasswordValidator(),null); |
42 | 0 | } |
43 | ||
44 | public DefaultPasswordCredentialProvider(CredentialPasswordValidator validator, CredentialPasswordEncoder encoder) |
|
45 | 0 | { |
46 | 0 | this.validator = validator; |
47 | 0 | this.encoder = encoder; |
48 | 0 | } |
49 | ||
50 | /** |
|
51 | * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getPasswordCredentialClass() |
|
52 | */ |
|
53 | public Class getPasswordCredentialClass() |
|
54 | { |
|
55 | 0 | return DefaultPasswordCredentialImpl.class; |
56 | } |
|
57 | ||
58 | /** |
|
59 | * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getValidator() |
|
60 | */ |
|
61 | public CredentialPasswordValidator getValidator() |
|
62 | { |
|
63 | 0 | return validator; |
64 | } |
|
65 | ||
66 | /** |
|
67 | * @see org.apache.jetspeed.security.spi.PasswordCredentialProvider#getEncoder() |
|
68 | */ |
|
69 | public CredentialPasswordEncoder getEncoder() |
|
70 | { |
|
71 | 0 | 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 | 0 | validator.validate(password); |
80 | PasswordCredential pc; |
|
81 | 0 | if ( encoder != null ) |
82 | { |
|
83 | 0 | pc = new DefaultPasswordCredentialImpl(userName, encoder.encode(userName, password).toCharArray()); |
84 | } |
|
85 | else |
|
86 | { |
|
87 | 0 | pc = new DefaultPasswordCredentialImpl(userName, password.toCharArray()); |
88 | } |
|
89 | 0 | 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 | 0 | return new DefaultPasswordCredentialImpl(userName, credential); |
98 | } |
|
99 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |