use of org.keycloak.dom.saml.v1.assertion.SAML11AttributeType in project keycloak by keycloak.
the class SAML11ParserUtil method parseSAML11Attribute.
/**
* Parse a {@link SAML11AttributeType}
*
* @param xmlEventReader
*
* @return
*
* @throws ParsingException
*/
public static SAML11AttributeType parseSAML11Attribute(XMLEventReader xmlEventReader) throws ParsingException {
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE.get());
SAML11AttributeType attributeType = null;
Attribute name = startElement.getAttributeByName(new QName(SAML11Constants.ATTRIBUTE_NAME));
if (name == null)
throw logger.parserRequiredAttribute("Name");
String attribName = StaxParserUtil.getAttributeValue(name);
Attribute namesp = startElement.getAttributeByName(new QName(SAML11Constants.ATTRIBUTE_NAMESPACE));
if (namesp == null)
throw logger.parserRequiredAttribute("Namespace");
String attribNamespace = StaxParserUtil.getAttributeValue(namesp);
attributeType = new SAML11AttributeType(attribName, URI.create(attribNamespace));
attributeType.add(parseAttributeValue(xmlEventReader));
parseAttributeType(xmlEventReader, startElement, JBossSAMLConstants.ATTRIBUTE.get(), attributeType);
return attributeType;
}
use of org.keycloak.dom.saml.v1.assertion.SAML11AttributeType in project keycloak by keycloak.
the class SAML11ParserUtil method parseSAML11AttributeStatement.
/**
* Parse an {@code SAML11AttributeStatementType}
*
* @param xmlEventReader
*
* @return
*
* @throws ParsingException
*/
public static SAML11AttributeStatementType parseSAML11AttributeStatement(XMLEventReader xmlEventReader) throws ParsingException {
SAML11AttributeStatementType attributeStatementType = new SAML11AttributeStatementType();
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
String ATTRIBSTATEMT = JBossSAMLConstants.ATTRIBUTE_STATEMENT.get();
StaxParserUtil.validate(startElement, ATTRIBSTATEMT);
while (xmlEventReader.hasNext()) {
XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
if (xmlEvent instanceof EndElement) {
EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
StaxParserUtil.validate(endElement, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get());
break;
}
// Get the next start element
startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
String tag = startElement.getName().getLocalPart();
if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag)) {
SAML11AttributeType attribute = parseSAML11Attribute(xmlEventReader);
attributeStatementType.add(attribute);
} else if (JBossSAMLConstants.SUBJECT.get().equals(tag)) {
SAML11SubjectParser parser = new SAML11SubjectParser();
SAML11SubjectType subject = (SAML11SubjectType) parser.parse(xmlEventReader);
attributeStatementType.setSubject(subject);
} else
throw logger.parserUnknownTag(tag, startElement.getLocation());
}
return attributeStatementType;
}
use of org.keycloak.dom.saml.v1.assertion.SAML11AttributeType in project keycloak by keycloak.
the class SAML11AssertionWriter method write.
public void write(SAML11AttributeStatementType statement) throws ProcessingException {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get(), SAML11Constants.ASSERTION_11_NSURI);
SAML11SubjectType subject = statement.getSubject();
if (subject != null)
write(subject);
List<SAML11AttributeType> attributes = statement.get();
if (attributes != null) {
for (SAML11AttributeType attr : attributes) {
write(attr);
}
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v1.assertion.SAML11AttributeType in project keycloak by keycloak.
the class SAML11RequestWriter method write.
public void write(SAML11AttributeQueryType attr) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.ATTRIBUTE_QUERY, namespace);
URI resource = attr.getResource();
if (resource != null) {
StaxUtil.writeAttribute(writer, SAML11Constants.RESOURCE, resource.toString());
}
SAML11SubjectType subject = attr.getSubject();
if (subject != null) {
assertionWriter.write(subject);
}
List<SAML11AttributeDesignatorType> attributes = attr.get();
for (SAML11AttributeDesignatorType attribute : attributes) {
if (attribute instanceof SAML11AttributeType) {
SAML11AttributeType sat = (SAML11AttributeType) attribute;
assertionWriter.write(sat);
} else
throw logger.writerUnknownTypeError(attribute.getClass().getName());
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v1.assertion.SAML11AttributeType in project keycloak by keycloak.
the class AssertionUtil method getRoles.
/**
* Given an assertion, return the list of roles it may have
*
* @param assertion The {@link SAML11AssertionType}
* @param roleKeys a list of string values representing the role keys. The list can be null.
*
* @return
*/
public static List<String> getRoles(SAML11AssertionType assertion, List<String> roleKeys) {
List<String> roles = new ArrayList<>();
List<SAML11StatementAbstractType> statements = assertion.getStatements();
for (SAML11StatementAbstractType statement : statements) {
if (statement instanceof SAML11AttributeStatementType) {
SAML11AttributeStatementType attributeStatement = (SAML11AttributeStatementType) statement;
List<SAML11AttributeType> attributes = attributeStatement.get();
for (SAML11AttributeType attr : attributes) {
if (roleKeys != null && roleKeys.size() > 0) {
if (!roleKeys.contains(attr.getAttributeName()))
continue;
}
List<Object> attributeValues = attr.get();
if (attributeValues != null) {
for (Object attrValue : attributeValues) {
if (attrValue instanceof String) {
roles.add((String) attrValue);
} else if (attrValue instanceof Node) {
Node roleNode = (Node) attrValue;
roles.add(roleNode.getFirstChild().getNodeValue());
} else
throw logger.unknownObjectType(attrValue);
}
}
}
}
}
return roles;
}
Aggregations