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 java.util.Map.Entry;
20
21 import javax.xml.namespace.QName;
22
23 import org.opensaml.Configuration;
24 import org.opensaml.common.impl.AbstractSAMLObjectMarshaller;
25 import org.opensaml.saml2.common.CacheableSAMLObject;
26 import org.opensaml.saml2.common.TimeBoundSAMLObject;
27 import org.opensaml.saml2.metadata.EntityDescriptor;
28 import org.opensaml.xml.XMLObject;
29 import org.opensaml.xml.util.XMLHelper;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.w3c.dom.Attr;
33 import org.w3c.dom.Element;
34
35
36
37
38 public class EntityDescriptorMarshaller extends AbstractSAMLObjectMarshaller {
39
40
41 private final Logger log = LoggerFactory.getLogger(EntityDescriptorMarshaller.class);
42
43
44 protected void marshallAttributes(XMLObject samlElement, Element domElement) {
45 EntityDescriptor entityDescriptor = (EntityDescriptor) samlElement;
46
47
48 if (entityDescriptor.getEntityID() != null) {
49 domElement.setAttributeNS(null, EntityDescriptor.ENTITY_ID_ATTRIB_NAME, entityDescriptor.getEntityID());
50 }
51
52
53 if (entityDescriptor.getID() != null) {
54 domElement.setAttributeNS(null, EntityDescriptor.ID_ATTRIB_NAME, entityDescriptor.getID());
55 domElement.setIdAttributeNS(null, EntityDescriptor.ID_ATTRIB_NAME, true);
56 }
57
58
59 if (entityDescriptor.getValidUntil() != null) {
60 log.debug("Writting validUntil attribute to EntityDescriptor DOM element");
61 String validUntilStr = Configuration.getSAMLDateFormatter().print(entityDescriptor.getValidUntil());
62 domElement.setAttributeNS(null, TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME, validUntilStr);
63 }
64
65
66 if (entityDescriptor.getCacheDuration() != null) {
67 log.debug("Writting cacheDuration attribute to EntityDescriptor DOM element");
68 String cacheDuration = XMLHelper.longToDuration(entityDescriptor.getCacheDuration());
69 domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
70 }
71
72 Attr attribute;
73 for (Entry<QName, String> entry : entityDescriptor.getUnknownAttributes().entrySet()) {
74 attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
75 attribute.setValue(entry.getValue());
76 domElement.setAttributeNodeNS(attribute);
77 if (Configuration.isIDAttribute(entry.getKey())
78 || entityDescriptor.getUnknownAttributes().isIDAttribute(entry.getKey())) {
79 attribute.getOwnerElement().setIdAttributeNode(attribute, true);
80 }
81 }
82 }
83 }