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;
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations