use of org.keycloak.dom.saml.v2.protocol.RequestedAuthnContextType in project keycloak by keycloak.
the class SAMLRequestWriter method write.
/**
* Write a {@code AuthnRequestType } to stream
*
* @param request
*
* @throws org.keycloak.saml.common.exceptions.ProcessingException
*/
public void write(AuthnRequestType request) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.AUTHN_REQUEST.get(), PROTOCOL_NSURI.get());
StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
// Attributes
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), request.getID());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(), request.getVersion());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
URI destination = request.getDestination();
if (destination != null)
StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(), destination.toASCIIString());
String consent = request.getConsent();
if (StringUtil.isNotNull(consent))
StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
URI assertionURL = request.getAssertionConsumerServiceURL();
if (assertionURL != null)
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_URL.get(), assertionURL.toASCIIString());
Boolean forceAuthn = request.isForceAuthn();
if (forceAuthn != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.FORCE_AUTHN.get(), forceAuthn.toString());
}
Boolean isPassive = request.isIsPassive();
// maximize compatibility we emit it only if it is set to true
if (isPassive != null && isPassive == true) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.IS_PASSIVE.get(), isPassive.toString());
}
URI protocolBinding = request.getProtocolBinding();
if (protocolBinding != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.PROTOCOL_BINDING.get(), protocolBinding.toString());
}
Integer assertionIndex = request.getAssertionConsumerServiceIndex();
if (assertionIndex != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_INDEX.get(), assertionIndex.toString());
}
Integer attrIndex = request.getAttributeConsumingServiceIndex();
if (attrIndex != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ATTRIBUTE_CONSUMING_SERVICE_INDEX.get(), attrIndex.toString());
}
String providerName = request.getProviderName();
if (StringUtil.isNotNull(providerName)) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.PROVIDER_NAME.get(), providerName);
}
NameIDType issuer = request.getIssuer();
if (issuer != null) {
write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX), false);
}
SubjectType subject = request.getSubject();
if (subject != null) {
write(subject);
}
Element sig = request.getSignature();
if (sig != null) {
StaxUtil.writeDOMElement(writer, sig);
}
ExtensionsType extensions = request.getExtensions();
if (extensions != null && !extensions.getAny().isEmpty()) {
write(extensions);
}
NameIDPolicyType nameIDPolicy = request.getNameIDPolicy();
if (nameIDPolicy != null) {
write(nameIDPolicy);
}
RequestedAuthnContextType requestedAuthnContext = request.getRequestedAuthnContext();
if (requestedAuthnContext != null) {
write(requestedAuthnContext);
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v2.protocol.RequestedAuthnContextType in project keycloak by keycloak.
the class SAMLRequestedAuthnContextParser method instantiateElement.
/**
* Parse the attributes at the authnrequesttype element
*
* @param startElement
*
* @return
*
* @throws ParsingException
*/
@Override
protected RequestedAuthnContextType instantiateElement(XMLEventReader xmlEventReader, StartElement startElement) throws ParsingException {
RequestedAuthnContextType context = new RequestedAuthnContextType();
Attribute comparison = startElement.getAttributeByName(SAMLProtocolQNames.ATTR_COMPARISON.getQName());
if (comparison != null) {
context.setComparison(AuthnContextComparisonType.fromValue(comparison.getValue()));
}
return context;
}
use of org.keycloak.dom.saml.v2.protocol.RequestedAuthnContextType in project keycloak by keycloak.
the class SAMLRequestWriter method write.
/**
* Write a {@code RequestedAuthnContextType} to stream
*
* @param requestedAuthnContextType
*
* @throws ProcessingException
*/
public void write(RequestedAuthnContextType requestedAuthnContextType) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.REQUESTED_AUTHN_CONTEXT.get(), PROTOCOL_NSURI.get());
AuthnContextComparisonType comparison = requestedAuthnContextType.getComparison();
if (comparison != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.COMPARISON.get(), comparison.value());
}
List<String> authnContextClassRef = requestedAuthnContextType.getAuthnContextClassRef();
if (authnContextClassRef != null && !authnContextClassRef.isEmpty()) {
for (String classRef : authnContextClassRef) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get(), ASSERTION_NSURI.get());
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, classRef);
StaxUtil.writeEndElement(writer);
}
}
List<String> authnContextDeclRef = requestedAuthnContextType.getAuthnContextDeclRef();
if (authnContextDeclRef != null && !authnContextDeclRef.isEmpty()) {
for (String declRef : authnContextDeclRef) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL_REF.get(), ASSERTION_NSURI.get());
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, declRef);
StaxUtil.writeEndElement(writer);
}
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
Aggregations