Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/security/auth/x500/X500PrivateCredential.java
38918 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.security.auth.x500;2627import java.security.PrivateKey;28import java.security.cert.X509Certificate;29import javax.security.auth.Destroyable;3031/**32* <p> This class represents an {@code X500PrivateCredential}.33* It associates an X.509 certificate, corresponding private key and the34* KeyStore alias used to reference that exact key pair in the KeyStore.35* This enables looking up the private credentials for an X.500 principal36* in a subject.37*38*/39public final class X500PrivateCredential implements Destroyable {40private X509Certificate cert;41private PrivateKey key;42private String alias;4344/**45* Creates an X500PrivateCredential that associates an X.509 certificate,46* a private key and the KeyStore alias.47* <p>48* @param cert X509Certificate49* @param key PrivateKey for the certificate50* @exception IllegalArgumentException if either {@code cert} or51* {@code key} is null52*53*/5455public X500PrivateCredential(X509Certificate cert, PrivateKey key) {56if (cert == null || key == null )57throw new IllegalArgumentException();58this.cert = cert;59this.key = key;60this.alias=null;61}6263/**64* Creates an X500PrivateCredential that associates an X.509 certificate,65* a private key and the KeyStore alias.66* <p>67* @param cert X509Certificate68* @param key PrivateKey for the certificate69* @param alias KeyStore alias70* @exception IllegalArgumentException if either {@code cert},71* {@code key} or {@code alias} is null72*73*/74public X500PrivateCredential(X509Certificate cert, PrivateKey key,75String alias) {76if (cert == null || key == null|| alias == null )77throw new IllegalArgumentException();78this.cert = cert;79this.key = key;80this.alias=alias;81}8283/**84* Returns the X.509 certificate.85* <p>86* @return the X509Certificate87*/8889public X509Certificate getCertificate() {90return cert;91}9293/**94* Returns the PrivateKey.95* <p>96* @return the PrivateKey97*/98public PrivateKey getPrivateKey() {99return key;100}101102/**103* Returns the KeyStore alias.104* <p>105* @return the KeyStore alias106*/107108public String getAlias() {109return alias;110}111112/**113* Clears the references to the X.509 certificate, private key and the114* KeyStore alias in this object.115*/116117public void destroy() {118cert = null;119key = null;120alias =null;121}122123/**124* Determines if the references to the X.509 certificate and private key125* in this object have been cleared.126* <p>127* @return true if X509Certificate and the PrivateKey are null128129*/130public boolean isDestroyed() {131return cert == null && key == null && alias==null;132}133}134135136