Search in sources :

Example 1 with XSStringBuilder

use of org.opensaml.core.xml.schema.impl.XSStringBuilder 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;
}
Also used : AttributeStatementBuilder(org.opensaml.saml.saml2.core.impl.AttributeStatementBuilder) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) XSIntegerBuilder(org.opensaml.core.xml.schema.impl.XSIntegerBuilder) XSBooleanBuilder(org.opensaml.core.xml.schema.impl.XSBooleanBuilder) XSAnyBuilder(org.opensaml.core.xml.schema.impl.XSAnyBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) EncryptedAttribute(org.opensaml.saml.saml2.core.EncryptedAttribute) ArrayList(java.util.ArrayList) XSString(org.opensaml.core.xml.schema.XSString) XSStringBuilder(org.opensaml.core.xml.schema.impl.XSStringBuilder) XSURI(org.opensaml.core.xml.schema.XSURI) XSAny(org.opensaml.core.xml.schema.XSAny) XSBooleanValue(org.opensaml.core.xml.schema.XSBooleanValue) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) XSInteger(org.opensaml.core.xml.schema.XSInteger) XSBoolean(org.opensaml.core.xml.schema.XSBoolean) XSURIBuilder(org.opensaml.core.xml.schema.impl.XSURIBuilder)

Example 2 with XSStringBuilder

use of org.opensaml.core.xml.schema.impl.XSStringBuilder in project spring-security by spring-projects.

the class TestOpenSamlObjects method attribute.

static Attribute attribute(String name, String value) {
    Attribute attribute = build(Attribute.DEFAULT_ELEMENT_NAME);
    attribute.setName(name);
    XSString xsValue = new XSStringBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
    xsValue.setValue(value);
    attribute.getAttributeValues().add(xsValue);
    return attribute;
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute) EncryptedAttribute(org.opensaml.saml.saml2.core.EncryptedAttribute) XSString(org.opensaml.core.xml.schema.XSString) XSStringBuilder(org.opensaml.core.xml.schema.impl.XSStringBuilder)

Example 3 with XSStringBuilder

use of org.opensaml.core.xml.schema.impl.XSStringBuilder 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;
}
Also used : lombok.val(lombok.val) XSBase64BinaryBuilder(org.opensaml.core.xml.schema.impl.XSBase64BinaryBuilder) XSBooleanBuilder(org.opensaml.core.xml.schema.impl.XSBooleanBuilder) XSIntegerBuilder(org.opensaml.core.xml.schema.impl.XSIntegerBuilder) XSBase64Binary(org.opensaml.core.xml.schema.XSBase64Binary) XSAnyBuilder(org.opensaml.core.xml.schema.impl.XSAnyBuilder) XSObject(org.apache.xerces.xs.XSObject) XSString(org.opensaml.core.xml.schema.XSString) XSStringBuilder(org.opensaml.core.xml.schema.impl.XSStringBuilder) XSURI(org.opensaml.core.xml.schema.XSURI) XSDateTime(org.opensaml.core.xml.schema.XSDateTime) XSDateTimeBuilder(org.opensaml.core.xml.schema.impl.XSDateTimeBuilder) XSBoolean(org.opensaml.core.xml.schema.XSBoolean) XSInteger(org.opensaml.core.xml.schema.XSInteger) JacksonXmlSerializer(org.apereo.cas.util.serialization.JacksonXmlSerializer) NameIDType(org.opensaml.saml.saml2.core.NameIDType) XSURIBuilder(org.opensaml.core.xml.schema.impl.XSURIBuilder)

Aggregations

XSString (org.opensaml.core.xml.schema.XSString)3 XSStringBuilder (org.opensaml.core.xml.schema.impl.XSStringBuilder)3 XSBoolean (org.opensaml.core.xml.schema.XSBoolean)2 XSInteger (org.opensaml.core.xml.schema.XSInteger)2 XSURI (org.opensaml.core.xml.schema.XSURI)2 XSAnyBuilder (org.opensaml.core.xml.schema.impl.XSAnyBuilder)2 XSBooleanBuilder (org.opensaml.core.xml.schema.impl.XSBooleanBuilder)2 XSIntegerBuilder (org.opensaml.core.xml.schema.impl.XSIntegerBuilder)2 XSURIBuilder (org.opensaml.core.xml.schema.impl.XSURIBuilder)2 Attribute (org.opensaml.saml.saml2.core.Attribute)2 EncryptedAttribute (org.opensaml.saml.saml2.core.EncryptedAttribute)2 ArrayList (java.util.ArrayList)1 lombok.val (lombok.val)1 XSObject (org.apache.xerces.xs.XSObject)1 JacksonXmlSerializer (org.apereo.cas.util.serialization.JacksonXmlSerializer)1 XSAny (org.opensaml.core.xml.schema.XSAny)1 XSBase64Binary (org.opensaml.core.xml.schema.XSBase64Binary)1 XSBooleanValue (org.opensaml.core.xml.schema.XSBooleanValue)1 XSDateTime (org.opensaml.core.xml.schema.XSDateTime)1 XSBase64BinaryBuilder (org.opensaml.core.xml.schema.impl.XSBase64BinaryBuilder)1