1 23 package com.sun.web.security; 24 25 import java.security.Principal ; 26 import java.security.cert.X509Certificate ; 27 import com.sun.enterprise.deployment.PrincipalImpl; 28 import com.sun.enterprise.security.SecurityContext; 29 30 public class WebPrincipal extends PrincipalImpl { 31 32 33 private String password; 34 35 private X509Certificate [] certs; 36 37 private boolean useCertificate; 38 39 private SecurityContext secCtx; 40 41 private Principal customPrincipal; 42 43 public WebPrincipal(Principal p, SecurityContext context) { 44 super(p.getName()); 45 if (!(p instanceof PrincipalImpl)) { 46 customPrincipal = p; 47 } 48 this.useCertificate = false; 49 this.secCtx = context; 50 } 51 52 public WebPrincipal(String user, String password, 53 SecurityContext context) { 54 super(user); 55 this.password = password; 56 this.useCertificate = false; 57 this.secCtx = context; 58 } 59 60 public WebPrincipal(X509Certificate [] certs, 61 SecurityContext context) { 62 super(certs[0].getSubjectDN().getName()); 63 this.certs = certs; 64 this.useCertificate = true; 65 this.secCtx = context; 66 } 67 68 public String getPassword() { 69 return password; 70 } 71 72 public X509Certificate [] getCertificates() { 73 return certs; 74 } 75 76 public boolean isUsingCertificate() { 77 return useCertificate; 78 } 79 80 public SecurityContext getSecurityContext() { 81 return secCtx; 82 } 83 84 public String getName() { 85 if (customPrincipal == null) { 86 return super.getName(); 87 } else { 88 return customPrincipal.getName(); 89 } 90 } 91 92 public boolean equals(Object another) { 93 94 if (customPrincipal == null) { 95 return super.equals(another); 96 } 97 return customPrincipal.equals(another); 98 } 99 100 public int hashCode() { 101 if (customPrincipal == null) { 102 return super.hashCode(); 103 } 104 return customPrincipal.hashCode(); 105 } 106 107 public String toString() { 108 if (customPrincipal == null) { 109 return super.toString(); 110 } 111 return customPrincipal.toString(); 112 } 113 114 } 115 116 | Popular Tags |