1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2;
18
19 import java.util.Arrays;
20 import java.util.Map;
21 import java.util.Objects;
22 import java.util.TreeMap;
23
24
25
26
27 public class UserAuthenticationData {
28
29
30
31
32 public static class Type implements Comparable<Type> {
33
34
35 private final String type;
36
37
38
39
40
41
42 public Type(final String type) {
43 this.type = type;
44 }
45
46 @Override
47 public boolean equals(final Object o) {
48 if (this == o) {
49 return true;
50 }
51 if (o == null || getClass() != o.getClass()) {
52 return false;
53 }
54 return Objects.equals(type, ((Type) o).type);
55 }
56
57 @Override
58 public int compareTo(final Type o) {
59 return type.compareTo(o.type);
60 }
61
62
63
64
65
66 @Override
67 public int hashCode() {
68 return type != null ? type.hashCode() : 0;
69 }
70
71
72
73
74
75 @Override
76 public String toString() {
77 return type;
78 }
79 }
80
81
82 public static final Type USERNAME = new Type("username");
83
84
85 public static final Type PASSWORD = new Type("password");
86
87
88 public static final Type DOMAIN = new Type("domain");
89
90
91 private final Map<Type, char[]> authenticationData = new TreeMap<>();
92
93
94
95
96 public UserAuthenticationData() {
97
98 }
99
100
101
102
103
104
105
106 public void setData(final Type type, final char[] data) {
107 authenticationData.put(type, data);
108 }
109
110
111
112
113
114
115
116 public char[] getData(final Type type) {
117 return authenticationData.get(type);
118 }
119
120
121
122
123 public void cleanup() {
124
125 for (final char[] data : authenticationData.values()) {
126 if (data == null) {
127 continue;
128 }
129
130 Arrays.fill(data, (char) 0);
131 }
132
133 authenticationData.clear();
134 }
135 }