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