* @param request
* @param response
* @param uriPrefix
*/
public void execute(HttpServletRequest request, HttpServletResponse response, String uriPrefix) {
UserRequest ureq = null;
try {
ureq = new UserRequest(uriPrefix, request, response);
if (! request.getMethod().equals(METHOD_POST)) {
log.warn("Wrong HTTP method, only POST allowed, but current method::" + request.getMethod());
DispatcherAction.redirectToDefaultDispatcher(response);
return;
}
String userName = ureq.getParameter(PARAM_USERNAME);
if (! StringHelper.containsNonWhitespace(userName)) {
log.warn("Missing username parameter, use '" + PARAM_USERNAME + "' to submit the login name");
DispatcherAction.redirectToDefaultDispatcher(response);
return;
}
String pwd = ureq.getParameter(PARAM_PASSWORD);
if ( ! StringHelper.containsNonWhitespace(pwd)) {
log.warn("Missing password parameter, use '" + PARAM_PASSWORD + "' to submit the password");
DispatcherAction.redirectToDefaultDispatcher(response);
return;
}
// Authenticate user
Identity identity = OLATAuthenticationController.authenticate(userName, pwd);
if (identity == null) {
log.info("Could not authenticate user '" + userName + "', wrong password or user name");
// redirect to OLAT loginscreen, add error parameter so that the loginform can mark itself as errorfull
String loginUrl = WebappHelper.getServletContextPath() + DispatcherAction.getPathDefault() + "?" + OLATAuthenticationController.PARAM_LOGINERROR + "=true";
DispatcherAction.redirectTo(response, loginUrl);
return;
}
// Login user, set up everything
int loginStatus = AuthHelper.doLogin(identity, OLATAuthenticationController.PROVIDER_OLAT, ureq);
if (loginStatus == AuthHelper.LOGIN_OK) {
// redirect to authenticated environment
ServletUtil.serveResource(request, response, ureq.getDispatchResult().getResultingMediaResource());
} else if (loginStatus == AuthHelper.LOGIN_NOTAVAILABLE) {
DispatcherAction.redirectToServiceNotAvailable(response);
} else {
// error, redirect to login screen
DispatcherAction.redirectToDefaultDispatcher(response);