public void testImpersonateEnabled() throws IOException, ServletException {
assertFalse("Current user shouldn't be the test user prior to the test",
Advapi32Util.getUserName().equals(MockWindowsAccount.TEST_USER_NAME));
final SimpleHttpRequest request = new SimpleHttpRequest();
request.setMethod("GET");
final String userHeaderValue = MockWindowsAccount.TEST_USER_NAME + ":" + MockWindowsAccount.TEST_PASSWORD;
final String basicAuthHeader = "Basic "
+ BaseEncoding.base64().encode(userHeaderValue.getBytes(Charsets.UTF_8));
request.addHeader("Authorization", basicAuthHeader);
final SimpleHttpResponse response = new SimpleHttpResponse();
final RecordUserNameFilterChain filterChain = new RecordUserNameFilterChain();
AutoDisposableWindowsPrincipal windowsPrincipal = null;
try {
this.filter.setImpersonate(true);
this.filter.doFilter(request, response, filterChain);
final Subject subject = (Subject) request.getSession().getAttribute("javax.security.auth.subject");
final boolean authenticated = (subject != null && subject.getPrincipals().size() > 0);
assertTrue("Test user should be authenticated", authenticated);
if (subject == null) {
return;