use of org.opensaml.core.xml.schema.impl.XSURIBuilder in project spring-security by spring-projects.
the class TestOpenSamlObjects method attributeStatements.
static List<AttributeStatement> attributeStatements() {
List<AttributeStatement> attributeStatements = new ArrayList<>();
AttributeStatementBuilder attributeStatementBuilder = new AttributeStatementBuilder();
AttributeBuilder attributeBuilder = new AttributeBuilder();
AttributeStatement attrStmt1 = attributeStatementBuilder.buildObject();
Attribute emailAttr = attributeBuilder.buildObject();
emailAttr.setName("email");
// gh-8864
XSAny email1 = new XSAnyBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSAny.TYPE_NAME);
email1.setTextContent("john.doe@example.com");
emailAttr.getAttributeValues().add(email1);
XSAny email2 = new XSAnyBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
email2.setTextContent("doe.john@example.com");
emailAttr.getAttributeValues().add(email2);
attrStmt1.getAttributes().add(emailAttr);
Attribute nameAttr = attributeBuilder.buildObject();
nameAttr.setName("name");
XSString name = new XSStringBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
name.setValue("John Doe");
nameAttr.getAttributeValues().add(name);
attrStmt1.getAttributes().add(nameAttr);
Attribute ageAttr = attributeBuilder.buildObject();
ageAttr.setName("age");
XSInteger age = new XSIntegerBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSInteger.TYPE_NAME);
age.setValue(21);
ageAttr.getAttributeValues().add(age);
attrStmt1.getAttributes().add(ageAttr);
attributeStatements.add(attrStmt1);
AttributeStatement attrStmt2 = attributeStatementBuilder.buildObject();
Attribute websiteAttr = attributeBuilder.buildObject();
websiteAttr.setName("website");
XSURI uri = new XSURIBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSURI.TYPE_NAME);
uri.setValue("https://johndoe.com/");
websiteAttr.getAttributeValues().add(uri);
attrStmt2.getAttributes().add(websiteAttr);
Attribute registeredAttr = attributeBuilder.buildObject();
registeredAttr.setName("registered");
XSBoolean registered = new XSBooleanBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSBoolean.TYPE_NAME);
registered.setValue(new XSBooleanValue(true, false));
registeredAttr.getAttributeValues().add(registered);
attrStmt2.getAttributes().add(registeredAttr);
attributeStatements.add(attrStmt2);
return attributeStatements;
}
use of org.opensaml.core.xml.schema.impl.XSURIBuilder in project cas by apereo.
the class AbstractSamlObjectBuilder method newAttributeValue.
/**
* New attribute value.
*
* @param value the value
* @param valueType the value type
* @param elementName the element name
* @return the xS string
*/
protected XMLObject newAttributeValue(final Object value, final String valueType, final QName elementName) {
LOGGER.trace("Creating new attribute value XMLObject for value: [{}], value type: [{}], QName: [{}]", value, valueType, elementName);
if (value instanceof NameIDType) {
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, value);
((NameIDType) value).detach();
return (NameIDType) value;
}
if (XSString.class.getSimpleName().equalsIgnoreCase(valueType)) {
val builder = new XSStringBuilder();
val attrValueObj = builder.buildObject(elementName, XSString.TYPE_NAME);
attrValueObj.setValue(value.toString());
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, attrValueObj);
return attrValueObj;
}
if (XSURI.class.getSimpleName().equalsIgnoreCase(valueType)) {
val builder = new XSURIBuilder();
val attrValueObj = builder.buildObject(elementName, XSURI.TYPE_NAME);
attrValueObj.setURI(value.toString());
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, attrValueObj);
return attrValueObj;
}
if (XSBoolean.class.getSimpleName().equalsIgnoreCase(valueType)) {
val builder = new XSBooleanBuilder();
val attrValueObj = builder.buildObject(elementName, XSBoolean.TYPE_NAME);
attrValueObj.setValue(XSBooleanValue.valueOf(value.toString().toLowerCase()));
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, attrValueObj);
return attrValueObj;
}
if (XSInteger.class.getSimpleName().equalsIgnoreCase(valueType)) {
val builder = new XSIntegerBuilder();
val attrValueObj = builder.buildObject(elementName, XSInteger.TYPE_NAME);
attrValueObj.setValue(Integer.valueOf(value.toString()));
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, attrValueObj);
return attrValueObj;
}
if (XSDateTime.class.getSimpleName().equalsIgnoreCase(valueType)) {
val builder = new XSDateTimeBuilder();
val attrValueObj = builder.buildObject(elementName, XSDateTime.TYPE_NAME);
attrValueObj.setValue(ZonedDateTime.parse(value.toString()).toInstant());
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, attrValueObj);
return attrValueObj;
}
if (XSBase64Binary.class.getSimpleName().equalsIgnoreCase(valueType)) {
val builder = new XSBase64BinaryBuilder();
val attrValueObj = builder.buildObject(elementName, XSBase64Binary.TYPE_NAME);
attrValueObj.setValue(value.toString());
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, attrValueObj);
return attrValueObj;
}
if (XSObject.class.getSimpleName().equalsIgnoreCase(valueType)) {
val mapper = new JacksonXmlSerializer();
val builder = new XSAnyBuilder();
val attrValueObj = builder.buildObject(elementName);
attrValueObj.setTextContent(mapper.writeValueAsString(value));
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, attrValueObj);
return attrValueObj;
}
val builder = new XSAnyBuilder();
val attrValueObj = builder.buildObject(elementName);
attrValueObj.setTextContent(value.toString());
LOGGER.trace(LOG_MESSAGE_ATTR_CREATED, attrValueObj);
return attrValueObj;
}
Aggregations