use of org.keycloak.dom.saml.v1.protocol.SAML11RequestType in project keycloak by keycloak.
the class SAML11RequestWriter method write.
public void write(SAML11RequestType request) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.REQUEST, namespace);
StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, namespace);
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_11_NSURI);
StaxUtil.writeDefaultNameSpace(writer, namespace);
// Attributes
StaxUtil.writeAttribute(writer, SAML11Constants.REQUEST_ID, request.getID());
StaxUtil.writeAttribute(writer, SAML11Constants.MAJOR_VERSION, request.getMajorVersion() + "");
StaxUtil.writeAttribute(writer, SAML11Constants.MINOR_VERSION, request.getMinorVersion() + "");
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
List<String> assertionIDRefs = request.getAssertionIDRef();
for (String assertionIDRef : assertionIDRefs) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_ID_REF, SAML11Constants.ASSERTION_11_NSURI);
StaxUtil.writeCharacters(writer, assertionIDRef);
StaxUtil.writeEndElement(writer);
}
List<String> assertionArtifacts = request.getAssertionArtifact();
for (String assertionArtifact : assertionArtifacts) {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.ASSERTION_ARTIFACT, namespace);
StaxUtil.writeCharacters(writer, assertionArtifact);
StaxUtil.writeEndElement(writer);
}
SAML11QueryAbstractType query = request.getQuery();
if (query instanceof SAML11AuthenticationQueryType) {
SAML11AuthenticationQueryType authQuery = (SAML11AuthenticationQueryType) query;
write(authQuery);
} else if (query instanceof SAML11AttributeQueryType) {
SAML11AttributeQueryType attQuery = (SAML11AttributeQueryType) query;
write(attQuery);
} else if (query instanceof SAML11AuthorizationDecisionQueryType) {
SAML11AuthorizationDecisionQueryType attQuery = (SAML11AuthorizationDecisionQueryType) query;
write(attQuery);
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v1.protocol.SAML11RequestType in project keycloak by keycloak.
the class SAML11RequestParser method parse.
/**
* @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
*/
public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
// Get the startelement
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
StaxParserUtil.validate(startElement, SAML11Constants.REQUEST);
SAML11RequestType request = parseRequiredAttributes(startElement);
while (xmlEventReader.hasNext()) {
// Let us peek at the next start element
startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
if (startElement == null)
break;
String elementName = StaxParserUtil.getElementName(startElement);
if (SAML11Constants.ATTRIBUTE_QUERY.equals(elementName)) {
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
SAML11AttributeQueryType query = SAML11ParserUtil.parseSAML11AttributeQuery(xmlEventReader);
request.setQuery(query);
} else if (SAML11Constants.AUTHENTICATION_QUERY.equals(elementName)) {
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
SAML11AuthenticationQueryType query = SAML11ParserUtil.parseSAML11AuthenticationQuery(xmlEventReader);
request.setQuery(query);
} else if (SAML11Constants.ASSERTION_ARTIFACT.equals(elementName)) {
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
request.addAssertionArtifact(StaxParserUtil.getElementText(xmlEventReader));
} else if (SAML11Constants.AUTHORIZATION_DECISION_QUERY.equals(elementName)) {
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
SAML11AuthorizationDecisionQueryType query = SAML11ParserUtil.parseSAML11AuthorizationDecisionQueryType(xmlEventReader);
request.setQuery(query);
} else if (elementName.equals(JBossSAMLConstants.SIGNATURE.get())) {
request.setSignature(StaxParserUtil.getDOMElement(xmlEventReader));
} else if (SAML11Constants.ASSERTION_ID_REF.equals(elementName)) {
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
request.addAssertionIDRef(StaxParserUtil.getElementText(xmlEventReader));
} else
throw logger.parserUnknownStartElement(elementName, startElement.getLocation());
}
return request;
}
use of org.keycloak.dom.saml.v1.protocol.SAML11RequestType in project keycloak by keycloak.
the class SAML11RequestParser method parseRequiredAttributes.
protected SAML11RequestType parseRequiredAttributes(StartElement startElement) throws ParsingException {
Attribute idAttr = startElement.getAttributeByName(new QName(SAML11Constants.REQUEST_ID));
if (idAttr == null)
throw logger.parserRequiredAttribute(SAML11Constants.REQUEST_ID);
String id = StaxParserUtil.getAttributeValue(idAttr);
Attribute issueInstantAttr = startElement.getAttributeByName(new QName(SAML11Constants.ISSUE_INSTANT));
if (issueInstantAttr == null)
throw logger.parserRequiredAttribute(SAML11Constants.ISSUE_INSTANT);
XMLGregorianCalendar issueInstant = XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(issueInstantAttr));
return new SAML11RequestType(id, issueInstant);
}
Aggregations