Search in sources :

Example 1 with DeflateEncoderDecoder

use of org.apache.cxf.rs.security.saml.DeflateEncoderDecoder in project ddf by codice.

the class RestSecurityTest method testInflateDeflateWithTokenDuplication.

@Test
public void testInflateDeflateWithTokenDuplication() throws Exception {
    String token = "valid_grant valid_grant valid_grant valid_grant valid_grant valid_grant";
    DeflateEncoderDecoder deflateEncoderDecoder = new DeflateEncoderDecoder();
    byte[] deflatedToken = deflateEncoderDecoder.deflateToken(token.getBytes());
    String cxfInflatedToken = IOUtils.toString(deflateEncoderDecoder.inflateToken(deflatedToken));
    String streamInflatedToken = IOUtils.toString(new InflaterInputStream(new ByteArrayInputStream(deflatedToken), new Inflater(true)));
    assertNotSame(cxfInflatedToken, token);
    assertEquals(streamInflatedToken, token);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) DeflateEncoderDecoder(org.apache.cxf.rs.security.saml.DeflateEncoderDecoder) Test(org.junit.Test)

Example 2 with DeflateEncoderDecoder

use of org.apache.cxf.rs.security.saml.DeflateEncoderDecoder in project ddf by codice.

the class SamlSecurityTest method testInflateDeflateWithTokenDuplication.

@Test
public void testInflateDeflateWithTokenDuplication() throws Exception {
    String token = "valid_grant valid_grant valid_grant valid_grant valid_grant valid_grant";
    DeflateEncoderDecoder deflateEncoderDecoder = new DeflateEncoderDecoder();
    byte[] deflatedToken = deflateEncoderDecoder.deflateToken(token.getBytes());
    String cxfInflatedToken = IOUtils.toString(deflateEncoderDecoder.inflateToken(deflatedToken));
    String streamInflatedToken = IOUtils.toString(new InflaterInputStream(new ByteArrayInputStream(deflatedToken), new Inflater(true)));
    assertNotSame(cxfInflatedToken, token);
    assertEquals(streamInflatedToken, token);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) DeflateEncoderDecoder(org.apache.cxf.rs.security.saml.DeflateEncoderDecoder) Test(org.junit.Test)

Example 3 with DeflateEncoderDecoder

use of org.apache.cxf.rs.security.saml.DeflateEncoderDecoder in project cxf by apache.

the class JAXRSSamlTest method encodeToken.

private String encodeToken(String assertion) throws Base64Exception {
    byte[] tokenBytes = assertion.getBytes(StandardCharsets.UTF_8);
    tokenBytes = new DeflateEncoderDecoder().deflateToken(tokenBytes);
    StringWriter writer = new StringWriter();
    Base64Utility.encode(tokenBytes, 0, tokenBytes.length, writer);
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) DeflateEncoderDecoder(org.apache.cxf.rs.security.saml.DeflateEncoderDecoder)

Example 4 with DeflateEncoderDecoder

use of org.apache.cxf.rs.security.saml.DeflateEncoderDecoder in project cxf by apache.

the class SamlRedirectBindingFilter method encodeAuthnRequest.

protected String encodeAuthnRequest(Element authnRequest) throws IOException {
    String requestMessage = DOM2Writer.nodeToString(authnRequest);
    DeflateEncoderDecoder encoder = new DeflateEncoderDecoder();
    byte[] deflatedBytes = encoder.deflateToken(requestMessage.getBytes(StandardCharsets.UTF_8));
    return Base64Utility.encode(deflatedBytes);
}
Also used : DeflateEncoderDecoder(org.apache.cxf.rs.security.saml.DeflateEncoderDecoder)

Example 5 with DeflateEncoderDecoder

use of org.apache.cxf.rs.security.saml.DeflateEncoderDecoder in project cxf by apache.

the class SamlPostBindingFilter method encodeAuthnRequest.

protected String encodeAuthnRequest(Element authnRequest) throws IOException {
    String requestMessage = DOM2Writer.nodeToString(authnRequest);
    final byte[] deflatedBytes;
    // Not correct according to the spec but required by some IDPs.
    if (useDeflateEncoding) {
        DeflateEncoderDecoder encoder = new DeflateEncoderDecoder();
        deflatedBytes = encoder.deflateToken(requestMessage.getBytes(StandardCharsets.UTF_8));
    } else {
        deflatedBytes = requestMessage.getBytes(StandardCharsets.UTF_8);
    }
    return Base64Utility.encode(deflatedBytes);
}
Also used : DeflateEncoderDecoder(org.apache.cxf.rs.security.saml.DeflateEncoderDecoder)

Aggregations

DeflateEncoderDecoder (org.apache.cxf.rs.security.saml.DeflateEncoderDecoder)10 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 StringWriter (java.io.StringWriter)3 Document (org.w3c.dom.Document)3 IOException (java.io.IOException)2 DataFormatException (java.util.zip.DataFormatException)2 Inflater (java.util.zip.Inflater)2 InflaterInputStream (java.util.zip.InflaterInputStream)2 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)2 Test (org.junit.Test)2 XMLObject (org.opensaml.core.xml.XMLObject)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SignatureException (java.security.SignatureException)1 BadRequestException (javax.ws.rs.BadRequestException)1