[ all classes ]
[ com.acciente.oacc ]
Coverage Summary for Class: PasswordCredentials (com.acciente.oacc)
Class | Method, % | Line, % |
---|---|---|
PasswordCredentials | 100% (2/ 2) | 100% (3/ 3) |
PasswordCredentials$Impl | 60% (3/ 5) | 41.7% (5/ 12) |
total | 71.4% (5/ 7) | 53.3% (8/ 15) |
1 /*
2 * Copyright 2009-2018, Acciente LLC
3 *
4 * Acciente LLC licenses this file to you under the
5 * Apache License, Version 2.0 (the "License"); you
6 * may not use this file except in compliance with the
7 * 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
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
14 * OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License.
17 */
18 package com.acciente.oacc;
19
20 import java.util.Arrays;
21
22 /**
23 * This is a {@link Credentials} implementation that may be used by an {@link AuthenticationProvider}
24 * that provides password-based authentication. The built-in {@link AuthenticationProvider} requires that the
25 * {@link Credentials} object passed be an instance of this class. If you implement a custom password-based
26 * {@link AuthenticationProvider}, it is recommended that you accept instances of this class, but you are
27 * not required to. If you accept instances of this class it allows switching to your implementation from
28 * the built-in implementation without any changes in the calling code.
29 * .
30 */
31 public abstract class PasswordCredentials implements Credentials {
32 /**
33 * Returns the password contained in this credentials instance
34 *
35 * @return a password as a char array
36 */
37 public abstract char[] getPassword();
38
39 public static PasswordCredentials newInstance(char[] password) {
40 return new Impl(password);
41 }
42
43 private static class Impl extends PasswordCredentials {
44 private final char[] password;
45
46 private Impl(char[] password) {
47 this.password = password;
48 }
49
50 @Override
51 public char[] getPassword() {
52 return password;
53 }
54
55 @Override
56 public boolean equals(Object other) {
57 if (this == other) {
58 return true;
59 }
60 if (other == null || getClass() != other.getClass()) {
61 return false;
62 }
63
64 Impl impl = (Impl) other;
65
66 return Arrays.equals(password, impl.password);
67 }
68
69 @Override
70 public int hashCode() {
71 return Arrays.hashCode(password);
72 }
73 }
74 }