Search in sources :

Example 1 with ASTChoiceType

use of org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType in project keycloak by keycloak.

the class StatementUtil method createAttributeStatement.

/**
 * Given a set of roles, create an attribute statement
 *
 * @param roles
 *
 * @return
 */
public static AttributeStatementType createAttributeStatement(List<String> roles) {
    AttributeStatementType attrStatement = null;
    for (String role : roles) {
        if (attrStatement == null) {
            attrStatement = new AttributeStatementType();
        }
        AttributeType attr = new AttributeType(AttributeConstants.ROLE_IDENTIFIER_ASSERTION);
        attr.addAttributeValue(role);
        attrStatement.addAttribute(new ASTChoiceType(attr));
    }
    return attrStatement;
}
Also used : AttributeType(org.keycloak.dom.saml.v2.assertion.AttributeType) AttributeStatementType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType) ASTChoiceType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType)

Example 2 with ASTChoiceType

use of org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType in project keycloak by keycloak.

the class StatementUtil method createAttributeStatementForRoles.

/**
 * Given a set of roles, create an attribute statement
 *
 * @param roles
 * @param multivalued if you want the attribute to be multi valued
 *
 * @return
 */
public static AttributeStatementType createAttributeStatementForRoles(List<String> roles, boolean multivalued) {
    if (!multivalued) {
        return createAttributeStatement(roles);
    }
    AttributeStatementType attrStatement = new AttributeStatementType();
    AttributeType attr = new AttributeType(AttributeConstants.ROLE_IDENTIFIER_ASSERTION);
    for (String role : roles) {
        attr.addAttributeValue(role);
    }
    attrStatement.addAttribute(new ASTChoiceType(attr));
    return attrStatement;
}
Also used : AttributeType(org.keycloak.dom.saml.v2.assertion.AttributeType) AttributeStatementType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType) ASTChoiceType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType)

Example 3 with ASTChoiceType

use of org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType in project keycloak by keycloak.

the class StatementUtil method createAttributeStatement.

/**
 * Given an attribute type and a value, create {@link AttributeStatementType}
 *
 * @param key attribute type
 * @param value attribute value
 *
 * @return
 */
public static AttributeStatementType createAttributeStatement(String key, String value) {
    AttributeStatementType attrStatement = new AttributeStatementType();
    AttributeType attr = new AttributeType(key);
    attr.addAttributeValue(value);
    attrStatement.addAttribute(new ASTChoiceType(attr));
    return attrStatement;
}
Also used : AttributeType(org.keycloak.dom.saml.v2.assertion.AttributeType) AttributeStatementType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType) ASTChoiceType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType)

Example 4 with ASTChoiceType

use of org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType in project keycloak by keycloak.

the class SAMLAssertionWriter method write.

public void write(AttributeStatementType statement) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get(), ASSERTION_NSURI.get());
    List<ASTChoiceType> attributes = statement.getAttributes();
    if (attributes != null) {
        for (ASTChoiceType attr : attributes) {
            AttributeType attributeType = attr.getAttribute();
            if (attributeType != null) {
                write(attributeType);
            }
            EncryptedElementType encType = attr.getEncryptedAssertion();
            if (encType != null)
                throw logger.notImplementedYet("EncryptedElementType");
        }
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : AttributeType(org.keycloak.dom.saml.v2.assertion.AttributeType) ASTChoiceType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType) EncryptedElementType(org.keycloak.dom.saml.v2.assertion.EncryptedElementType)

Example 5 with ASTChoiceType

use of org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType in project keycloak by keycloak.

the class BrokerTest method createAuthnResponse.

private SAML2Object createAuthnResponse(SAML2Object so) {
    AuthnRequestType req = (AuthnRequestType) so;
    try {
        final ResponseType res = new SAML2LoginResponseBuilder().requestID(req.getID()).destination(req.getAssertionConsumerServiceURL().toString()).issuer("https://saml.idp/saml").assertionExpiration(1000000).subjectExpiration(1000000).requestIssuer(getAuthServerRealmBase(REALM_NAME).toString()).sessionIndex("idp:" + UUID.randomUUID()).buildModel();
        AttributeStatementType attrStatement = new AttributeStatementType();
        AttributeType attribute = new AttributeType("mail");
        attribute.addAttributeValue("v@w.x");
        attrStatement.addAttribute(new ASTChoiceType(attribute));
        res.getAssertions().get(0).getAssertion().addStatement(attrStatement);
        return res;
    } catch (ConfigurationException | ProcessingException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) ConfigurationException(org.keycloak.saml.common.exceptions.ConfigurationException) AttributeType(org.keycloak.dom.saml.v2.assertion.AttributeType) AttributeStatementType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType) ASTChoiceType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType) SAML2LoginResponseBuilder(org.keycloak.saml.SAML2LoginResponseBuilder) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Aggregations

ASTChoiceType (org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType)10 AttributeType (org.keycloak.dom.saml.v2.assertion.AttributeType)10 AttributeStatementType (org.keycloak.dom.saml.v2.assertion.AttributeStatementType)8 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)2 StatementAbstractType (org.keycloak.dom.saml.v2.assertion.StatementAbstractType)2 IOException (java.io.IOException)1 URI (java.net.URI)1 KeyPair (java.security.KeyPair)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Status (javax.ws.rs.core.Response.Status)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1