KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > security > auth > x500 > X500PrivateCredential


1 /*
2  * @(#)X500PrivateCredential.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.security.auth.x500;
9
10 import java.security.PrivateKey JavaDoc;
11 import java.security.cert.X509Certificate JavaDoc;
12 import javax.security.auth.Destroyable JavaDoc;
13
14 /**
15  * <p> This class represents an <code>X500PrivateCredential</code>.
16  * It associates an X.509 certificate, corresponding private key and the
17  * KeyStore alias used to reference that exact key pair in the KeyStore.
18  * This enables looking up the private credentials for an X.500 principal
19  * in a subject.
20  *
21  * @version 1.8, 12/19/03
22  */

23 public final class X500PrivateCredential implements Destroyable JavaDoc {
24     private X509Certificate JavaDoc cert;
25     private PrivateKey JavaDoc key;
26     private String JavaDoc alias;
27
28     /**
29      * Creates an X500PrivateCredential that associates an X.509 certificate,
30      * a private key and the KeyStore alias.
31      * <p>
32      * @param cert X509Certificate
33      * @param key PrivateKey for the certificate
34      * @exception IllegalArgumentException if either <code>cert</code> or
35      * <code>key</code> is null
36      *
37      */

38     
39     public X500PrivateCredential(X509Certificate JavaDoc cert, PrivateKey JavaDoc key) {
40     if (cert == null || key == null )
41         throw new IllegalArgumentException JavaDoc();
42     this.cert = cert;
43     this.key = key;
44     this.alias=null;
45     }
46
47     /**
48      * Creates an X500PrivateCredential that associates an X.509 certificate,
49      * a private key and the KeyStore alias.
50      * <p>
51      * @param cert X509Certificate
52      * @param key PrivateKey for the certificate
53      * @param alias KeyStore alias
54      * @exception IllegalArgumentException if either <code>cert</code>,
55      * <code>key</code> or <code>alias</code> is null
56      *
57      */

58     public X500PrivateCredential(X509Certificate JavaDoc cert, PrivateKey JavaDoc key,
59                  String JavaDoc alias) {
60     if (cert == null || key == null|| alias == null )
61         throw new IllegalArgumentException JavaDoc();
62     this.cert = cert;
63     this.key = key;
64     this.alias=alias;
65     }
66
67     /**
68      * Returns the X.509 certificate.
69      * <p>
70      * @return the X509Certificate
71      */

72
73     public X509Certificate JavaDoc getCertificate() {
74     return cert;
75     }
76
77     /**
78      * Returns the PrivateKey.
79      * <p>
80      * @return the PrivateKey
81      */

82     public PrivateKey JavaDoc getPrivateKey() {
83     return key;
84     }
85
86     /**
87      * Returns the KeyStore alias.
88      * <p>
89      * @return the KeyStore alias
90      */

91
92     public String JavaDoc getAlias() {
93     return alias;
94     }
95
96     /**
97      * Clears the references to the X.509 certificate, private key and the
98      * KeyStore alias in this object.
99      */

100
101     public void destroy() {
102     cert = null;
103     key = null;
104     alias =null;
105     }
106
107     /**
108      * Determines if the references to the X.509 certificate and private key
109      * in this object have been cleared.
110      * <p>
111      * @return true if X509Certificate and the PrivateKey are null
112
113      */

114     public boolean isDestroyed() {
115     return cert == null && key == null && alias==null;
116     }
117 }
118
Popular Tags