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 /**
27 * Class SamlDecision represents the raw data to be used by the <code>SamlAssertionWrapper</code> when
28 * creating SAML Authorization Decision Statements.
29 */
30 public class AuthDecisionStatementBean {
31
32 /**
33 * The SAML subject
34 */
35 private SubjectBean subject;
36
37 /**
38 * enum representing the possible decision types as specified in the SAML spec
39 */
40 public enum Decision { PERMIT, INDETERMINATE, DENY }
41
42 /**
43 * The decision rendered by the SAML authority with respect to the specified resource
44 */
45 private Decision decision;
46
47 /**
48 * A URI reference identifying the resource to which access authorization is sought
49 */
50 private String resource;
51
52 /**
53 * The set of actions authorized to be performed on the specified resource (one or more)
54 */
55 private List<ActionBean> actionBeans;
56
57 /**
58 * A set of assertions that the SAML authority relied on in making the decision (optional)
59 */
60 private Object evidence;
61
62 /**
63 * Constructor SamlDecision creates a new SamlDecision instance.
64 */
65 public AuthDecisionStatementBean() {
66 actionBeans = new ArrayList<>();
67 }
68
69 /**
70 * Constructor SamlDecision creates a new SamlDecision instance.
71 *
72 * @param decision of type Decision
73 * @param resource of type String
74 * @param subject of type SubjectBean
75 * @param evidence of type Object
76 * @param actionBeans of type List<SamlAction>
77 */
78 public AuthDecisionStatementBean(
79 Decision decision,
80 String resource,
81 SubjectBean subject,
82 Object evidence,
83 List<ActionBean> actionBeans
84 ) {
85 this.decision = decision;
86 this.resource = resource;
87 this.subject = subject;
88 this.evidence = evidence;
89 this.actionBeans = actionBeans;
90 }
91
92 /**
93 * Method getResource returns the resource of this SamlDecision object.
94 *
95 * @return the resource (type String) of this SamlDecision object.
96 */
97 public String getResource() {
98 return resource;
99 }
100
101 /**
102 * Method setResource sets the resource of this SamlDecision object.
103 *
104 * @param resource the resource of this SamlDecision object.
105 */
106 public void setResource(String resource) {
107 this.resource = resource;
108 }
109
110 /**
111 * Method getActions returns the actions of this SamlDecision object.
112 *
113 * @return the actions (type List<SamlAction>) of this SamlDecision object.
114 */
115 public List<ActionBean> getActions() {
116 return actionBeans;
117 }
118
119 /**
120 * Method setActions sets the actions of this SamlDecision object.
121 *
122 * @param actionBeans the actions of this SamlDecision object.
123 */
124 public void setActions(List<ActionBean> actionBeans) {
125 this.actionBeans = actionBeans;
126 }
127
128 /**
129 * Method getDecision returns the decision of this SamlDecision object.
130 *
131 * @return the decision (type Decision) of this SamlDecision object.
132 */
133 public Decision getDecision() {
134 return decision;
135 }
136
137 /**
138 * Method setDecision sets the decision of this SamlDecision object.
139 *
140 * @param decision the decision of this SamlDecision object.
141 */
142 public void setDecision(Decision decision) {
143 this.decision = decision;
144 }
145
146 /**
147 * Method getEvidence returns the evidence of this SamlDecision object.
148 *
149 * @return the evidence (type Object) of this SamlDecision object.
150 */
151 public Object getEvidence() {
152 return evidence;
153 }
154
155 /**
156 * Method setEvidence sets the evidence of this SamlDecision object.
157 *
158 * @param evidence the evidence of this SamlDecision object.
159 */
160 public void setEvidence(Object evidence) {
161 this.evidence = evidence;
162 }
163
164 /**
165 * Get the Subject
166 * @return the Subject
167 */
168 public SubjectBean getSubject() {
169 return subject;
170 }
171
172 /**
173 * Set the Subject
174 * @param subject the SubjectBean instance to set
175 */
176 public void setSubject(SubjectBean subject) {
177 this.subject = subject;
178 }
179
180 @Override
181 public boolean equals(Object o) {
182 if (this == o) {
183 return true;
184 }
185 if (!(o instanceof AuthDecisionStatementBean)) {
186 return false;
187 }
188
189 AuthDecisionStatementBean that = (AuthDecisionStatementBean) o;
190
191 if (subject == null && that.subject != null) {
192 return false;
193 } else if (subject != null && !subject.equals(that.subject)) {
194 return false;
195 }
196
197 if (decision == null && that.decision != null) {
198 return false;
199 } else if (decision != null && !decision.equals(that.decision)) {
200 return false;
201 }
202
203 if (evidence == null && that.evidence != null) {
204 return false;
205 } else if (evidence != null && !evidence.equals(that.evidence)) {
206 return false;
207 }
208
209 if (actionBeans == null && that.actionBeans != null) {
210 return false;
211 } else if (actionBeans != null && !actionBeans.equals(that.actionBeans)) {
212 return false;
213 }
214
215 if (resource == null && that.resource != null) {
216 return false;
217 } else if (resource != null && !resource.equals(that.resource)) {
218 return false;
219 }
220
221 return true;
222 }
223
224 @Override
225 public int hashCode() {
226 int result = subject != null ? subject.hashCode() : 0;
227 result = 31 * result + (decision != null ? decision.hashCode() : 0);
228 result = 31 * result + (evidence != null ? evidence.hashCode() : 0);
229 result = 31 * result + (actionBeans != null ? actionBeans.hashCode() : 0);
230 result = 31 * result + (resource != null ? resource.hashCode() : 0);
231 return result;
232 }
233 }