Search in sources :

Example 11 with Base64

use of java.util.Base64 in project webpieces by deanhiller.

the class SettingsMarshaller method marshalPayload.

public String marshalPayload(List<Http2Setting> settingsPayload) {
    DataWrapper data = marshalOut(settingsPayload);
    byte[] byteBuf = data.createByteArray();
    Encoder encoder = Base64.getEncoder();
    return encoder.encodeToString(byteBuf);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Encoder(java.util.Base64.Encoder)

Example 12 with Base64

use of java.util.Base64 in project webpieces by deanhiller.

the class SettingsMarshaller method unmarshalPayload.

public List<Http2Setting> unmarshalPayload(String base64SettingsPayload) {
    Decoder decoder = Base64.getDecoder();
    byte[] decoded = decoder.decode(base64SettingsPayload);
    ByteBuffer buf = ByteBuffer.wrap(decoded);
    return unmarshal(buf);
}
Also used : Decoder(java.util.Base64.Decoder) ByteBuffer(java.nio.ByteBuffer)

Example 13 with Base64

use of java.util.Base64 in project fru-paqx-parent by dellemc-symphony.

the class ContextConfig method servletContainer.

@Bean
public /**
     * This container is required in order to implement the redirect from http 8080 to https 18443 in spring boot.
     * This means that http can continue to be used but will automatically redirect to https
     * The responses from FRU will be https regardless of the protocol/port used by the cli.
     */
EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }

        @Override
        protected /**
             * This is the method where ssl is configured in the tomcat container.
             * We want to override this in order to be able to take an encrypted-base64-encoded password from
             * application.properties and to decode+decrypt it and provide it to the Ssl object before ssl configuration begins.
             */
        void configureSsl(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("ContextConfig: servletContainer: encoded password = " + ssl.getKeyStorePassword());
            }
            byte[] decodedBytes = Base64.getDecoder().decode(ssl.getKeyStorePassword());
            ssl.setKeyStorePassword(new String(decodedBytes));
            super.configureSsl(protocol, ssl);
        }
    };
    //Setup the redirection
    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    //Setup the custom realm, which sets the custom redirect code.
    //By default the redirect is 302.  But if the request to be redirected is a post,
    //then the post is converted to a get and therefore the post's body is removed in the redirect. (e.g. using CURL)
    //We need to set the redirection with code 307 so that the origin method is used in the redirect
    //e.g. get uses get on redirect and post uses post on redirect.
    //This conforms to standard RFC 2616
    tomcat.addContextCustomizers((TomcatContextCustomizer) context -> {
        RealmBase base = new CombinedRealm();
        base.setTransportGuaranteeRedirectStatus(307);
        context.setRealm(base);
    });
    return tomcat;
}
Also used : Context(org.apache.catalina.Context) CombinedRealm(org.apache.catalina.realm.CombinedRealm) Logger(org.slf4j.Logger) TomcatContextCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection) LoggerFactory(org.slf4j.LoggerFactory) Connector(org.apache.catalina.connector.Connector) Context(org.apache.catalina.Context) EmbeddedServletContainerFactory(org.springframework.boot.context.embedded.EmbeddedServletContainerFactory) RealmBase(org.apache.catalina.realm.RealmBase) Configuration(org.springframework.context.annotation.Configuration) Ssl(org.springframework.boot.context.embedded.Ssl) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) Base64(java.util.Base64) ConsumerContextConfig(com.dell.cpsd.service.common.client.context.ConsumerContextConfig) AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) Bean(org.springframework.context.annotation.Bean) AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol) CombinedRealm(org.apache.catalina.realm.CombinedRealm) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) RealmBase(org.apache.catalina.realm.RealmBase) Ssl(org.springframework.boot.context.embedded.Ssl) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection) Bean(org.springframework.context.annotation.Bean)

Example 14 with Base64

use of java.util.Base64 in project j2objc by google.

the class Base64Test method testEncoder_encodeByteBuffer.

public void testEncoder_encodeByteBuffer() {
    Encoder encoder = Base64.getEncoder();
    byte[] emptyByteArray = new byte[0];
    ByteBuffer emptyByteBuffer = ByteBuffer.wrap(emptyByteArray);
    ByteBuffer emptyEncodedBuffer = encoder.encode(emptyByteBuffer);
    assertEquals(emptyByteBuffer, emptyEncodedBuffer);
    assertNotSame(emptyByteArray, emptyEncodedBuffer);
    // Test the two types of byte buffer.
    byte[] input = "abcefghi".getBytes(US_ASCII);
    String expectedString = "YWJjZWZnaGk=";
    byte[] expectedBytes = expectedString.getBytes(US_ASCII);
    ByteBuffer inputBuffer = ByteBuffer.allocate(input.length);
    inputBuffer.put(input);
    inputBuffer.position(0);
    testEncoder_encodeByteBuffer(encoder, inputBuffer, expectedBytes);
    inputBuffer = ByteBuffer.allocateDirect(input.length);
    inputBuffer.put(input);
    inputBuffer.position(0);
    testEncoder_encodeByteBuffer(encoder, inputBuffer, expectedBytes);
}
Also used : Encoder(java.util.Base64.Encoder) ByteBuffer(java.nio.ByteBuffer)

Example 15 with Base64

use of java.util.Base64 in project j2objc by google.

the class Base64Test method testEncoder_encodeArrayToArray.

/**
     * Tests {@link Decoder#decode(byte[], byte[])} for correctness.
     */
public void testEncoder_encodeArrayToArray() {
    Encoder encoder = Base64.getEncoder();
    // Empty input
    assertEquals(0, encoder.encode(new byte[0], new byte[0]));
    // Test data for non-empty input
    byte[] input = "abcefghi".getBytes(US_ASCII);
    String expectedString = "YWJjZWZnaGk=";
    byte[] encodedBytes = expectedString.getBytes(US_ASCII);
    // Non-empty input: output array too short
    byte[] tooShort = new byte[encodedBytes.length - 1];
    try {
        encoder.encode(input, tooShort);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    // Non-empty input: output array longer than required
    byte[] tooLong = new byte[encodedBytes.length + 1];
    int tooLongBytesEncoded = encoder.encode(input, tooLong);
    assertEquals(encodedBytes.length, tooLongBytesEncoded);
    assertEquals(0, tooLong[tooLong.length - 1]);
    assertArrayPrefixEquals(tooLong, encodedBytes.length, encodedBytes);
    // Non-empty input: output array has exact minimum required size
    byte[] justRight = new byte[encodedBytes.length];
    int justRightBytesEncoded = encoder.encode(input, justRight);
    assertEquals(encodedBytes.length, justRightBytesEncoded);
    assertArrayEquals(encodedBytes, justRight);
}
Also used : Encoder(java.util.Base64.Encoder)

Aggregations

Decoder (java.util.Base64.Decoder)16 Encoder (java.util.Base64.Encoder)9 Base64 (java.util.Base64)8 ByteBuffer (java.nio.ByteBuffer)5 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ConsumerContextConfig (com.dell.cpsd.service.common.client.context.ConsumerContextConfig)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Unauthorized401Exception (com.nike.riposte.server.error.exception.Unauthorized401Exception)1 CompressionType (com.yahoo.pulsar.client.api.CompressionType)1 Message (com.yahoo.pulsar.client.api.Message)1 MessageBuilder (com.yahoo.pulsar.client.api.MessageBuilder)1 Producer (com.yahoo.pulsar.client.api.Producer)1 ProducerConfiguration (com.yahoo.pulsar.client.api.ProducerConfiguration)1 MessageRoutingMode (com.yahoo.pulsar.client.api.ProducerConfiguration.MessageRoutingMode)1 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)1 ObjectMapperFactory (com.yahoo.pulsar.common.util.ObjectMapperFactory)1 WebSocketError (com.yahoo.pulsar.websocket.WebSocketError)1