View Javadoc

1   /*
2    * Copyright 2009 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.samlext.saml2delrestrict.impl;
18  
19  import org.joda.time.DateTime;
20  import org.joda.time.chrono.ISOChronology;
21  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
22  import org.opensaml.saml2.core.BaseID;
23  import org.opensaml.saml2.core.EncryptedID;
24  import org.opensaml.saml2.core.NameID;
25  import org.opensaml.samlext.saml2delrestrict.Delegate;
26  import org.opensaml.xml.XMLObject;
27  import org.opensaml.xml.io.UnmarshallingException;
28  import org.w3c.dom.Attr;
29  
30  /**
31   * Unmarshaller for instances of {@link Delegate}.
32   */
33  public class DelegateUnmarshaller extends AbstractSAMLObjectUnmarshaller {
34  
35      /** {@inheritDoc} */
36      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
37          Delegate delegate = (Delegate) samlObject;
38          
39          String attrName = attribute.getLocalName();
40          if (Delegate.CONFIRMATION_METHOD_ATTRIB_NAME.equals(attrName)) {
41              delegate.setConfirmationMethod(attribute.getValue());
42          } else if (Delegate.DELEGATION_INSTANT_ATTRIB_NAME.equals(attrName)) {
43              delegate.setDelegationInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
44          } else {
45              super.processAttribute(samlObject, attribute);
46          }
47      }
48  
49      /** {@inheritDoc} */
50      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
51              throws UnmarshallingException {
52          Delegate delegate = (Delegate) parentSAMLObject;
53          
54          if (childSAMLObject instanceof BaseID) {
55              delegate.setBaseID((BaseID) childSAMLObject);
56          } else if (childSAMLObject instanceof NameID) {
57              delegate.setNameID((NameID) childSAMLObject);
58          } else if (childSAMLObject instanceof EncryptedID) {
59              delegate.setEncryptedID((EncryptedID) childSAMLObject);
60          } else {
61              super.processChildElement(parentSAMLObject, childSAMLObject);
62          }
63      }
64  
65  }