use of org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter in project keycloak by keycloak.
the class SAMLDataMarshaller method serialize.
@Override
public String serialize(Object obj) {
// Lame impl, but hopefully sufficient for now. See if something better is needed...
if (obj.getClass().getName().startsWith("org.keycloak.dom.saml")) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
if (obj instanceof ResponseType) {
ResponseType responseType = (ResponseType) obj;
SAMLResponseWriter samlWriter = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(bos));
samlWriter.write(responseType);
} else if (obj instanceof AssertionType) {
AssertionType assertion = (AssertionType) obj;
SAMLAssertionWriter samlWriter = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(bos));
samlWriter.write(assertion);
} else if (obj instanceof AuthnStatementType) {
AuthnStatementType authnStatement = (AuthnStatementType) obj;
SAMLAssertionWriter samlWriter = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(bos));
samlWriter.write(authnStatement, true);
} else if (obj instanceof ArtifactResponseType) {
ArtifactResponseType artifactResponseType = (ArtifactResponseType) obj;
SAMLResponseWriter samlWriter = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(bos));
samlWriter.write(artifactResponseType);
} else {
throw new IllegalArgumentException("Don't know how to serialize object of type " + obj.getClass().getName());
}
} catch (ProcessingException pe) {
throw new RuntimeException(pe);
}
return new String(bos.toByteArray(), GeneralConstants.SAML_CHARSET);
} else {
return super.serialize(obj);
}
}
use of org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter in project keycloak by keycloak.
the class AssertionUtil method asString.
/**
* Given {@code AssertionType}, convert it into a String
*
* @param assertion
*
* @return
*
* @throws ProcessingException
*/
public static String asString(AssertionType assertion) throws ProcessingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(assertion);
return new String(baos.toByteArray(), GeneralConstants.SAML_CHARSET);
}
use of org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter in project keycloak by keycloak.
the class AssertionUtil method asDocument.
/**
* Given {@code AssertionType}, convert it into a DOM Document.
*
* @param assertion
*
* @return
*
* @throws ProcessingException
*/
public static Document asDocument(AssertionType assertion) throws ProcessingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(assertion);
try {
return DocumentUtil.getDocument(new ByteArrayInputStream(baos.toByteArray()));
} catch (Exception e) {
throw logger.processingError(e);
}
}
Aggregations