1 17 18 package org.apache.geronimo.security; 19 20 import java.security.Principal ; 21 import java.io.Serializable ; 22 23 24 29 public class RealmPrincipal implements Principal , Serializable { 30 private final String realm; 31 private final String domain; 32 private final Principal principal; 33 private transient String name = null; 34 35 public RealmPrincipal(String realm, String domain, Principal principal) { 36 37 if (realm == null) throw new IllegalArgumentException ("realm is null"); 38 if (domain == null) throw new IllegalArgumentException ("domain is null"); 39 if (principal == null) throw new IllegalArgumentException ("principal is null"); 40 41 this.realm = realm; 42 this.domain = domain; 43 this.principal = principal; 44 } 45 46 public boolean equals(Object o) { 47 if (this == o) return true; 48 if (o == null || getClass() != o.getClass()) return false; 49 50 final RealmPrincipal that = (RealmPrincipal) o; 51 52 if (!domain.equals(that.domain)) return false; 53 if (!principal.equals(that.principal)) return false; 54 if (!realm.equals(that.realm)) return false; 55 56 return true; 57 } 58 59 public int hashCode() { 60 int result; 61 result = realm.hashCode(); 62 result = 29 * result + domain.hashCode(); 63 result = 29 * result + principal.hashCode(); 64 return result; 65 } 66 67 72 public String toString() { 73 return getName(); 74 } 75 76 81 public String getName() { 82 if (name == null) { 83 StringBuffer buffer = new StringBuffer (""); 84 buffer.append(realm); 85 buffer.append("::"); 86 buffer.append(domain); 87 buffer.append("::"); 88 buffer.append(principal.getClass().getName()); 89 buffer.append(':'); 90 buffer.append(principal.getName()); 91 92 name = buffer.toString(); 93 } 94 return name; 95 } 96 97 102 public String getRealm() { 103 return realm; 104 } 105 106 111 public Principal getPrincipal() { 112 return principal; 113 } 114 115 120 public String getLoginDomain() { 121 return domain; 122 } 123 } 124 | Popular Tags |