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.wss4j.common.saml.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 byte[] ephemeralKey;
41 private Element keyInfoElement;
42
43 /**
44 * Constructor KeyInfoBean creates a new KeyInfoBean instance.
45 */
46 public KeyInfoBean() {
47 }
48
49 /**
50 * Method getCertificate returns the certificate of this KeyInfoBean object.
51 *
52 * @return the cert (type X509Certificate) of this KeyInfoBean object.
53 */
54 public X509Certificate getCertificate() {
55 return cert;
56 }
57
58 /**
59 * Method setCertificate sets the cert of this KeyInfoBean object.
60 *
61 * @param cert the cert of this KeyInfoBean object.
62 */
63 public void setCertificate(X509Certificate cert) {
64 this.cert = cert;
65 }
66
67 /**
68 * Method getPublicKey returns the public key of this KeyInfoBean object.
69 *
70 * @return the publicKey (type PublicKey) of this KeyInfoBean object.
71 */
72 public PublicKey getPublicKey() {
73 return publicKey;
74 }
75
76 /**
77 * Method setPublicKey sets the publicKey of this KeyInfoBean object.
78 *
79 * @param publicKey the publicKey of this KeyInfoBean object.
80 */
81 public void setPublicKey(PublicKey publicKey) {
82 this.publicKey = publicKey;
83 }
84
85 /**
86 * Method getCertIdentifer returns the cert identifer of this KeyInfoBean object.
87 *
88 * @return the certIdentifier (type CERT_IDENTIFIER) of this KeyInfoBean object.
89 */
90 public CERT_IDENTIFIER getCertIdentifer() {
91 return certIdentifier;
92 }
93
94 /**
95 * Method setCertIdentifer sets the cert identifier of this KeyInfoBean object.
96 *
97 * @param certIdentifier the certIdentifier of this KeyInfoBean object.
98 */
99 public void setCertIdentifer(CERT_IDENTIFIER certIdentifier) {
100 this.certIdentifier = certIdentifier;
101 }
102
103 public byte[] getEphemeralKey() {
104 return ephemeralKey;
105 }
106
107 public void setEphemeralKey(byte[] ephemeralKey) {
108 this.ephemeralKey = ephemeralKey;
109 }
110
111 /**
112 * Method getElement returns the DOM Element of this KeyInfoBean object.
113 *
114 * @return the keyInfoElement (type Element) of this KeyInfoBean object.
115 */
116 public Element getElement() {
117 return keyInfoElement;
118 }
119
120 /**
121 * Method setElement sets the DOM Element of this KeyInfoBean object.
122 *
123 * @param keyInfoElement the DOM Element of this KeyInfoBean object.
124 */
125 public void setElement(Element keyInfoElement) {
126 this.keyInfoElement = keyInfoElement;
127 }
128
129 /**
130 * Method equals ...
131 *
132 * @param o of type Object
133 * @return boolean
134 */
135 @Override
136 public boolean equals(Object o) {
137 if (this == o) {
138 return true;
139 }
140 if (!(o instanceof KeyInfoBean)) {
141 return false;
142 }
143
144 KeyInfoBean that = (KeyInfoBean) o;
145
146 if (certIdentifier != that.certIdentifier) {
147 return false;
148 }
149 if (cert == null && that.cert != null) {
150 return false;
151 } else if (cert != null && !cert.equals(that.cert)) {
152 return false;
153 }
154
155 if (publicKey == null && that.publicKey != null) {
156 return false;
157 } else if (publicKey != null && !publicKey.equals(that.publicKey)) {
158 return false;
159 }
160
161 if (keyInfoElement == null && that.keyInfoElement != null) {
162 return false;
163 } else if (keyInfoElement != null && !keyInfoElement.equals(that.keyInfoElement)) {
164 return false;
165 }
166
167 return true;
168 }
169
170 /**
171 * @return the hashCode of this object
172 */
173 @Override
174 public int hashCode() {
175 int result = certIdentifier.hashCode();
176 if (cert != null) {
177 result = 31 * result + cert.hashCode();
178 }
179 if (publicKey != null) {
180 result = 31 * result + publicKey.hashCode();
181 }
182 if (keyInfoElement != null) {
183 result = 31 * result + keyInfoElement.hashCode();
184 }
185 return result;
186 }
187 }