@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
// look for existing valid session
final AuthenticationSession existingAuthSession = authenticationSessionStrategy.lookupValid(request, response);
if (existingAuthSession != null) {
redirectToStartPage(response, existingAuthSession.getUserName());
return;
}
// prompt
final String user = request.getParameter("username");
final String password = request.getParameter("password");
if (user == null && !getDeploymentType().isExploring()) {
renderPrompt(response, "", "", null);
return;
}
// authenticate; re-prompt if required
final AuthenticationSession authSession = authenticate(user, password);
if (authSession == null) {
renderPrompt(response, user, password, "user/password invalid");
return;
}
// authenticated
authenticationSessionStrategy.bind(request, response, authSession);
final Context context = new Context(getHtmlComponentFactory());
context.setSession(authSession);
authSession.setAttribute(HtmlServletConstants.AUTHENTICATION_SESSION_CONTEXT_KEY, context);
LOG.info("created session");
redirectToStartPage(response, user);
}