1 17 18 package org.apache.geronimo.security; 19 20 import java.io.Serializable ; 21 import java.security.Principal ; 22 23 28 public class DomainPrincipal implements Principal , Serializable { 29 private final String domain; 30 private final Principal principal; 31 private transient String name = null; 32 33 public DomainPrincipal(String domain, Principal principal) { 34 if (domain == null) throw new IllegalArgumentException ("domain is null"); 35 if (principal == null) throw new IllegalArgumentException ("principal is null"); 36 37 this.domain = domain; 38 this.principal = principal; 39 } 40 41 public boolean equals(Object o) { 42 if (this == o) return true; 43 if (o == null || getClass() != o.getClass()) return false; 44 45 final DomainPrincipal that = (DomainPrincipal) o; 46 47 if (!domain.equals(that.domain)) return false; 48 if (!principal.equals(that.principal)) return false; 49 50 return true; 51 } 52 53 58 public String toString() { 59 return getName(); 60 } 61 62 67 public int hashCode() { 68 int result; 69 result = domain.hashCode(); 70 result = 29 * result + principal.hashCode(); 71 return result; 72 } 73 74 79 public String getName() { 80 if (name == null) { 81 82 StringBuffer buffer = new StringBuffer (""); 83 buffer.append(domain); 84 buffer.append("::"); 85 buffer.append(principal.getClass().getName()); 86 buffer.append(':'); 87 buffer.append(principal.getName()); 88 buffer.append("]"); 89 90 name = buffer.toString(); 91 } 92 return name; 93 } 95 96 101 public Principal getPrincipal() { 102 return principal; 103 } 104 105 110 public String getDomain() { 111 return domain; 112 } 113 } 114 | Popular Tags |