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. package javax.security.auth.x500;
  8. import java.security.PrivateKey;
  9. import java.security.cert.X509Certificate;
  10. import javax.security.auth.Destroyable;
  11. /**
  12. * <p> This class represents an <code>X500PrivateCredential</code>.
  13. * It associates an X.509 certificate, corresponding private key and the
  14. * KeyStore alias used to reference that exact key pair in the KeyStore.
  15. * This enables looking up the private credentials for an X.500 principal
  16. * in a subject.
  17. *
  18. * @version 1.8, 12/19/03
  19. */
  20. public final class X500PrivateCredential implements Destroyable {
  21. private X509Certificate cert;
  22. private PrivateKey key;
  23. private String alias;
  24. /**
  25. * Creates an X500PrivateCredential that associates an X.509 certificate,
  26. * a private key and the KeyStore alias.
  27. * <p>
  28. * @param cert X509Certificate
  29. * @param key PrivateKey for the certificate
  30. * @exception IllegalArgumentException if either <code>cert</code> or
  31. * <code>key</code> is null
  32. *
  33. */
  34. public X500PrivateCredential(X509Certificate cert, PrivateKey key) {
  35. if (cert == null || key == null )
  36. throw new IllegalArgumentException();
  37. this.cert = cert;
  38. this.key = key;
  39. this.alias=null;
  40. }
  41. /**
  42. * Creates an X500PrivateCredential that associates an X.509 certificate,
  43. * a private key and the KeyStore alias.
  44. * <p>
  45. * @param cert X509Certificate
  46. * @param key PrivateKey for the certificate
  47. * @param alias KeyStore alias
  48. * @exception IllegalArgumentException if either <code>cert</code>,
  49. * <code>key</code> or <code>alias</code> is null
  50. *
  51. */
  52. public X500PrivateCredential(X509Certificate cert, PrivateKey key,
  53. String alias) {
  54. if (cert == null || key == null|| alias == null )
  55. throw new IllegalArgumentException();
  56. this.cert = cert;
  57. this.key = key;
  58. this.alias=alias;
  59. }
  60. /**
  61. * Returns the X.509 certificate.
  62. * <p>
  63. * @return the X509Certificate
  64. */
  65. public X509Certificate getCertificate() {
  66. return cert;
  67. }
  68. /**
  69. * Returns the PrivateKey.
  70. * <p>
  71. * @return the PrivateKey
  72. */
  73. public PrivateKey getPrivateKey() {
  74. return key;
  75. }
  76. /**
  77. * Returns the KeyStore alias.
  78. * <p>
  79. * @return the KeyStore alias
  80. */
  81. public String getAlias() {
  82. return alias;
  83. }
  84. /**
  85. * Clears the references to the X.509 certificate, private key and the
  86. * KeyStore alias in this object.
  87. */
  88. public void destroy() {
  89. cert = null;
  90. key = null;
  91. alias =null;
  92. }
  93. /**
  94. * Determines if the references to the X.509 certificate and private key
  95. * in this object have been cleared.
  96. * <p>
  97. * @return true if X509Certificate and the PrivateKey are null
  98. */
  99. public boolean isDestroyed() {
  100. return cert == null && key == null && alias==null;
  101. }
  102. }