Example usage for org.apache.commons.codec.binary Base64 isArrayByteBase64

List of usage examples for org.apache.commons.codec.binary Base64 isArrayByteBase64

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 isArrayByteBase64.

Prototype

@Deprecated
public static boolean isArrayByteBase64(final byte[] arrayOctet) 

Source Link

Document

Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.

Usage

From source file:org.sonar.api.config.AesCipherTest.java

@Test
public void encrypt() throws Exception {
    Settings settings = new Settings();
    settings.setProperty(CoreProperties.ENCRYPTION_SECRET_KEY_PATH, pathToSecretKey());
    AesCipher cipher = new AesCipher(settings);

    String encryptedText = cipher.encrypt("this is a secret");

    assertThat(StringUtils.isNotBlank(encryptedText), is(true));
    assertThat(Base64.isArrayByteBase64(encryptedText.getBytes()), is(true));
}

From source file:org.sonar.application.AesCipherTest.java

@Test
public void generateRandomSecretKey() {
    AesCipher cipher = new AesCipher(null);

    String key = cipher.generateRandomSecretKey();

    assertThat(StringUtils.isNotBlank(key)).isTrue();
    assertThat(Base64.isArrayByteBase64(key.getBytes())).isTrue();
}

From source file:org.sonar.application.AesCipherTest.java

@Test
public void encrypt() throws Exception {
    AesCipher cipher = new AesCipher(pathToSecretKey());

    String encryptedText = cipher.encrypt("this is a secret");

    assertThat(StringUtils.isNotBlank(encryptedText)).isTrue();
    assertThat(Base64.isArrayByteBase64(encryptedText.getBytes())).isTrue();
}

From source file:org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServicesTests.java

@Test
public void loginSuccessNormalWithNonUserDetailsBasedPrincipalSetsExpectedCookie() {
    // SEC-822/*from www  .j  a v a  2 s .  c  o  m*/
    services.setTokenValiditySeconds(500000000);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(TokenBasedRememberMeServices.DEFAULT_PARAMETER, "true");

    MockHttpServletResponse response = new MockHttpServletResponse();
    services.loginSuccess(request, response, new TestingAuthenticationToken("someone", "password", "ROLE_ABC"));

    Cookie cookie = response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
    String expiryTime = services.decodeCookie(cookie.getValue())[1];
    long expectedExpiryTime = 1000L * 500000000;
    expectedExpiryTime += System.currentTimeMillis();
    assertThat(Long.parseLong(expiryTime) > expectedExpiryTime - 10000).isTrue();
    assertThat(cookie).isNotNull();
    assertThat(cookie.getMaxAge()).isEqualTo(services.getTokenValiditySeconds());
    assertThat(Base64.isArrayByteBase64(cookie.getValue().getBytes())).isTrue();
    assertThat(new Date().before(new Date(determineExpiryTimeFromBased64EncodedToken(cookie.getValue()))))
            .isTrue();
}

From source file:org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServicesTests.java

@Test
public void loginSuccessNormalWithUserDetailsBasedPrincipalSetsExpectedCookie() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(TokenBasedRememberMeServices.DEFAULT_PARAMETER, "true");

    MockHttpServletResponse response = new MockHttpServletResponse();
    services.loginSuccess(request, response, new TestingAuthenticationToken("someone", "password", "ROLE_ABC"));

    Cookie cookie = response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
    assertThat(cookie).isNotNull();//from   w  w  w. ja  va2s.com
    assertThat(cookie.getMaxAge()).isEqualTo(services.getTokenValiditySeconds());
    assertThat(Base64.isArrayByteBase64(cookie.getValue().getBytes())).isTrue();
    assertThat(new Date().before(new Date(determineExpiryTimeFromBased64EncodedToken(cookie.getValue()))))
            .isTrue();
}

From source file:org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServicesTests.java

@Test
public void negativeValidityPeriodIsSetOnCookieButExpiryTimeRemainsAtTwoWeeks() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(DEFAULT_PARAMETER, "true");

    MockHttpServletResponse response = new MockHttpServletResponse();
    services.setTokenValiditySeconds(-1);
    services.loginSuccess(request, response, new TestingAuthenticationToken("someone", "password", "ROLE_ABC"));

    Cookie cookie = response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
    assertThat(cookie).isNotNull();//  www.  j  a va2  s.  c  o  m
    // Check the expiry time is within 50ms of two weeks from current time
    assertThat(determineExpiryTimeFromBased64EncodedToken(cookie.getValue())
            - System.currentTimeMillis() > TWO_WEEKS_S - 50).isTrue();
    assertThat(cookie.getMaxAge()).isEqualTo(-1);
    assertThat(Base64.isArrayByteBase64(cookie.getValue().getBytes())).isTrue();
}

From source file:org.springframework.security.web.authentication.www.DigestAuthenticationEntryPointTests.java

private void checkNonceValid(String nonce) {
    // Check the nonce seems to be generated correctly
    // format of nonce is:
    // base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key))
    assertThat(Base64.isArrayByteBase64(nonce.getBytes())).isTrue();

    String decodedNonce = new String(Base64.decodeBase64(nonce.getBytes()));
    String[] nonceTokens = StringUtils.delimitedListToStringArray(decodedNonce, ":");
    assertThat(nonceTokens).hasSize(2);/*  w  w  w .  j  ava2s .co  m*/

    String expectedNonceSignature = DigestUtils.md5Hex(nonceTokens[0] + ":" + "key");
    assertThat(nonceTokens[1]).isEqualTo(expectedNonceSignature);
}