Search in sources :

Example 71 with DataFormatException

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) WebApplicationException(javax.ws.rs.WebApplicationException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLObject(org.opensaml.core.xml.XMLObject) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Document(org.w3c.dom.Document) DeflateEncoderDecoder(org.apache.cxf.rs.security.saml.DeflateEncoderDecoder) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) Base64Exception(org.apache.cxf.common.util.Base64Exception) WebApplicationException(javax.ws.rs.WebApplicationException) Response(javax.ws.rs.core.Response) DataFormatException(java.util.zip.DataFormatException) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64Exception(org.apache.cxf.common.util.Base64Exception)

Aggregations

DataFormatException (java.util.zip.DataFormatException)71 IOException (java.io.IOException)32 Inflater (java.util.zip.Inflater)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ByteBuffer (java.nio.ByteBuffer)9 ArrayList (java.util.ArrayList)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)5 File (java.io.File)4 BufferedOutputStream (java.io.BufferedOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 ImageException (cbit.image.ImageException)2 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 BaseMediaHeader (cbit.vcell.export.gloworm.atoms.BaseMediaHeader)2 BaseMediaInformation (cbit.vcell.export.gloworm.atoms.BaseMediaInformation)2 HandlerReference (cbit.vcell.export.gloworm.atoms.HandlerReference)2 VideoMediaInformation (cbit.vcell.export.gloworm.atoms.VideoMediaInformation)2 GeometryException (cbit.vcell.geometry.GeometryException)2