KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > security > auth > message > callback > PrivateKeyCallback


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package javax.security.auth.message.callback;
23
24 import java.math.BigInteger JavaDoc;
25 import java.security.PrivateKey JavaDoc;
26 import java.security.cert.Certificate JavaDoc;
27
28 import javax.security.auth.callback.Callback JavaDoc;
29 import javax.security.auth.x500.X500Principal JavaDoc;
30
31 //$Id: PrivateKeyCallback.java 45179 2006-05-23 20:18:57Z asaldhana $
32

33 /**
34  * Callback for private key and corresponding certificate chain.
35  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
36  * @author Charlie Lai, Ron Monzillo (Javadoc for JSR-196)
37  * @since May 11, 2006
38  * @version $Revision: 45179 $
39  */

40 public class PrivateKeyCallback implements Callback JavaDoc
41 {
42    /**
43     * <p>Marker interface for private key request types.</p>
44     */

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

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

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

74       public String JavaDoc getAlias()
75       {
76          return alias;
77       }
78    }
79    
80    /**
81     * <p>Request type for private keys that are identified via an issuer/serial number.</p>
82     */

83    public static class IssuerSerialNumRequest
84    {
85       private X500Principal JavaDoc issuer;
86       private java.math.BigInteger JavaDoc serialNumber;
87       
88       /**
89        * <p>Constructs a IssuerSerialNumRequest with an issuer/serial number.</p>
90        *
91        * @param issuer the X500Principal name of the certificate issuer, or null.
92        * @param serialNumber the serial number of the certificate, or null.
93        */

94       public IssuerSerialNumRequest(X500Principal JavaDoc issuer, BigInteger JavaDoc serialNumber)
95       {
96          this.issuer = issuer;
97          this.serialNumber = serialNumber;
98       }
99
100       /**
101        * Get the issuer.
102        * @return the issuer, or null.
103        */

104       public X500Principal JavaDoc getIssuer()
105       {
106          return issuer;
107       }
108
109       /**
110        * Get the serial number.
111        * @return the issuer, or null.
112        */

113       public BigInteger JavaDoc getSerialNumber()
114       {
115          return serialNumber;
116       }
117    }
118    /**
119     * <p>Request type for private keys that are identified via a SubjectKeyID</p>
120     */

121    public static class SubjectKeyIDRequest
122    {
123       private byte[] subjectKeyID;
124       
125       /**
126        * <p>Construct a SubjectKeyIDRequest with an subjectKeyID.</p>
127        *
128        * <p>The subjectKeyID is used to directly identify the private key to be returned.
129        * The corresponding certificate chain for the private key is also returned.</p>
130        *
131        * <p>If the subjectKeyID is null, the handler of the callback relies on its
132        * own default.</p>
133        *
134        * @param keyID identifier for the private key, or null.
135        */

136       public SubjectKeyIDRequest(byte[] keyID)
137       {
138          subjectKeyID = keyID;
139       }
140       
141       /**
142        * Get the subjectKeyID.
143        * @return the subjectKeyID, or null.
144        */

145       public byte[] getSubjectKeyID()
146       {
147          return subjectKeyID;
148       }
149    }
150    
151    //Private Variables
152
private Request request = null;
153    private Certificate JavaDoc[] chain = null;
154    private PrivateKey JavaDoc key = null;
155    
156    /**
157     *
158     * <p>Constructs this PrivateKeyCallback with a private key Request object.</p>
159     * <p>The request object identifies the private key to be returned. The corresponding
160     * certificate chain for the private key is also returned.</p>
161     *
162     * <p>If the request object is null, the handler of the callback relies on its
163     * own default.</p>
164     *
165     * @param request identifier for the private key, or null.
166     */

167    public PrivateKeyCallback(Request request)
168    {
169       this.request = request;
170    }
171    
172    /**
173     *
174     * @return
175     */

176    public Certificate JavaDoc[] getChain()
177    {
178       return chain;
179    }
180    
181    /**
182     * Get the requested private key.
183     * @return the private key, or null if the key could not be found.
184     */

185    public PrivateKey JavaDoc getKey()
186    {
187       return key;
188    }
189
190    /**
191     * Get the Request object which identifies the private key to be returned.
192     * @return the Request object which identifies the private key to be returned,
193     * or null. If null, the handler of the callback relies on its own default.
194     */

195    public Request getRequest()
196    {
197       return request;
198    }
199
200    /**
201     * <p>Set the requested private key.</p>
202     * <p>If the requested private key or chain could not be found, then
203     * both values must be set to null.</p>
204     *
205     * @param key the private key, or null.
206     * @param chain the corresponding certificate chain, or null.
207     */

208    public void setKey(PrivateKey JavaDoc key, Certificate JavaDoc[] chain)
209    {
210       this.key = key;
211       this.chain = chain;
212    }
213 }
214
Popular Tags