J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000-2001 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package javax.security.auth.x500; |
| 27 | |
| 28 | import java.security.PrivateKey; |
| 29 | import java.security.cert.X509Certificate; |
| 30 | import javax.security.auth.Destroyable; |
| 31 | |
| 32 | /** |
| 33 | * <p> This class represents an <code>X500PrivateCredential</code>. |
| 34 | * It associates an X.509 certificate, corresponding private key and the |
| 35 | * KeyStore alias used to reference that exact key pair in the KeyStore. |
| 36 | * This enables looking up the private credentials for an X.500 principal |
| 37 | * in a subject. |
| 38 | * |
| 39 | */ |
| 40 | public final class X500PrivateCredential implements Destroyable { |
| 41 | private X509Certificate cert; |
| 42 | private PrivateKey key; |
| 43 | private String alias; |
| 44 | |
| 45 | /** |
| 46 | * Creates an X500PrivateCredential that associates an X.509 certificate, |
| 47 | * a private key and the KeyStore alias. |
| 48 | * <p> |
| 49 | * @param cert X509Certificate |
| 50 | * @param key PrivateKey for the certificate |
| 51 | * @exception IllegalArgumentException if either <code>cert</code> or |
| 52 | * <code>key</code> is null |
| 53 | * |
| 54 | */ |
| 55 | |
| 56 | public X500PrivateCredential(X509Certificate cert, PrivateKey key) { |
| 57 | if (cert == null || key == null ) |
| 58 | throw new IllegalArgumentException(); |
| 59 | this.cert = cert; |
| 60 | this.key = key; |
| 61 | this.alias=null; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Creates an X500PrivateCredential that associates an X.509 certificate, |
| 66 | * a private key and the KeyStore alias. |
| 67 | * <p> |
| 68 | * @param cert X509Certificate |
| 69 | * @param key PrivateKey for the certificate |
| 70 | * @param alias KeyStore alias |
| 71 | * @exception IllegalArgumentException if either <code>cert</code>, |
| 72 | * <code>key</code> or <code>alias</code> is null |
| 73 | * |
| 74 | */ |
| 75 | public X500PrivateCredential(X509Certificate cert, PrivateKey key, |
| 76 | String alias) { |
| 77 | if (cert == null || key == null|| alias == null ) |
| 78 | throw new IllegalArgumentException(); |
| 79 | this.cert = cert; |
| 80 | this.key = key; |
| 81 | this.alias=alias; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Returns the X.509 certificate. |
| 86 | * <p> |
| 87 | * @return the X509Certificate |
| 88 | */ |
| 89 | |
| 90 | public X509Certificate getCertificate() { |
| 91 | return cert; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns the PrivateKey. |
| 96 | * <p> |
| 97 | * @return the PrivateKey |
| 98 | */ |
| 99 | public PrivateKey getPrivateKey() { |
| 100 | return key; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Returns the KeyStore alias. |
| 105 | * <p> |
| 106 | * @return the KeyStore alias |
| 107 | */ |
| 108 | |
| 109 | public String getAlias() { |
| 110 | return alias; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Clears the references to the X.509 certificate, private key and the |
| 115 | * KeyStore alias in this object. |
| 116 | */ |
| 117 | |
| 118 | public void destroy() { |
| 119 | cert = null; |
| 120 | key = null; |
| 121 | alias =null; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Determines if the references to the X.509 certificate and private key |
| 126 | * in this object have been cleared. |
| 127 | * <p> |
| 128 | * @return true if X509Certificate and the PrivateKey are null |
| 129 | |
| 130 | */ |
| 131 | public boolean isDestroyed() { |
| 132 | return cert == null && key == null && alias==null; |
| 133 | } |
| 134 | } |