001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.vfs;
018:
019: import java.util.Map;
020: import java.util.TreeMap;
021: import java.util.Iterator;
022:
023: /**
024: * Container for various authentication data
025: */
026: public class UserAuthenticationData {
027: public static class Type implements Comparable {
028: private final String type;
029:
030: public Type(String type) {
031: this .type = type;
032: }
033:
034: public boolean equals(Object o) {
035: if (this == o) {
036: return true;
037: }
038: if (o == null || getClass() != o.getClass()) {
039: return false;
040: }
041:
042: Type type1 = (Type) o;
043:
044: if (type != null ? !type.equals(type1.type)
045: : type1.type != null) {
046: return false;
047: }
048:
049: return true;
050: }
051:
052: public int compareTo(Object o) {
053: Type t = (Type) o;
054:
055: return type.compareTo(t.type);
056: }
057: }
058:
059: public static final Type USERNAME = new Type("username");
060: public static final Type PASSWORD = new Type("password");
061: public static final Type DOMAIN = new Type("domain");
062:
063: private Map authenticationData = new TreeMap();
064:
065: public UserAuthenticationData() {
066: }
067:
068: /**
069: * set a data to this collection
070: */
071: public void setData(Type type, char[] data) {
072: authenticationData.put(type, data);
073: }
074:
075: /**
076: * get a data from the collection
077: */
078: public char[] getData(Type type) {
079: return (char[]) authenticationData.get(type);
080: }
081:
082: /**
083: * deleted all data stored within this authenticator
084: */
085: public void cleanup() {
086: // step 1: nullify character buffers
087: Iterator iterAuthenticationData = authenticationData.values()
088: .iterator();
089: while (iterAuthenticationData.hasNext()) {
090: char[] data = (char[]) iterAuthenticationData.next();
091: if (data == null || data.length < 0) {
092: continue;
093: }
094:
095: for (int i = 0; i < data.length; i++) {
096: data[i] = 0;
097: }
098: }
099: // step 2: allow data itself to gc
100: authenticationData.clear();
101: }
102: }
|