01: /**
02: * $Id: NetFileUserInfo.java,v 1.7 2005/11/30 11:26:35 ss150821 Exp $
03: * Copyright 2002 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.netfile.servlet.java1;
14:
15: import java.util.*;
16: import com.sun.portal.log.common.PortalLogger;
17:
18: class NetFileUserInfo {
19: private String s_empty_string = "";
20: private static Hashtable users = new Hashtable();
21: private static Hashtable machines = new Hashtable();
22:
23: NetFileUserInfo(String userID) {
24:
25: if (users.containsKey(userID)) {
26: } else {
27: users.put(userID, this );
28: }
29: }
30:
31: static synchronized NetFileUserInfo get(String userID) {
32: NetFileUserInfo user = (NetFileUserInfo) users.get(userID);
33: if (user == null) {
34: user = new NetFileUserInfo(userID);
35: }
36: return user;
37: }
38:
39: void setInfo(String machineName, String userName, String password) {
40: machines.put(machineName, userName + "|" + password);
41: }
42:
43: String getInfo(String machine) {
44: String name = s_empty_string;
45: String value = s_empty_string;
46: String userInfo = s_empty_string;
47: String userName = s_empty_string;
48: String password = s_empty_string;
49: StringBuffer buf = new StringBuffer();
50: for (Enumeration e = machines.keys(); e.hasMoreElements();) {
51: name = (String) e.nextElement();
52: value = (String) machines.get(name);
53: int ndx = value.indexOf("|");
54: if (ndx >= 0) {
55: userName = value.substring(0, ndx);
56: password = value.substring(ndx + 1);
57: buf.append("MACHINE:").append(name).append("|").append(
58: "USER:").append(userName).append("|").append(
59: "PASS:").append(password).append("^");
60: }
61: }
62:
63: userInfo = buf.toString();
64: String userStr = s_empty_string;
65: int ndx1;
66: ndx1 = userInfo.indexOf(machine);
67: if (ndx1 >= 0) {
68: int ndx2 = userInfo.indexOf("^", ndx1);
69: userStr = userInfo.substring(ndx1 - 8, ndx2);
70:
71: return userStr;
72: } else {
73: return s_empty_string;
74: }
75: }
76: }
|