Example usage for org.springframework.util Base64Utils decodeFromString

List of usage examples for org.springframework.util Base64Utils decodeFromString

Introduction

In this page you can find the example usage for org.springframework.util Base64Utils decodeFromString.

Prototype

public static byte[] decodeFromString(String src) 

Source Link

Document

Base64-decode the given byte array from an UTF-8 String.

Usage

From source file:io.spring.initializr.actuate.stat.MainControllerStatsIntegrationTests.java

@Test
public void authorizationHeaderIsSet() {
    downloadArchive("/starter.zip");
    assertEquals("No stat got generated", 1, statsMockController.stats.size());
    StatsMockController.Content content = statsMockController.stats.get(0);

    String authorization = content.authorization;
    assertNotNull("Authorization header must be set", authorization);
    assertTrue("Wrong value for authorization header", authorization.startsWith("Basic "));
    String token = authorization.substring("Basic ".length(), authorization.length());
    String[] data = new String(Base64Utils.decodeFromString(token)).split(":");
    assertEquals("Wrong user from " + token, "test-user", data[0]);
    assertEquals("Wrong password " + token, "test-password", data[1]);
}

From source file:org.kaaproject.kaa.server.control.service.DefaultControlService.java

@Override
public CredentialsDto provisionCredentials(String applicationId, String credentialsBody)
        throws ControlServiceException {
    CredentialsDto credentials = new CredentialsDto(Base64Utils.decodeFromString(credentialsBody),
            CredentialsStatus.AVAILABLE);
    try {/*w  w  w .  j av a2s  .c  om*/
        return this.credentialsServiceLocator.getCredentialsService(applicationId)
                .provideCredentials(credentials);
    } catch (CredentialsServiceException cause) {
        String message = MessageFormat.format("An unexpected exception occured while saving credentials [{0}]",
                credentials);
        LOG.error(message, cause);
        throw new ControlServiceException(cause);
    }
}