KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > jauth > callback > PrivateKeyCallback


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
24 package com.sun.enterprise.security.jauth.callback;
25
26 import java.math.BigInteger JavaDoc;
27 import java.security.PrivateKey JavaDoc;
28 import java.security.cert.Certificate JavaDoc;
29 import javax.security.auth.callback.Callback JavaDoc;
30 import javax.security.auth.x500.X500Principal JavaDoc;
31
32 /**
33  * Callback for private key and corresponding certificate chain.
34  *
35  * @version %I%, %G%
36  */

37 public class PrivateKeyCallback implements Callback JavaDoc {
38
39     private Request request;
40     private PrivateKey JavaDoc key;
41     private Certificate JavaDoc[] chain;
42
43     /**
44      * Marker interface for private key request types.
45      */

46     public static interface Request { };
47
48     /**
49      * Request type for private keys that are identified via an alias.
50      */

51     public static class AliasRequest implements Request {
52     private String JavaDoc alias;
53
54     /**
55      * Construct an AliasRequest with an alias.
56      *
57      * <p> The alias is used to directly identify the private key
58      * to be returned. The corresponding certificate chain for the
59      * private key is also returned.
60      *
61      * <p> If the alias is null,
62      * the handler of the callback relies on its own default.
63      *
64      * @param alias name identifier for the private key, or null.
65      */

66     public AliasRequest(String JavaDoc alias) {
67         this.alias = alias;
68     }
69
70     /**
71      * Get the alias.
72      *
73      * @return the alias, or null.
74      */

75     public String JavaDoc getAlias() {
76         return alias;
77     }
78     }
79
80     /**
81      * Request type for private keys that are identified via a SubjectKeyID
82      */

83     public static class SubjectKeyIDRequest implements Request {
84     private byte[] id;
85
86     /**
87      * Construct a SubjectKeyIDRequest with an subjectKeyID.
88      *
89      * <p> The subjectKeyID is used to directly identify the private key
90      * to be returned. The corresponding certificate chain for the
91      * private key is also returned.
92      *
93      * <p> If the subjectKeyID is null,
94      * the handler of the callback relies on its own default.
95      *
96      * @param subjectKeyID identifier for the private key, or null.
97      */

98     public SubjectKeyIDRequest(byte[] subjectKeyID) {
99         if (subjectKeyID != null) {
100         this.id = (byte[])subjectKeyID.clone();
101         }
102     }
103
104     /**
105      * Get the subjectKeyID.
106      *
107      * @return the subjectKeyID, or null.
108      */

109     public byte[] getSubjectKeyID() {
110         return id;
111     }
112     }
113
114     /**
115      * Request type for private keys that are identified via an
116      * issuer/serial number.
117      */

118     public static class IssuerSerialNumRequest implements Request {
119     private X500Principal JavaDoc issuer;
120     private BigInteger JavaDoc serialNum;
121
122     /**
123      * Constructs a IssuerSerialNumRequest with an issuer/serial number.
124      *
125      * <p> The issuer/serial number are used to identify a
126      * public key certificate. The corresponding private key
127      * is returned in the callback. The corresponding certificate chain
128      * for the private key is also returned.
129      *
130      * If the issuer/serialNumber parameters are null,
131      * the handler of the callback relies on its own defaults.
132      *
133      * @param issuer the X500Principal name of the certificate issuer,
134      * or null.
135      *
136      * @param serialNumber the serial number of the certificate,
137      * or null.
138      */

139     public IssuerSerialNumRequest(X500Principal JavaDoc issuer,
140                     BigInteger JavaDoc serialNumber) {
141         this.issuer = issuer;
142         this.serialNum = serialNumber;
143     }
144
145     /**
146      * Get the issuer.
147      *
148      * @return the issuer, or null.
149      */

150     public X500Principal JavaDoc getIssuer() {
151         return issuer;
152     }
153
154     /**
155      * Get the serial number.
156      *
157      * @return the issuer, or null.
158      */

159     public BigInteger JavaDoc getSerialNum() {
160         return serialNum;
161     }
162     }
163
164     /**
165      * Constructs this PrivateKeyCallback with a private key Request object.
166      *
167      * <p> The <i>request</i> object identifies the private key
168      * to be returned. The corresponding certificate chain for the
169      * private key is also returned.
170      *
171      * <p> If the <i>request</i> object is null,
172      * the handler of the callback relies on its own default.
173      *
174      * @param request identifier for the private key, or null.
175      */

176     public PrivateKeyCallback(Request request) {
177     this.request = request;
178     }
179
180     /**
181      * Get the Request object which identifies the private key to be returned.
182      *
183      * @return the Request object which identifies the private key
184      * to be returned, or null. If null, the handler of the callback
185      * relies on its own default.
186      */

187     public Request getRequest() {
188     return request;
189     }
190
191     /**
192      * Set the requested private key.
193      *
194      * <p> If the requested private key or chain could not be found,
195      * then both values must be set to null.
196      *
197      * @param key the private key, or null.
198      * @param chain the corresponding certificate chain, or null.
199      */

200     public void setKey(PrivateKey JavaDoc key, Certificate JavaDoc[] chain) {
201     this.key = key;
202     this.chain = chain;
203     }
204
205     /**
206      * Get the requested private key.
207      *
208      * @return the private key, or null if the key could not be found.
209      */

210     public PrivateKey JavaDoc getKey() {
211     return key;
212     }
213
214     /**
215      * Get the requested certificate chain.
216      *
217      * @return the certificate chain, or null if the chain could not be found.
218      */

219     public Certificate JavaDoc[] getChain() {
220     return chain;
221     }
222 }
223
Popular Tags