View Javadoc
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  /**
23   * Class SubjectBean represents a SAML subject (can be used to create
24   * both SAML v1.1 and v2.0 statements)
25   */
26  public class SubjectBean {
27      private final NameIDBean nameID = new NameIDBean();
28      private String subjectConfirmationMethod;
29      private KeyInfoBean keyInfo;
30      private SubjectConfirmationDataBean subjectConfirmationData;
31      private NameIDBean subjectConfirmationNameID;
32  
33      /**
34       * Constructor SubjectBean creates a new SubjectBean instance.
35       */
36      public SubjectBean() {
37      }
38  
39      /**
40       * Constructor SubjectBean creates a new SubjectBean instance.
41       *
42       * @param subjectName of type String
43       * @param subjectNameQualifier of type String
44       * @param subjectConfirmationMethod of type String
45       */
46      public SubjectBean(
47          String subjectName,
48          String subjectNameQualifier,
49          String subjectConfirmationMethod
50      ) {
51          nameID.setNameValue(subjectName);
52          nameID.setNameQualifier(subjectNameQualifier);
53          this.subjectConfirmationMethod = subjectConfirmationMethod;
54      }
55  
56      /**
57       * Constructor SubjectBean creates a new SubjectBean instance.
58       *
59       * @param subjectName of type String
60       * @param subjectNameQualifier of type String
61       * @param subjectConfirmationMethod of type String
62       * @param subjectNameIDFormat of type String
63       */
64      public SubjectBean(
65          String subjectName,
66          String subjectNameQualifier,
67          String subjectConfirmationMethod,
68          String subjectNameIDFormat
69      ) {
70          this(subjectName, subjectNameQualifier, subjectConfirmationMethod);
71          nameID.setNameIDFormat(subjectNameIDFormat);
72      }
73  
74      /**
75       * Constructor SubjectBean creates a new SubjectBean instance.
76       *
77       * @param subjectName of type String
78       * @param subjectNameQualifier of type String
79       * @param subjectConfirmationMethod of type String
80       * @param subjectNameIDFormat of type String
81       * @param subjectNameSPProvidedID of type String
82       */
83      public SubjectBean(
84              String subjectName,
85              String subjectNameQualifier,
86              String subjectConfirmationMethod,
87              String subjectNameIDFormat,
88              String subjectNameSPProvidedID
89      ) {
90          this(subjectName, subjectNameQualifier, subjectConfirmationMethod, subjectNameIDFormat);
91          nameID.setSPProvidedID(subjectNameSPProvidedID);
92      }
93  
94      /**
95       * Method getSubjectName returns the subjectName of this SubjectBean object.
96       *
97       * @return the subjectName (type String) of this SubjectBean object.
98       */
99      public String getSubjectName() {
100         return nameID.getNameValue();
101     }
102 
103     /**
104      * Method setSubjectName sets the subjectName of this SubjectBean object.
105      *
106      * @param subjectName the subjectName of this SubjectBean object.
107      */
108     public void setSubjectName(String subjectName) {
109         nameID.setNameValue(subjectName);
110     }
111 
112     /**
113      * Method getSubjectNameQualifier returns the subjectNameQualifier of this SubjectBean object.
114      *
115      * @return the subjectNameQualifier (type String) of this SubjectBean object.
116      */
117     public String getSubjectNameQualifier() {
118         return nameID.getNameQualifier();
119     }
120 
121     /**
122      * Method setSubjectNameQualifier sets the subjectNameQualifier of this SubjectBean object.
123      *
124      * @param subjectNameQualifier the subjectNameQualifier of this SubjectBean object.
125      */
126     public void setSubjectNameQualifier(String subjectNameQualifier) {
127         nameID.setNameQualifier(subjectNameQualifier);
128     }
129 
130     /**
131      * Method getSubjectConfirmationMethod returns the subjectConfirmationMethod of
132      * this SubjectBean object.
133      *
134      * @return the subjectConfirmationMethod (type String) of this SubjectBean object.
135      */
136     public String getSubjectConfirmationMethod() {
137         return subjectConfirmationMethod;
138     }
139 
140     /**
141      * Method setSubjectConfirmationMethod sets the subjectConfirmationMethod of
142      * this SubjectBean object.
143      *
144      * @param subjectConfirmationMethod the subjectConfirmationMethod of this
145      *        SubjectBean object.
146      */
147     public void setSubjectConfirmationMethod(String subjectConfirmationMethod) {
148         this.subjectConfirmationMethod = subjectConfirmationMethod;
149     }
150 
151     /**
152      * Method getSubjectNameIDFormat returns the subjectNameIDFormat of this SubjectBean
153      * object.
154      *
155      * @return the subjectNameIDFormat (type String) of this SubjectBean object.
156      */
157     public String getSubjectNameIDFormat() {
158         return nameID.getNameIDFormat();
159     }
160 
161     /**
162      * Method setSubjectNameIDFormat sets the subjectNameIDFormat of this SubjectBean
163      * object.
164      *
165      * @param subjectNameIDFormat the subjectNameIDFormat of this SubjectBean object.
166      */
167     public void setSubjectNameIDFormat(String subjectNameIDFormat) {
168         nameID.setNameIDFormat(subjectNameIDFormat);
169     }
170 
171     public String getSubjectNameSPNameQualifier() {
172         return nameID.getSPNameQualifier();
173     }
174 
175     public void setSubjectNameSPNameQualifier(String subjectNameSPNameQualifier) {
176         nameID.setSPNameQualifier(subjectNameSPNameQualifier);
177     }
178 
179     public String getSubjectNameSPProvidedID() {
180         return nameID.getSPProvidedID();
181     }
182 
183     public void setSubjectNameSPProvidedID(String subjectNameSPProvidedID) {
184         nameID.setSPProvidedID(subjectNameSPProvidedID);
185     }
186 
187     /**
188      * Method getKeyInfo returns the keyInfo of this SubjectBean object.
189      *
190      * @return the keyInfo (type KeyInfoBean) of this SubjectBean object.
191      */
192     public KeyInfoBean getKeyInfo() {
193         return keyInfo;
194     }
195 
196     /**
197      * Method setKeyInfo sets the keyInfo of this SubjectBean object.
198      *
199      * @param keyInfo the keyInfo of this SubjectBean object.
200      */
201     public void setKeyInfo(KeyInfoBean keyInfo) {
202         this.keyInfo = keyInfo;
203     }
204 
205     /**
206      * Set the SubjectConfirmationData of this SubjectBean object
207      * @return the SubjectConfirmationData of this SubjectBean object
208      */
209     public SubjectConfirmationDataBean getSubjectConfirmationData() {
210         return subjectConfirmationData;
211     }
212 
213     /**
214      * Get the SubjectConfirmationData of this SubjectBean object
215      * @param subjectConfirmationData the SubjectConfirmationData of this SubjectBean object
216      */
217     public void setSubjectConfirmationData(
218         SubjectConfirmationDataBean subjectConfirmationData
219     ) {
220         this.subjectConfirmationData = subjectConfirmationData;
221     }
222 
223     /**
224      * Get the NameId of the SubjectConfirmation object
225      * @return the NameId of the SubjectConfirmation object
226      */
227     public NameIDBean getSubjectConfirmationNameID() {
228         return subjectConfirmationNameID;
229     }
230 
231     /**
232      * Set the NameID of the SubjectConfirmation object
233      * @param subjectConfirmationNameID the NameID of the SubjectConfirmation object
234      */
235     public void setSubjectConfirmationNameID(NameIDBean subjectConfirmationNameID) {
236         this.subjectConfirmationNameID = subjectConfirmationNameID;
237     }
238 
239     /**
240      * Method equals ...
241      *
242      * @param o of type Object
243      * @return boolean
244      */
245     @Override
246     public boolean equals(Object o) {
247         if (this == o) {
248             return true;
249         }
250         if (!(o instanceof SubjectBean)) {
251             return false;
252         }
253 
254         SubjectBean that = (SubjectBean) o;
255 
256         if (!nameID.equals(that.nameID)) {
257             return false;
258         }
259 
260         if (subjectConfirmationMethod == null && that.subjectConfirmationMethod != null) {
261             return false;
262         } else if (subjectConfirmationMethod != null
263             && !subjectConfirmationMethod.equals(that.subjectConfirmationMethod)) {
264             return false;
265         }
266 
267         if (keyInfo == null && that.keyInfo != null) {
268             return false;
269         } else if (keyInfo != null && !keyInfo.equals(that.keyInfo)) {
270             return false;
271         }
272 
273         if (subjectConfirmationData == null && that.subjectConfirmationData != null) {
274             return false;
275         } else if (subjectConfirmationData != null
276             && !subjectConfirmationData.equals(that.subjectConfirmationData)) {
277             return false;
278         }
279 
280         if (subjectConfirmationNameID == null && that.subjectConfirmationNameID != null) {
281             return false;
282         } else if (subjectConfirmationNameID != null
283             && !subjectConfirmationNameID.equals(that.subjectConfirmationNameID)) {
284             return false;
285         }
286 
287         return true;
288     }
289 
290     /**
291      * @return the hashcode of this object
292      */
293     @Override
294     public int hashCode() {
295         int result = nameID.hashCode();
296         if (subjectConfirmationMethod != null) {
297             result = 31 * result + subjectConfirmationMethod.hashCode();
298         }
299         if (keyInfo != null) {
300             result = 31 * result + keyInfo.hashCode();
301         }
302         if (subjectConfirmationData != null) {
303             result = 31 * result + subjectConfirmationData.hashCode();
304         }
305         if (subjectConfirmationNameID != null) {
306             result = 31 * result + subjectConfirmationNameID.hashCode();
307         }
308         return result;
309     }
310 
311 }