clientContext.setCredentialsHandle(clientCredentials.getHandle());
clientContext.setSecurityPackage(securityPackage);
clientContext.initialize(null, null, WindowsAccountImpl.getCurrentUsername());
// negotiate
boolean authenticated = false;
final SimpleHttpRequest request = new SimpleHttpRequest();
while (true) {
final String clientToken = BaseEncoding.base64().encode(clientContext.getToken());
request.addHeader("Authorization", securityPackage + " " + clientToken);
final SimpleHttpResponse response = new SimpleHttpResponse();
authenticated = this.authenticator.authenticate(request, response, null);
if (authenticated) {
Assert.assertNotNull(request.getUserPrincipal());
Assert.assertTrue(request.getUserPrincipal() instanceof GenericWindowsPrincipal);
final GenericWindowsPrincipal windowsPrincipal = (GenericWindowsPrincipal) request
.getUserPrincipal();
Assert.assertTrue(windowsPrincipal.getSidString().startsWith("S-"));
Assertions.assertThat(windowsPrincipal.getSid().length).isGreaterThan(0);
Assert.assertTrue(windowsPrincipal.getGroups().containsKey("Everyone"));
Assertions.assertThat(response.getHeaderNames().length).isLessThanOrEqualTo(1);