KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > web > security > WebPrincipal


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.web.security;
24
25 import java.security.Principal JavaDoc;
26 import java.security.cert.X509Certificate JavaDoc;
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 JavaDoc password;
34
35     private X509Certificate JavaDoc[] certs;
36
37     private boolean useCertificate;
38
39     private SecurityContext secCtx;
40
41     private Principal JavaDoc customPrincipal;
42
43     public WebPrincipal(Principal JavaDoc 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 JavaDoc user, String JavaDoc 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 JavaDoc[] 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 JavaDoc getPassword() {
69         return password;
70     }
71
72     public X509Certificate JavaDoc[] 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 JavaDoc getName() {
85     if (customPrincipal == null) {
86         return super.getName();
87     } else {
88         return customPrincipal.getName();
89     }
90     }
91
92     public boolean equals(Object JavaDoc 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 JavaDoc toString() {
108     if (customPrincipal == null) {
109         return super.toString();
110     }
111     return customPrincipal.toString();
112     }
113
114 }
115
116
Popular Tags