HttpBasicAuthenticationHandler extends AbstractHttpAuthenticationHandler { @Override public Credentials parseCredentials(final HttpServletRequest request) { final String header = getAuthzHeader(request); if (!isLoginAttempt(request)) { throw new IllegalArgumentException("Request does not contain any credentials"); } final String authorization = header.substring(6).trim(); final String decoded = new String(Base64.decodeBase64(authorization.getBytes())); final String[] credentialString = decoded.split(":"); return new Credentials(credentialString[0], credentialString[1]); } HttpBasicAuthenticationHandler();  HttpBasicAuthenticationHandler(final String realm); @Override String getAuthScheme(); @Override Credentials parseCredentials(final HttpServletRequest request); @Override String getRealm();  }
@Test public void testParseCredentials() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final HttpBasicAuthenticationHandler handler = new HttpBasicAuthenticationHandler(); Credentials credentials; try { handler.parseCredentials(request); fail("Should cause IllegalArgumentException"); } catch (IllegalArgumentException iae) { } final String credentialString = "uid:pwd"; request.addHeader(AbstractHttpAuthenticationHandler.AUTHORIZATION_HEADER, "Basic " + new String(Base64.encodeBase64(credentialString.getBytes()))); credentials = handler.parseCredentials(request); assertFalse(credentials.isEmpty()); assertEquals("uid", credentials.getUserName()); assertEquals("pwd", credentials.getPassword()); }