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