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