1 19 package gcc.rmi.iiop; 20 21 import gcc.security.*; 22 import gcc.util.*; 23 import java.util.*; 24 25 public class ObjectKey 26 { 27 public static final int TYPE_MANAGER = 'M'; 28 29 public static final int TYPE_SESSION = 'S'; 30 31 public int type; 32 public String username = ""; 33 public String password = ""; 34 public String component = ""; 35 public String sessionID = ""; 36 37 public byte[] encode() 38 { 39 int un = username.length(); 40 int pn = password.length(); 41 int cn = component.length(); 42 int sn = sessionID.length(); 43 StringBuffer keyBuffer = new StringBuffer(12 + un + pn + cn + sn); 44 keyBuffer.append("U="); 45 keyBuffer.append(username); 46 keyBuffer.append("\tP="); 47 keyBuffer.append(password); 48 keyBuffer.append("\tC="); 49 keyBuffer.append(component); 50 if (sn > 0) 51 { 52 keyBuffer.append("\tS="); 53 keyBuffer.append(sessionID); 54 } 55 byte[] bytes = SecurityInfo.encode(keyBuffer.toString()); 56 bytes[0] = (byte)type; 57 return bytes; 58 } 59 60 public void decode(byte[] bytes) 61 { 62 type = bytes.length == 0 ? 0 : bytes[0]; 63 String key = SecurityInfo.decode(bytes); 64 List items = ListUtil.getListWithSeparator(key, "\t"); 65 for (Iterator i = items.iterator(); i.hasNext();) 66 { 67 String item = (String)i.next(); 68 if (item.startsWith("U=")) 69 { 70 username = item.substring(2); 71 } 72 else if (item.startsWith("P=")) 73 { 74 password = item.substring(2); 75 } 76 else if (item.startsWith("C=")) 77 { 78 component = item.substring(2); 79 } 80 else if (item.startsWith("S=")) 81 { 82 sessionID = item.substring(2); 83 } 84 } 85 } 86 87 public void checkPassword() 88 { 89 User.getInstance(username).login(password); 90 } 91 } 92 | Popular Tags |