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.List;
20 import java.util.Map.Entry;
21
22 import javax.xml.namespace.QName;
23
24 import org.opensaml.Configuration;
25 import org.opensaml.common.impl.AbstractSAMLObjectMarshaller;
26 import org.opensaml.saml2.common.CacheableSAMLObject;
27 import org.opensaml.saml2.common.TimeBoundSAMLObject;
28 import org.opensaml.saml2.metadata.RoleDescriptor;
29 import org.opensaml.xml.XMLObject;
30 import org.opensaml.xml.io.MarshallingException;
31 import org.opensaml.xml.util.XMLHelper;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.w3c.dom.Attr;
35 import org.w3c.dom.Element;
36
37
38
39
40 public abstract class RoleDescriptorMarshaller extends AbstractSAMLObjectMarshaller {
41
42
43 private final Logger log = LoggerFactory.getLogger(RoleDescriptorMarshaller.class);
44
45
46 protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException {
47 RoleDescriptor roleDescriptor = (RoleDescriptor) samlElement;
48
49
50 if (roleDescriptor.getID() != null) {
51 log.trace("Writing ID attribute to RoleDescriptor DOM element");
52 domElement.setAttributeNS(null, RoleDescriptor.ID_ATTRIB_NAME, roleDescriptor.getID());
53 domElement.setIdAttributeNS(null, RoleDescriptor.ID_ATTRIB_NAME, true);
54 }
55
56
57 if (roleDescriptor.getValidUntil() != null) {
58 log.trace("Writting validUntil attribute to RoleDescriptor DOM element");
59 String validUntilStr = Configuration.getSAMLDateFormatter().print(roleDescriptor.getValidUntil());
60 domElement.setAttributeNS(null, TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME, validUntilStr);
61 }
62
63
64 if (roleDescriptor.getCacheDuration() != null) {
65 log.trace("Writting cacheDuration attribute to EntitiesDescriptor DOM element");
66 String cacheDuration = XMLHelper.longToDuration(roleDescriptor.getCacheDuration());
67 domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
68 }
69
70
71 List<String> supportedProtocols = roleDescriptor.getSupportedProtocols();
72 if (supportedProtocols != null && supportedProtocols.size() > 0) {
73 log.trace("Writting protocolSupportEnumberation attribute to RoleDescriptor DOM element");
74
75 StringBuilder builder = new StringBuilder();
76 for (String protocol : supportedProtocols) {
77 builder.append(protocol);
78 builder.append(" ");
79 }
80
81 domElement.setAttributeNS(null, RoleDescriptor.PROTOCOL_ENUMERATION_ATTRIB_NAME, builder.toString().trim());
82 }
83
84
85 if (roleDescriptor.getErrorURL() != null) {
86 log.trace("Writting errorURL attribute to RoleDescriptor DOM element");
87 domElement.setAttributeNS(null, RoleDescriptor.ERROR_URL_ATTRIB_NAME, roleDescriptor.getErrorURL());
88 }
89
90 Attr attribute;
91 for (Entry<QName, String> entry : roleDescriptor.getUnknownAttributes().entrySet()) {
92 attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
93 attribute.setValue(entry.getValue());
94 domElement.setAttributeNodeNS(attribute);
95 if (Configuration.isIDAttribute(entry.getKey())
96 || roleDescriptor.getUnknownAttributes().isIDAttribute(entry.getKey())) {
97 attribute.getOwnerElement().setIdAttributeNode(attribute, true);
98 }
99 }
100 }
101 }