X500PrivateCredential.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package javax.security.auth.x500;
  18. import java.security.cert.X509Certificate;
  19. import java.security.PrivateKey;
  20. import javax.security.auth.Destroyable;
  21. import org.apache.harmony.auth.internal.nls.Messages;
  22. public final class X500PrivateCredential implements Destroyable {
  23. //X509 certificate
  24. private X509Certificate cert;
  25. //Private key
  26. private PrivateKey key;
  27. //Alias
  28. private String alias;
  29. public X500PrivateCredential(X509Certificate cert, PrivateKey key) {
  30. super();
  31. if (cert == null) {
  32. throw new IllegalArgumentException(Messages.getString("auth.28")); //$NON-NLS-1$
  33. }
  34. if (key == null) {
  35. throw new IllegalArgumentException(Messages.getString("auth.29")); //$NON-NLS-1$
  36. }
  37. this.cert = cert;
  38. this.key = key;
  39. }
  40. public X500PrivateCredential(X509Certificate cert, PrivateKey key, String alias) {
  41. this(cert, key);
  42. if (alias == null) {
  43. throw new IllegalArgumentException(Messages.getString("auth.2A")); //$NON-NLS-1$
  44. }
  45. this.alias = alias;
  46. }
  47. public X509Certificate getCertificate() {
  48. return cert;
  49. }
  50. public PrivateKey getPrivateKey() {
  51. return key;
  52. }
  53. public String getAlias() {
  54. return alias;
  55. }
  56. public void destroy() {
  57. cert = null;
  58. key = null;
  59. alias = null;
  60. }
  61. public boolean isDestroyed() {
  62. return (cert == null && key == null && alias == null);
  63. }
  64. }