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 org.joda.time.DateTime;
24  import org.joda.time.chrono.ISOChronology;
25  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
26  import org.opensaml.saml2.core.AuthnContext;
27  import org.opensaml.saml2.core.AuthnStatement;
28  import org.opensaml.saml2.core.SubjectLocality;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.io.UnmarshallingException;
31  import org.opensaml.xml.util.DatatypeHelper;
32  import org.w3c.dom.Attr;
33  
34  /**
35   * A thread-safe Unmarshaller for {@link org.opensaml.saml2.core.AuthnStatement}.
36   */
37  public class AuthnStatementUnmarshaller extends AbstractSAMLObjectUnmarshaller {
38  
39      /** {@inheritDoc} */
40      protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
41          AuthnStatement authnStatement = (AuthnStatement) parentObject;
42          if (childObject instanceof SubjectLocality) {
43              authnStatement.setSubjectLocality((SubjectLocality) childObject);
44          } else if (childObject instanceof AuthnContext) {
45              authnStatement.setAuthnContext((AuthnContext) childObject);
46          } else {
47              super.processChildElement(parentObject, childObject);
48          }
49      }
50  
51      /** {@inheritDoc} */
52      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
53          AuthnStatement authnStatement = (AuthnStatement) samlObject;
54          if (attribute.getLocalName().equals(AuthnStatement.AUTHN_INSTANT_ATTRIB_NAME)
55                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
56              authnStatement.setAuthnInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
57          } else if (attribute.getLocalName().equals(AuthnStatement.SESSION_INDEX_ATTRIB_NAME)) {
58              authnStatement.setSessionIndex(attribute.getValue());
59          } else if (attribute.getLocalName().equals(AuthnStatement.SESSION_NOT_ON_OR_AFTER_ATTRIB_NAME)
60                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
61              authnStatement.setSessionNotOnOrAfter(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
62          } else {
63              super.processAttribute(samlObject, attribute);
64          }
65      }
66  }