boolean postBinding,
String samlResponse
) {
if (StringUtils.isEmpty(samlResponse)) {
reportError("MISSING_SAML_RESPONSE");
throw new BadRequestException();
}
String samlResponseDecoded = samlResponse;
/*
// URL Decoding only applies for the re-direct binding
if (!postBinding) {
try {
samlResponseDecoded = URLDecoder.decode(samlResponse, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new BadRequestException();
}
}
*/
InputStream tokenStream = null;
if (isSupportBase64Encoding()) {
try {
byte[] deflatedToken = Base64Utility.decode(samlResponseDecoded);
tokenStream = !postBinding && isSupportDeflateEncoding()
? new DeflateEncoderDecoder().inflateToken(deflatedToken)
: new ByteArrayInputStream(deflatedToken);
} catch (Base64Exception ex) {
throw new BadRequestException(ex);
} catch (DataFormatException ex) {
throw new BadRequestException(ex);
}
} else {
try {
tokenStream = new ByteArrayInputStream(samlResponseDecoded.getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
throw new BadRequestException(ex);
}
}
Document responseDoc = null;
try {
responseDoc = StaxUtils.read(new InputStreamReader(tokenStream, "UTF-8"));
} catch (Exception ex) {
throw new WebApplicationException(400);
}
LOG.fine("Received response: " + DOM2Writer.nodeToString(responseDoc.getDocumentElement()));
XMLObject responseObject = null;
try {
responseObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
} catch (WSSecurityException ex) {
throw new BadRequestException(ex);
}
if (!(responseObject instanceof org.opensaml.saml2.core.Response)) {
throw new BadRequestException();
}
return (org.opensaml.saml2.core.Response)responseObject;
}