1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs;
18
19 import java.util.Map;
20 import java.util.TreeMap;
21 import java.util.Iterator;
22
23 /***
24 * Container for various authentication data
25 */
26 public class UserAuthenticationData
27 {
28 public static class Type implements Comparable
29 {
30 private final String type;
31
32 public Type(String type)
33 {
34 this.type = type;
35 }
36
37 public boolean equals(Object o)
38 {
39 if (this == o)
40 {
41 return true;
42 }
43 if (o == null || getClass() != o.getClass())
44 {
45 return false;
46 }
47
48 Type type1 = (Type) o;
49
50 if (type != null ? !type.equals(type1.type) : type1.type != null)
51 {
52 return false;
53 }
54
55 return true;
56 }
57
58 public int compareTo(Object o)
59 {
60 Type t = (Type) o;
61
62 return type.compareTo(t.type);
63 }
64 }
65
66 public static final Type USERNAME = new Type("username");
67 public static final Type PASSWORD = new Type("password");
68 public static final Type DOMAIN = new Type("domain");
69
70 private Map authenticationData = new TreeMap();
71
72 public UserAuthenticationData()
73 {
74 }
75
76 /***
77 * set a data to this collection
78 */
79 public void setData(Type type, char[] data)
80 {
81 authenticationData.put(type, data);
82 }
83
84 /***
85 * get a data from the collection
86 */
87 public char[] getData(Type type)
88 {
89 return (char[]) authenticationData.get(type);
90 }
91
92 /***
93 * deleted all data stored within this authenticator
94 */
95 public void cleanup()
96 {
97
98 Iterator iterAuthenticationData = authenticationData.values().iterator();
99 while (iterAuthenticationData.hasNext())
100 {
101 char[] data = (char[]) iterAuthenticationData.next();
102 if (data == null || data.length < 0)
103 {
104 continue;
105 }
106
107 for (int i = 0; i<data.length; i++)
108 {
109 data[i]=0;
110 }
111 }
112
113 authenticationData.clear();
114 }
115 }