1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.ws.security.saml.ext.bean;
21
22 import java.security.PublicKey;
23 import java.security.cert.X509Certificate;
24
25 import org.w3c.dom.Element;
26
27
28 /**
29 * Class KeyInfoBean represents a KeyInfo structure that will be embedded in a SAML Subject.
30 */
31 public class KeyInfoBean {
32
33 public enum CERT_IDENTIFIER {
34 X509_CERT, X509_ISSUER_SERIAL, KEY_VALUE
35 }
36
37 private X509Certificate cert;
38 private CERT_IDENTIFIER certIdentifier = CERT_IDENTIFIER.X509_CERT;
39 private PublicKey publicKey;
40 private Element keyInfoElement;
41
42 /**
43 * Constructor KeyInfoBean creates a new KeyInfoBean instance.
44 */
45 public KeyInfoBean() {
46 }
47
48 /**
49 * Method getCertificate returns the certificate of this KeyInfoBean object.
50 *
51 * @return the cert (type X509Certificate) of this KeyInfoBean object.
52 */
53 public X509Certificate getCertificate() {
54 return cert;
55 }
56
57 /**
58 * Method setCertificate sets the cert of this KeyInfoBean object.
59 *
60 * @param cert the cert of this KeyInfoBean object.
61 */
62 public void setCertificate(X509Certificate cert) {
63 this.cert = cert;
64 }
65
66 /**
67 * Method getPublicKey returns the public key of this KeyInfoBean object.
68 *
69 * @return the publicKey (type PublicKey) of this KeyInfoBean object.
70 */
71 public PublicKey getPublicKey() {
72 return publicKey;
73 }
74
75 /**
76 * Method setPublicKey sets the publicKey of this KeyInfoBean object.
77 *
78 * @param publicKey the publicKey of this KeyInfoBean object.
79 */
80 public void setPublicKey(PublicKey publicKey) {
81 this.publicKey = publicKey;
82 }
83
84 /**
85 * Method getCertIdentifer returns the cert identifer of this KeyInfoBean object.
86 *
87 * @return the certIdentifier (type CERT_IDENTIFIER) of this KeyInfoBean object.
88 */
89 public CERT_IDENTIFIER getCertIdentifer() {
90 return certIdentifier;
91 }
92
93 /**
94 * Method setCertIdentifer sets the cert identifier of this KeyInfoBean object.
95 *
96 * @param certIdentifier the certIdentifier of this KeyInfoBean object.
97 */
98 public void setCertIdentifer(CERT_IDENTIFIER certIdentifier) {
99 this.certIdentifier = certIdentifier;
100 }
101
102 /**
103 * Method getElement returns the DOM Element of this KeyInfoBean object.
104 *
105 * @return the keyInfoElement (type Element) of this KeyInfoBean object.
106 */
107 public Element getElement() {
108 return keyInfoElement;
109 }
110
111 /**
112 * Method setElement sets the DOM Element of this KeyInfoBean object.
113 *
114 * @param keyInfoElement the DOM Element of this KeyInfoBean object.
115 */
116 public void setElement(Element keyInfoElement) {
117 this.keyInfoElement = keyInfoElement;
118 }
119
120 /**
121 * Method equals ...
122 *
123 * @param o of type Object
124 * @return boolean
125 */
126 @Override
127 public boolean equals(Object o) {
128 if (this == o) return true;
129 if (!(o instanceof KeyInfoBean)) return false;
130
131 KeyInfoBean that = (KeyInfoBean) o;
132
133 if (certIdentifier != that.certIdentifier) return false;
134 if (cert == null && that.cert != null) {
135 return false;
136 } else if (cert != null && !cert.equals(that.cert)) {
137 return false;
138 }
139
140 if (publicKey == null && that.publicKey != null) {
141 return false;
142 } else if (publicKey != null && !publicKey.equals(that.publicKey)) {
143 return false;
144 }
145
146 if (keyInfoElement == null && that.keyInfoElement != null) {
147 return false;
148 } else if (keyInfoElement != null && !keyInfoElement.equals(that.keyInfoElement)) {
149 return false;
150 }
151
152 return true;
153 }
154
155 /**
156 * @return the hashCode of this object
157 */
158 @Override
159 public int hashCode() {
160 int result = certIdentifier.hashCode();
161 if (cert != null) {
162 result = 31 * result + cert.hashCode();
163 }
164 if (publicKey != null) {
165 result = 31 * result + publicKey.hashCode();
166 }
167 if (keyInfoElement != null) {
168 result = 31 * result + keyInfoElement.hashCode();
169 }
170 return result;
171 }
172 }