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