BasicAuthCredentials { public String getAuthorizationHeaderValue() { String result = null; if (!StringUtils.isBlank(username) && !StringUtils.isBlank(password)) { String value = username + ":" + password; result = "Basic " + new String(Base64.encodeBase64(value.getBytes())) ; } return result; } BasicAuthCredentials(String username, String password); static BasicAuthCredentials createCredentialsFromHeader(final String authorizationHeader); boolean isValid(); boolean isNull(); String getUsername(); String getPassword(); @Override String toString(); String getAuthorizationHeaderValue();  }
@Test public void testGetAuthorizationHeaderValue() throws Exception { BasicAuthCredentials credentials = new BasicAuthCredentials("john.doe","secret"); assertTrue(credentials.isValid()); BasicAuthCredentials fromAuthValue = BasicAuthCredentials.createCredentialsFromHeader(credentials.getAuthorizationHeaderValue()); assertEquals(credentials.getUsername(), fromAuthValue.getUsername()); assertEquals(credentials.getPassword(), fromAuthValue.getPassword()); }