sendWwwAuthenticateResponse(response);
return;
}
NtlmUserAccount ntlmUserAccount = null;
try {
log.debug("Try authenticating user now...");
ntlmUserAccount = ntlmManager.authenticate(
src, serverChallenge);
log.info("Authentication was successful. Creating session.");
session = request.getSession(true);
session.setAttribute(NTLM_USER_ACCOUNT, ntlmUserAccount);
} catch (Exception e) {
log.error("NTLM authentication failed: " + e, e);
} finally {
synchronized(cache) {
cache.remove(request.getRemoteAddr());
}
}
if (ntlmUserAccount == null) {
// No NTLM user in session yet, or authentication failed
sendWwwAuthenticateResponse(response);
return;
}
if (log.isDebugEnabled()) {
log.debug("NTLM remote user " + ntlmUserAccount.getUserName());
}
}
// Check if NTLM user account has already been stored in session
NtlmUserAccount ntlmUserAccount = null;
if (session != null) {
ntlmUserAccount = (NtlmUserAccount)session.getAttribute(
NTLM_USER_ACCOUNT);
}
HttpServletRequest filteredReq = request;
if (ntlmUserAccount == null) {
log.debug("No NTLM user set yet, begin authentication...");
sendWwwAuthenticateResponse(response);
return;
}
log.debug("NTLM user in session: " + ntlmUserAccount.getUserName());
if(!(request instanceof NtlmV2HttpRequestWrapper)) {
// Wrap original request only once
filteredReq = new NtlmV2HttpRequestWrapper(request, ntlmUserAccount.getUserName());
}
filterChain.doFilter(filteredReq, res);
}