1 17 18 package org.apache.geronimo.security.jaas.server; 19 20 import java.io.Serializable ; 21 22 23 26 public class JaasSessionId implements Serializable { 27 private final long sessionId; 28 private final byte[] hash; 29 private transient int hashCode; 30 private transient String name; 31 32 public JaasSessionId(long sessionId, byte[] hash) { 33 this.sessionId = sessionId; 34 this.hash = hash; 35 } 36 37 public long getSessionId() { 38 return sessionId; 39 } 40 41 public byte[] getHash() { 42 return hash; 43 } 44 45 public boolean equals(Object obj) { 46 if (!(obj instanceof JaasSessionId)) return false; 47 48 JaasSessionId another = (JaasSessionId) obj; 49 if (another.sessionId != sessionId) return false; 50 for (int i = 0; i < hash.length; i++) { 51 if (another.hash[i] != hash[i]) return false; 52 } 53 return true; 54 } 55 56 public String toString() { 57 if (name == null) { 58 StringBuffer buffer = new StringBuffer (); 59 buffer.append('['); 60 buffer.append(sessionId); 61 buffer.append(":0x"); 62 for (int i = 0; i < hash.length; i++) { 63 buffer.append(HEXCHAR[(hash[i]>>>4)&0x0F]); 64 buffer.append(HEXCHAR[(hash[i] )&0x0F]); 65 } 66 buffer.append(']'); 67 name = buffer.toString(); 68 } 69 return name; 70 } 71 72 77 public int hashCode() { 78 if (hashCode == 0) { 79 for (int i = 0; i < hash.length; i++) { 80 hashCode ^= hash[i]; 81 } 82 hashCode ^= (int)(sessionId ^ (sessionId >>> 32)); 83 } 84 return hashCode; 85 } 86 87 private static final char[] HEXCHAR = { 88 '0', '1', '2', '3', '4', '5', '6', '7', 89 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' 90 }; 91 } 92 | Popular Tags |