use of java.util.zip.DataFormatException in project cxf by apache.
the class AbstractRequestAssertionConsumerHandler method readSAMLResponse.
private org.opensaml.saml.saml2.core.Response readSAMLResponse(boolean postBinding, String samlResponse) {
if (StringUtils.isEmpty(samlResponse)) {
reportError("MISSING_SAML_RESPONSE");
throw ExceptionUtils.toBadRequestException(null, null);
}
String samlResponseDecoded = samlResponse;
/*
// URL Decoding only applies for the re-direct binding
if (!postBinding) {
try {
samlResponseDecoded = URLDecoder.decode(samlResponse, StandardCharsets.UTF_8);
} catch (UnsupportedEncodingException e) {
throw ExceptionUtils.toBadRequestException(null, null);
}
}
*/
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 ExceptionUtils.toBadRequestException(ex, null);
} catch (DataFormatException ex) {
throw ExceptionUtils.toBadRequestException(ex, null);
}
} else {
tokenStream = new ByteArrayInputStream(samlResponseDecoded.getBytes(StandardCharsets.UTF_8));
}
Document responseDoc = null;
try {
responseDoc = StaxUtils.read(new InputStreamReader(tokenStream, StandardCharsets.UTF_8));
} catch (Exception ex) {
throw new WebApplicationException(400);
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Received response: " + DOM2Writer.nodeToString(responseDoc.getDocumentElement()));
}
XMLObject responseObject = null;
try {
responseObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
} catch (WSSecurityException ex) {
throw ExceptionUtils.toBadRequestException(ex, null);
}
if (!(responseObject instanceof org.opensaml.saml.saml2.core.Response)) {
throw ExceptionUtils.toBadRequestException(null, null);
}
return (org.opensaml.saml.saml2.core.Response) responseObject;
}
Aggregations