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  import java.util.List;
23  import java.util.ArrayList;
24  
25  /**
26   * Class SamlAttribute represents an instance of a SAML attribute.
27   */
28  public class AttributeBean {
29      private String simpleName;
30      private String qualifiedName;
31      private String nameFormat;
32      private List<Object> attributeValues;
33  
34      /**
35       * Constructor SamlAttribute creates a new SamlAttribute instance.
36       */
37      public AttributeBean() {
38          attributeValues = new ArrayList<>();
39      }
40  
41      /**
42       * Constructor SamlAttribute creates a new SamlAttribute instance.
43       *
44       * @param simpleName of type String
45       * @param qualifiedName of type String
46       * @param attributeValues of type List<Object>
47       */
48      public AttributeBean(String simpleName, String qualifiedName, List<Object> attributeValues) {
49          this.simpleName = simpleName;
50          this.qualifiedName = qualifiedName;
51          this.attributeValues = attributeValues;
52      }
53  
54      /**
55       * Method getSimpleName returns the simpleName of this SamlAttribute object.
56       *
57       * @return the simpleName (type String) of this SamlAttribute object.
58       */
59      public String getSimpleName() {
60          return simpleName;
61      }
62  
63      /**
64       * Method setSimpleName sets the simpleName of this SamlAttribute object.
65       *
66       * @param simpleName the simpleName of this SamlAttribute object.
67       */
68      public void setSimpleName(String simpleName) {
69          this.simpleName = simpleName;
70      }
71  
72      /**
73       * Method getNameFormat returns the nameFormat of this SamlAttribute object
74       *
75       * @return the nameFormat of this SamlAttribute object
76       */
77      public String getNameFormat() {
78          return nameFormat;
79      }
80  
81      /**
82       * Method setNameFormat sets the nameFormat of this SamlAttribute object.
83       *
84       * @param nameFormat the nameFormat of this SamlAttribute object.
85       */
86      public void setNameFormat(String nameFormat) {
87          this.nameFormat = nameFormat;
88      }
89  
90      /**
91       * Method getQualifiedName returns the qualifiedName of this SamlAttribute object.
92       *
93       * @return the qualifiedName (type String) of this SamlAttribute object.
94       */
95      public String getQualifiedName() {
96          return qualifiedName;
97      }
98  
99      /**
100      * Method setQualifiedName sets the qualifiedName of this SamlAttribute object.
101      *
102      * @param qualifiedName the qualifiedName of this SamlAttribute object.
103      */
104     public void setQualifiedName(String qualifiedName) {
105         this.qualifiedName = qualifiedName;
106     }
107 
108     /**
109      * Method getAttributeValues returns the attributeValues of this SamlAttribute object.
110      *
111      * @return the attributeValues (type List) of this SamlAttribute object.
112      */
113     public List<Object> getAttributeValues() {
114         return attributeValues;
115     }
116 
117     /**
118      * Method setAttributeValues sets the attributeValues of this SamlAttribute object.
119      *
120      * @param attributeValues the attributeValues of this SamlAttribute object.
121      */
122     public void setAttributeValues(List<Object> attributeValues) {
123         this.attributeValues = attributeValues;
124     }
125 
126     public void addAttributeValue(Object attributeValue) {
127         if (attributeValues == null) {
128             attributeValues = new ArrayList<>();
129         }
130         attributeValues.add(attributeValue);
131     }
132 
133     @Override
134     public boolean equals(Object o) {
135         if (this == o) {
136             return true;
137         }
138         if (!(o instanceof AttributeBean)) {
139             return false;
140         }
141 
142         AttributeBean that = (AttributeBean) o;
143 
144         if (attributeValues == null && that.attributeValues != null) {
145             return false;
146         } else if (attributeValues != null && !attributeValues.equals(that.attributeValues)) {
147             return false;
148         }
149 
150         if (qualifiedName == null && that.qualifiedName != null) {
151             return false;
152         } else if (qualifiedName != null && !qualifiedName.equals(that.qualifiedName)) {
153             return false;
154         }
155 
156         if (nameFormat == null && that.nameFormat != null) {
157             return false;
158         } else if (nameFormat != null && !nameFormat.equals(that.nameFormat)) {
159             return false;
160         }
161 
162         if (simpleName == null && that.simpleName != null) {
163             return false;
164         } else if (simpleName != null && !simpleName.equals(that.simpleName)) {
165             return false;
166         }
167 
168         return true;
169     }
170 
171     @Override
172     public int hashCode() {
173         int result = 0;
174         if (simpleName != null) {
175             result = 31 * result + simpleName.hashCode();
176         }
177         if (qualifiedName != null) {
178             result = 31 * result + qualifiedName.hashCode();
179         }
180         if (nameFormat != null) {
181             result = 31 * result + nameFormat.hashCode();
182         }
183         if (attributeValues != null) {
184             result = 31 * result + attributeValues.hashCode();
185         }
186         return result;
187     }
188 }