1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.saml2.metadata.impl;
18
19 import javax.xml.namespace.QName;
20
21 import org.joda.time.DateTime;
22 import org.joda.time.chrono.ISOChronology;
23 import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
24 import org.opensaml.saml2.common.CacheableSAMLObject;
25 import org.opensaml.saml2.common.Extensions;
26 import org.opensaml.saml2.common.TimeBoundSAMLObject;
27 import org.opensaml.saml2.metadata.AdditionalMetadataLocation;
28 import org.opensaml.saml2.metadata.AffiliationDescriptor;
29 import org.opensaml.saml2.metadata.ContactPerson;
30 import org.opensaml.saml2.metadata.EntityDescriptor;
31 import org.opensaml.saml2.metadata.Organization;
32 import org.opensaml.saml2.metadata.RoleDescriptor;
33 import org.opensaml.xml.XMLObject;
34 import org.opensaml.xml.io.UnmarshallingException;
35 import org.opensaml.xml.signature.Signature;
36 import org.opensaml.xml.util.DatatypeHelper;
37 import org.opensaml.xml.util.XMLHelper;
38 import org.w3c.dom.Attr;
39
40
41
42
43 public class EntityDescriptorUnmarshaller extends AbstractSAMLObjectUnmarshaller {
44
45
46 protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
47 throws UnmarshallingException {
48 EntityDescriptor entityDescriptor = (EntityDescriptor) parentSAMLObject;
49
50 if (childSAMLObject instanceof Extensions) {
51 entityDescriptor.setExtensions((Extensions) childSAMLObject);
52 } else if (childSAMLObject instanceof Signature) {
53 entityDescriptor.setSignature((Signature) childSAMLObject);
54 } else if (childSAMLObject instanceof RoleDescriptor) {
55 entityDescriptor.getRoleDescriptors().add((RoleDescriptor) childSAMLObject);
56 } else if (childSAMLObject instanceof AffiliationDescriptor) {
57 entityDescriptor.setAffiliationDescriptor((AffiliationDescriptor) childSAMLObject);
58 } else if (childSAMLObject instanceof Organization) {
59 entityDescriptor.setOrganization((Organization) childSAMLObject);
60 } else if (childSAMLObject instanceof ContactPerson) {
61 entityDescriptor.getContactPersons().add((ContactPerson) childSAMLObject);
62 } else if (childSAMLObject instanceof AdditionalMetadataLocation) {
63 entityDescriptor.getAdditionalMetadataLocations().add((AdditionalMetadataLocation) childSAMLObject);
64 } else {
65 super.processChildElement(parentSAMLObject, childSAMLObject);
66 }
67 }
68
69
70 protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
71 EntityDescriptor entityDescriptor = (EntityDescriptor) samlObject;
72
73 if (attribute.getLocalName().equals(EntityDescriptor.ENTITY_ID_ATTRIB_NAME)) {
74 entityDescriptor.setEntityID(attribute.getValue());
75 } else if (attribute.getLocalName().equals(EntityDescriptor.ID_ATTRIB_NAME)) {
76 entityDescriptor.setID(attribute.getValue());
77 attribute.getOwnerElement().setIdAttributeNode(attribute, true);
78 } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME)
79 && !DatatypeHelper.isEmpty(attribute.getValue())) {
80 entityDescriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
81 } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) {
82 entityDescriptor.setCacheDuration(XMLHelper.durationToLong(attribute.getValue()));
83 } else {
84 QName attribQName = XMLHelper.getNodeQName(attribute);
85 if (attribute.isId()) {
86 entityDescriptor.getUnknownAttributes().registerID(attribQName);
87 }
88 entityDescriptor.getUnknownAttributes().put(attribQName, attribute.getValue());
89 }
90 }
91 }