Path: blob/master/src/java.base/share/classes/javax/security/auth/x500/X500PrivateCredential.java
41161 views
/*1* Copyright (c) 2000, 2020, 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* @since 1.439*/40public final class X500PrivateCredential implements Destroyable {41private X509Certificate cert;42private PrivateKey key;43private String alias;4445/**46* Creates an X500PrivateCredential that associates an X.509 certificate,47* a private key and the KeyStore alias.48*49* @param cert X509Certificate50* @param key PrivateKey for the certificate51* @exception IllegalArgumentException if either {@code cert} or52* {@code key} is null53*54*/5556public X500PrivateCredential(X509Certificate cert, PrivateKey key) {57if (cert == null || key == null )58throw new IllegalArgumentException();59this.cert = cert;60this.key = key;61this.alias=null;62}6364/**65* Creates an X500PrivateCredential that associates an X.509 certificate,66* a private key and the KeyStore alias.67*68* @param cert X509Certificate69* @param key PrivateKey for the certificate70* @param alias KeyStore alias71* @exception IllegalArgumentException if either {@code cert},72* {@code key} or {@code alias} is null73*74*/75public X500PrivateCredential(X509Certificate cert, PrivateKey key,76String alias) {77if (cert == null || key == null|| alias == null )78throw new IllegalArgumentException();79this.cert = cert;80this.key = key;81this.alias=alias;82}8384/**85* Returns the X.509 certificate.86*87* @return the X509Certificate88*/8990public X509Certificate getCertificate() {91return cert;92}9394/**95* Returns the PrivateKey.96*97* @return the PrivateKey98*/99public PrivateKey getPrivateKey() {100return key;101}102103/**104* Returns the KeyStore alias.105*106* @return the KeyStore alias107*/108109public String getAlias() {110return alias;111}112113/**114* Clears the references to the X.509 certificate, private key and the115* KeyStore alias in this object.116*/117118public void destroy() {119cert = null;120key = null;121alias =null;122}123124/**125* Determines if the references to the X.509 certificate and private key126* in this object have been cleared.127*128* @return true if X509Certificate and the PrivateKey are null129*/130public boolean isDestroyed() {131return cert == null && key == null && alias==null;132}133}134135136