1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.internet2.middleware.shibboleth.common.attribute.encoding.provider;
18
19 import java.util.List;
20
21 import org.opensaml.saml1.core.Attribute;
22 import org.opensaml.saml1.core.AttributeValue;
23 import org.opensaml.xml.XMLObject;
24 import org.opensaml.xml.XMLObjectBuilder;
25 import org.opensaml.xml.schema.XSString;
26 import org.opensaml.xml.schema.impl.XSStringBuilder;
27 import org.opensaml.xml.util.DatatypeHelper;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
32
33
34
35
36 public class SAML1StringAttributeEncoder extends AbstractSAML1AttributeEncoder {
37
38
39 private final Logger log = LoggerFactory.getLogger(SAML1StringAttributeEncoder.class);
40
41
42 private final XMLObjectBuilder<XSString> stringBuilder;
43
44
45 public SAML1StringAttributeEncoder() {
46 super();
47 stringBuilder = new XSStringBuilder();
48 }
49
50
51 public Attribute encode(BaseAttribute attribute) {
52 Attribute samlAttribute = attributeBuilder.buildObject();
53 populateAttribute(samlAttribute);
54
55 String attributeValue;
56 XSString samlAttributeValue;
57 for (Object o : attribute.getValues()) {
58 if (o == null) {
59 continue;
60 }
61
62 attributeValue = o.toString();
63 if (!DatatypeHelper.isEmpty(attributeValue)) {
64 samlAttributeValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
65 samlAttributeValue.setValue(attributeValue);
66 samlAttribute.getAttributeValues().add(samlAttributeValue);
67 }
68 }
69
70 List<XMLObject> attributeValues = samlAttribute.getAttributeValues();
71 if (attributeValues == null || attributeValues.isEmpty()) {
72 log.debug("Unable to encode {} attribute. It does not contain any values", attribute.getId());
73 return null;
74 }
75
76 return samlAttribute;
77 }
78
79 }