SimpleHttpRequest request = new SimpleHttpRequest();
while (true) {
String clientToken = BaseEncoding.base64().encode(clientContext.getToken());
request.addHeader("Authorization", securityPackage + " " + clientToken);
SimpleHttpResponse response = new SimpleHttpResponse();
this.filter.doFilter(request, response, filterChain);
Subject subject = (Subject) request.getSession().getAttribute("javax.security.auth.subject");
authenticated = (subject != null && subject.getPrincipals().size() > 0);
if (authenticated) {
Assertions.assertThat(response.getHeaderNamesSize()).isGreaterThanOrEqualTo(0);
break;
}
assertTrue(response.getHeader("WWW-Authenticate").startsWith(securityPackage + " "));
assertEquals("keep-alive", response.getHeader("Connection"));
assertEquals(2, response.getHeaderNamesSize());
assertEquals(401, response.getStatus());
String continueToken = response.getHeader("WWW-Authenticate").substring(securityPackage.length() + 1);
byte[] continueTokenBytes = BaseEncoding.base64().decode(continueToken);
Assertions.assertThat(continueTokenBytes.length).isGreaterThan(0);
SecBufferDesc continueTokenBuffer = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, continueTokenBytes);
clientContext.initialize(clientContext.getHandle(), continueTokenBuffer, "localhost");
}