use of org.keycloak.dom.saml.v2.assertion.AuthnContextType in project keycloak by keycloak.
the class SAMLAssertionWriter method write.
/**
* Write an {@code AuthnContextType} to stream
*
* @param authContext
*
* @throws ProcessingException
*/
public void write(AuthnContextType authContext) throws ProcessingException {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT.get(), ASSERTION_NSURI.get());
AuthnContextType.AuthnContextTypeSequence sequence = authContext.getSequence();
if (sequence != null) {
AuthnContextClassRefType authnContextClassRefType = sequence.getClassRef();
if (authnContextClassRefType != null) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, authnContextClassRefType.getValue().toASCIIString());
StaxUtil.writeEndElement(writer);
}
Set<URIType> uriTypes = sequence.getURIType();
if (uriTypes != null) {
for (URIType uriType : uriTypes) {
if (uriType instanceof AuthnContextDeclType) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toASCIIString());
StaxUtil.writeEndElement(writer);
}
if (uriType instanceof AuthnContextDeclRefType) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL_REF.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toASCIIString());
StaxUtil.writeEndElement(writer);
}
}
}
}
Set<URI> authAuthorities = authContext.getAuthenticatingAuthority();
if (authAuthorities != null) {
for (URI aa : authAuthorities) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHENTICATING_AUTHORITY.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, aa.toASCIIString());
StaxUtil.writeEndElement(writer);
}
}
Set<URIType> uriTypes = authContext.getURIType();
for (URIType uriType : uriTypes) {
if (uriType instanceof AuthnContextClassRefType) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toString());
StaxUtil.writeEndElement(writer);
} else if (uriType instanceof AuthnContextDeclRefType) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL_REF.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toString());
StaxUtil.writeEndElement(writer);
} else if (uriType instanceof AuthnContextDeclType) {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toString());
StaxUtil.writeEndElement(writer);
}
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v2.assertion.AuthnContextType in project keycloak by keycloak.
the class SAMLAssertionWriter method write.
/**
* Write an {@code AuthnStatementType} to stream
*
* @param authnStatement
*
* @throws ProcessingException
*/
public void write(AuthnStatementType authnStatement, boolean includeNamespace) throws ProcessingException {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_STATEMENT.get(), ASSERTION_NSURI.get());
if (includeNamespace) {
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
}
XMLGregorianCalendar authnInstant = authnStatement.getAuthnInstant();
if (authnInstant != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.AUTHN_INSTANT.get(), authnInstant.toString());
}
String sessionIndex = authnStatement.getSessionIndex();
if (sessionIndex != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.SESSION_INDEX.get(), sessionIndex);
}
XMLGregorianCalendar sessionNotOnOrAfter = authnStatement.getSessionNotOnOrAfter();
if (sessionNotOnOrAfter != null) {
StaxUtil.writeAttribute(writer, SAMLAssertionQNames.ATTR_SESSION_NOT_ON_OR_AFTER.getQName(), sessionNotOnOrAfter.toString());
}
AuthnContextType authnContext = authnStatement.getAuthnContext();
if (authnContext != null)
write(authnContext);
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
Aggregations