use of org.keycloak.dom.saml.v1.assertion.SAML11ActionType in project keycloak by keycloak.
the class SAML11ParserUtil method parseSAML11AuthorizationDecisionStatement.
public static SAML11AuthorizationDecisionStatementType parseSAML11AuthorizationDecisionStatement(XMLEventReader xmlEventReader) throws ParsingException {
SAML11AuthorizationDecisionStatementType authzDecision = null;
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
StaxParserUtil.validate(startElement, SAML11Constants.AUTHORIZATION_DECISION_STATEMENT);
Attribute decision = startElement.getAttributeByName(new QName(SAML11Constants.DECISION));
if (decision == null)
throw logger.parserRequiredAttribute("Decision");
String decisionValue = StaxParserUtil.getAttributeValue(decision);
Attribute resource = startElement.getAttributeByName(new QName(SAML11Constants.RESOURCE));
if (resource == null)
throw logger.parserRequiredAttribute("Namespace");
String resValue = StaxParserUtil.getAttributeValue(resource);
authzDecision = new SAML11AuthorizationDecisionStatementType(URI.create(resValue), SAML11DecisionType.valueOf(decisionValue));
while (xmlEventReader.hasNext()) {
XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
if (xmlEvent instanceof EndElement) {
EndElement end = StaxParserUtil.getNextEndElement(xmlEventReader);
if (StaxParserUtil.matches(end, SAML11Constants.AUTHORIZATION_DECISION_STATEMENT))
break;
}
startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
if (startElement == null)
break;
String tag = StaxParserUtil.getElementName(startElement);
if (SAML11Constants.ACTION.equals(tag)) {
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
SAML11ActionType samlAction = new SAML11ActionType();
Attribute namespaceAttr = startElement.getAttributeByName(new QName(SAML11Constants.NAMESPACE));
if (namespaceAttr != null) {
samlAction.setNamespace(StaxParserUtil.getAttributeValue(namespaceAttr));
}
samlAction.setValue(StaxParserUtil.getElementText(xmlEventReader));
authzDecision.addAction(samlAction);
} else if (JBossSAMLConstants.SUBJECT.get().equals(tag)) {
SAML11SubjectParser parser = new SAML11SubjectParser();
authzDecision.setSubject((SAML11SubjectType) parser.parse(xmlEventReader));
} else
throw logger.parserUnknownTag(tag, startElement.getLocation());
}
return authzDecision;
}
use of org.keycloak.dom.saml.v1.assertion.SAML11ActionType in project keycloak by keycloak.
the class SAML11RequestWriter method write.
public void write(SAML11AuthorizationDecisionQueryType attr) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.AUTHORIZATION_DECISION_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<SAML11ActionType> actions = attr.get();
for (SAML11ActionType action : actions) {
assertionWriter.write(action);
}
SAML11EvidenceType evidence = attr.getEvidence();
if (evidence != null) {
assertionWriter.write(evidence);
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v1.assertion.SAML11ActionType in project keycloak by keycloak.
the class SAML11ParserUtil method parseSAML11AuthorizationDecisionQueryType.
/**
* Parse the {@link SAML11AuthorizationDecisionQueryType}
*
* @param xmlEventReader
*
* @return
*
* @throws ParsingException
*/
public static SAML11AuthorizationDecisionQueryType parseSAML11AuthorizationDecisionQueryType(XMLEventReader xmlEventReader) throws ParsingException {
SAML11AuthorizationDecisionQueryType query = new SAML11AuthorizationDecisionQueryType();
StartElement startElement;
// There may be additional things under subject confirmation
while (xmlEventReader.hasNext()) {
XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
if (xmlEvent instanceof EndElement) {
EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
if (StaxParserUtil.matches(endElement, SAML11Constants.AUTHORIZATION_DECISION_QUERY))
break;
else
throw logger.parserUnknownEndElement(StaxParserUtil.getElementName(endElement), xmlEvent.getLocation());
}
if (xmlEvent instanceof StartElement) {
startElement = (StartElement) xmlEvent;
String startTag = StaxParserUtil.getElementName(startElement);
if (startTag.equals(JBossSAMLConstants.SUBJECT.get())) {
SAML11SubjectParser parser = new SAML11SubjectParser();
query.setSubject((SAML11SubjectType) parser.parse(xmlEventReader));
} else if (startTag.equals(SAML11Constants.RESOURCE)) {
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
query.setResource(URI.create(StaxParserUtil.getElementText(xmlEventReader)));
} else if (startTag.equals(SAML11Constants.ACTION)) {
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
SAML11ActionType action = new SAML11ActionType();
Attribute nsAttr = startElement.getAttributeByName(new QName(SAML11Constants.NAMESPACE));
if (nsAttr != null) {
action.setNamespace(StaxParserUtil.getAttributeValue(nsAttr));
}
action.setValue(StaxParserUtil.getElementText(xmlEventReader));
query.add(action);
} else
throw logger.parserUnknownTag(startTag, startElement.getLocation());
}
}
return query;
}
use of org.keycloak.dom.saml.v1.assertion.SAML11ActionType in project keycloak by keycloak.
the class SAML11AssertionWriter method write.
public void write(SAML11AuthorizationDecisionStatementType xacmlStat) throws ProcessingException {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.AUTHORIZATION_DECISION_STATEMENT, ns);
String resource = xacmlStat.getResource().toString();
StaxUtil.writeAttribute(writer, SAML11Constants.RESOURCE, resource);
StaxUtil.writeAttribute(writer, SAML11Constants.DECISION, xacmlStat.getDecision().name());
SAML11SubjectType subject = xacmlStat.getSubject();
if (subject != null)
write(subject);
List<SAML11ActionType> actions = xacmlStat.getActions();
for (SAML11ActionType action : actions) {
write(action);
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
Aggregations