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  package org.opensaml.saml1.core.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import javax.xml.namespace.QName;
24  
25  import org.joda.time.DateTime;
26  import org.opensaml.common.SAMLVersion;
27  import org.opensaml.common.impl.AbstractSignableSAMLObject;
28  import org.opensaml.common.xml.SAMLConstants;
29  import org.opensaml.saml1.core.Advice;
30  import org.opensaml.saml1.core.Assertion;
31  import org.opensaml.saml1.core.AttributeStatement;
32  import org.opensaml.saml1.core.AuthenticationStatement;
33  import org.opensaml.saml1.core.AuthorizationDecisionStatement;
34  import org.opensaml.saml1.core.Conditions;
35  import org.opensaml.saml1.core.Statement;
36  import org.opensaml.saml1.core.SubjectStatement;
37  import org.opensaml.xml.XMLObject;
38  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
39  
40  /**
41   * This class implements the SAML 1 <code> Assertion </code> statement.
42   */
43  public class AssertionImpl extends AbstractSignableSAMLObject implements Assertion {
44  
45      /** The <code> AssertionID </code> attrribute */
46      private String id;
47      
48      /** SAML version of this assertion */
49      private SAMLVersion version;
50      
51      /** Object version of the <code> Issuer </code> attribute. */
52      private String issuer;
53  
54      /** Object version of the <code> IssueInstant </code> attribute. */
55      private DateTime issueInstant;
56  
57      /** (Possibly null) Singleton object version of the <code> Conditions </code> element. */
58      private Conditions conditions;
59  
60      /** (Possibly null) Singleton object version of the <code> Advice </code> element. */
61      private Advice advice;
62  
63      /** Object representnation of all the <code> Statement <\code> elements. */
64      private final IndexedXMLObjectChildrenList<Statement> statements;
65      
66      /**
67       * Constructor
68       * 
69       * @param namespaceURI the namespace the element is in
70       * @param elementLocalName the local name of the XML element this Object represents
71       * @param namespacePrefix the prefix for the given namespace
72       */
73      protected AssertionImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
74          super(namespaceURI, elementLocalName, namespacePrefix);
75          statements = new IndexedXMLObjectChildrenList<Statement>(this);
76          version = SAMLVersion.VERSION_11;
77      }
78      
79      /** {@inheritDoc} */
80      public int getMajorVersion(){
81          return version.getMajorVersion();
82      }
83      
84      /** {@inheritDoc} */
85      public int getMinorVersion() {
86          return version.getMinorVersion();
87      }
88      
89      /** {@inheritDoc} */
90      public void setVersion(SAMLVersion newVersion){
91          version = prepareForAssignment(version, newVersion);
92      }
93  
94      /** {@inheritDoc} */
95      public String getID() {
96          return id;
97      }
98  
99      /** {@inheritDoc} */
100     public void setID(String id) {
101         String oldID = this.id;
102         this.id = prepareForAssignment(this.id, id);   
103         registerOwnID(oldID, this.id);
104     }
105 
106     /** {@inheritDoc} */
107     public String getIssuer() {
108         return this.issuer;
109     }
110 
111     /** {@inheritDoc} */
112     public void setIssuer(String issuer) {
113         this.issuer = prepareForAssignment(this.issuer, issuer);
114     }
115 
116     /** {@inheritDoc} */
117     public DateTime getIssueInstant() {
118         return this.issueInstant;
119     }
120 
121     /** {@inheritDoc} */
122     public void setIssueInstant(DateTime issueInstant) {
123         this.issueInstant = prepareForAssignment(this.issueInstant, issueInstant);
124     }
125 
126     /** {@inheritDoc} */
127     public Conditions getConditions() {
128         return conditions;
129     }
130 
131     /** {@inheritDoc} */
132     public void setConditions(Conditions conditions) throws IllegalArgumentException {
133         this.conditions = prepareForAssignment(this.conditions, conditions);
134     }
135 
136     /** {@inheritDoc} */
137     public Advice getAdvice() {
138         return advice;
139     }
140 
141     /** {@inheritDoc} */
142     public void setAdvice(Advice advice) throws IllegalArgumentException {
143         this.advice = prepareForAssignment(this.advice, advice);
144     }
145 
146     /** {@inheritDoc} */
147     public List<Statement> getStatements() {
148         return statements;
149     }
150 
151     /** {@inheritDoc} */
152     public List<Statement> getStatements(QName typeOrName) {
153         return (List<Statement>) statements.subList(typeOrName);
154     }
155 
156     /** {@inheritDoc} */
157     public List<SubjectStatement> getSubjectStatements() {
158         QName statementQName = new QName(SAMLConstants.SAML1_NS, SubjectStatement.DEFAULT_ELEMENT_LOCAL_NAME);
159         return (List<SubjectStatement>) statements.subList(statementQName);
160     }
161 
162     /** {@inheritDoc} */
163     public List<AuthenticationStatement> getAuthenticationStatements() {
164         QName statementQName = new QName(SAMLConstants.SAML1_NS, AuthenticationStatement.DEFAULT_ELEMENT_LOCAL_NAME);
165         return (List<AuthenticationStatement>) statements.subList(statementQName);
166     }
167 
168     /** {@inheritDoc} */
169     public List<AuthorizationDecisionStatement> getAuthorizationDecisionStatements() {
170         QName statementQName = new QName(SAMLConstants.SAML1_NS, AuthorizationDecisionStatement.DEFAULT_ELEMENT_LOCAL_NAME);
171         return (List<AuthorizationDecisionStatement>) statements.subList(statementQName);
172     }
173 
174     /** {@inheritDoc} */
175     public List<AttributeStatement> getAttributeStatements() {
176         QName statementQName = new QName(SAMLConstants.SAML1_NS, AttributeStatement.DEFAULT_ELEMENT_LOCAL_NAME);
177         return (List<AttributeStatement>) statements.subList(statementQName);
178     }
179     
180     /** {@inheritDoc} */
181     public String getSignatureReferenceID(){
182         return id;
183     }
184 
185     /** {@inheritDoc} */
186     public List<XMLObject> getOrderedChildren() {
187 
188         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
189 
190         if (conditions != null) {
191             children.add(conditions);
192         }
193 
194         if (advice != null) {
195             children.add(advice);
196         }
197 
198         children.addAll(statements);
199         
200         if(getSignature() != null){
201             children.add(getSignature());
202         }
203 
204         if (children.size() == 0) {
205             return null;
206         }
207         return Collections.unmodifiableList(children);
208     }
209 }