View Javadoc

1   /*
2    * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /**
18   * 
19   */
20  
21  package org.opensaml.saml2.core.impl;
22  
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import javax.xml.namespace.QName;
28  
29  import org.joda.time.DateTime;
30  import org.opensaml.common.SAMLVersion;
31  import org.opensaml.common.impl.AbstractSignableSAMLObject;
32  import org.opensaml.common.xml.SAMLConstants;
33  import org.opensaml.saml2.core.Advice;
34  import org.opensaml.saml2.core.Assertion;
35  import org.opensaml.saml2.core.AttributeStatement;
36  import org.opensaml.saml2.core.AuthnStatement;
37  import org.opensaml.saml2.core.AuthzDecisionStatement;
38  import org.opensaml.saml2.core.Conditions;
39  import org.opensaml.saml2.core.Issuer;
40  import org.opensaml.saml2.core.Statement;
41  import org.opensaml.saml2.core.Subject;
42  import org.opensaml.xml.XMLObject;
43  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
44  
45  /**
46   * A concrete implementation of {@link org.opensaml.saml2.core.Assertion}.
47   */
48  public class AssertionImpl extends AbstractSignableSAMLObject implements Assertion {
49  
50      /** SAML Version of the assertion. */
51      private SAMLVersion version;
52  
53      /** Issue Instant of the assertion. */
54      private DateTime issueInstant;
55  
56      /** ID of the assertion. */
57      private String id;
58  
59      /** Issuer of the assertion. */
60      private Issuer issuer;
61  
62      /** Subject of the assertion. */
63      private Subject subject;
64  
65      /** Conditions of the assertion. */
66      private Conditions conditions;
67  
68      /** Advice of the assertion. */
69      private Advice advice;
70  
71      /** Statements of the assertion. */
72      private final IndexedXMLObjectChildrenList<Statement> statements;
73  
74      /**
75       * Constructor.
76       * 
77       * @param namespaceURI the namespace the element is in
78       * @param elementLocalName the local name of the XML element this Object represents
79       * @param namespacePrefix the prefix for the given namespace
80       */
81      protected AssertionImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
82          super(namespaceURI, elementLocalName, namespacePrefix);
83          version = SAMLVersion.VERSION_20;
84          statements = new IndexedXMLObjectChildrenList<Statement>(this);
85      }
86  
87      /** {@inheritDoc} */
88      public SAMLVersion getVersion() {
89          return version;
90      }
91  
92      /** {@inheritDoc} */
93      public void setVersion(SAMLVersion newVersion) {
94          this.version = prepareForAssignment(this.version, newVersion);
95      }
96  
97      /** {@inheritDoc} */
98      public DateTime getIssueInstant() {
99          return issueInstant;
100     }
101 
102     /** {@inheritDoc} */
103     public void setIssueInstant(DateTime newIssueInstance) {
104         this.issueInstant = prepareForAssignment(this.issueInstant, newIssueInstance);
105     }
106 
107     /** {@inheritDoc} */
108     public String getID() {
109         return id;
110     }
111 
112     /** {@inheritDoc} */
113     public void setID(String newID) {
114         String oldID = this.id;
115         this.id = prepareForAssignment(this.id, newID);
116         registerOwnID(oldID, this.id);
117     }
118 
119     /** {@inheritDoc} */
120     public Issuer getIssuer() {
121         return issuer;
122     }
123 
124     /** {@inheritDoc} */
125     public void setIssuer(Issuer newIssuer) {
126         this.issuer = prepareForAssignment(this.issuer, newIssuer);
127     }
128 
129     /** {@inheritDoc} */
130     public Subject getSubject() {
131         return subject;
132     }
133 
134     /** {@inheritDoc} */
135     public void setSubject(Subject newSubject) {
136         this.subject = prepareForAssignment(this.subject, newSubject);
137     }
138 
139     /** {@inheritDoc} */
140     public Conditions getConditions() {
141         return conditions;
142     }
143 
144     /** {@inheritDoc} */
145     public void setConditions(Conditions newConditions) {
146         this.conditions = prepareForAssignment(this.conditions, newConditions);
147     }
148 
149     /** {@inheritDoc} */
150     public Advice getAdvice() {
151         return advice;
152     }
153 
154     /** {@inheritDoc} */
155     public void setAdvice(Advice newAdvice) {
156         this.advice = prepareForAssignment(this.advice, newAdvice);
157     }
158 
159     /** {@inheritDoc} */
160     public List<Statement> getStatements() {
161         return statements;
162     }
163 
164     /** {@inheritDoc} */
165     public List<Statement> getStatements(QName typeOrName) {
166         return (List<Statement>) statements.subList(typeOrName);
167     }
168 
169     /** {@inheritDoc} */
170     public List<AuthnStatement> getAuthnStatements() {
171         QName statementQName = new QName(SAMLConstants.SAML20_NS, AuthnStatement.DEFAULT_ELEMENT_LOCAL_NAME,
172                 SAMLConstants.SAML20_PREFIX);
173         return (List<AuthnStatement>) statements.subList(statementQName);
174     }
175 
176     /** {@inheritDoc} */
177     public List<AuthzDecisionStatement> getAuthzDecisionStatements() {
178         QName statementQName = new QName(SAMLConstants.SAML20_NS, AuthzDecisionStatement.DEFAULT_ELEMENT_LOCAL_NAME,
179                 SAMLConstants.SAML20_PREFIX);
180         return (List<AuthzDecisionStatement>) statements.subList(statementQName);
181     }
182 
183     /** {@inheritDoc} */
184     public List<AttributeStatement> getAttributeStatements() {
185         QName statementQName = new QName(SAMLConstants.SAML20_NS, AttributeStatement.DEFAULT_ELEMENT_LOCAL_NAME,
186                 SAMLConstants.SAML20_PREFIX);
187         return (List<AttributeStatement>) statements.subList(statementQName);
188     }
189     
190     /** {@inheritDoc} */
191     public String getSignatureReferenceID(){
192         return id;
193     }
194 
195     /** {@inheritDoc} */
196     public List<XMLObject> getOrderedChildren() {
197         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
198 
199         children.add(issuer);
200         
201         if(getSignature() != null){
202             children.add(getSignature());
203         }
204         
205         children.add(subject);
206         children.add(conditions);
207         children.add(advice);
208         children.addAll(statements);
209 
210         return Collections.unmodifiableList(children);
211     }
212 }