* @param request
* @param response
* @param uriPrefix
*/
public void execute(HttpServletRequest request, HttpServletResponse response, String uriPrefix) {
UserSession usess = UserSession.getUserSession(request);
UserRequest ureq = null;
try{
//upon creation URL is checked for
ureq = new UserRequest(uriPrefix, request, response);
} catch(NumberFormatException nfe) {
//MODE could not be decoded
//typically if robots with wrong urls hit the system
//or user have bookmarks
//or authors copy-pasted links to the content.
//showing redscreens for non valid URL is wrong instead
//a 404 message must be shown -> e.g. robots correct their links.
if(Tracing.isDebugEnabled(AuthenticatedDispatcher.class)){
Tracing.logDebug("Bad Request "+request.getPathInfo(), this.getClass());
}
DispatcherAction.sendBadRequest(request.getPathInfo(), response);
return;
}
GUIInterna.setLoadPerformanceMode(ureq);
boolean auth = usess.isAuthenticated();
if (!auth) {
if (!ureq.isValidDispatchURI()) {
// might be a direct jump request -> remember it if not logged in yet
String reqUri = request.getRequestURI();
String query = request.getQueryString();
String allGet = reqUri + QUESTIONMARK + query;
usess.putEntryInNonClearedStore(AUTHDISPATCHER_ENTRYURL, allGet);
}
String guestAccess = ureq.getParameter(GUEST);
if (guestAccess == null || !LoginModule.isGuestLoginLinksEnabled()) {
DispatcherAction.redirectToDefaultDispatcher(response);
return;
} else if (guestAccess.equals(TRUE)) {
// try to log in as anonymous
// use the language from the lang paramter if available, otherwhise use the system default locale
String guestLang = ureq.getParameter("lang");
Locale guestLoc;
if (guestLang == null) {
guestLoc = I18nModule.getDefaultLocale();
} else {
guestLoc = I18nManager.getInstance().getLocaleOrDefault(guestLang);
}
int loginStatus = AuthHelper.doAnonymousLogin(ureq, guestLoc);
if ( loginStatus != AuthHelper.LOGIN_OK) {
if (loginStatus == AuthHelper.LOGIN_NOTAVAILABLE) {
DispatcherAction.redirectToServiceNotAvailable(response);
}
DispatcherAction.redirectToDefaultDispatcher(response); // error, redirect to login screen
return;
}
// else now logged in as anonymous user, continue
}
}
// authenticated!
try {
//kill session if not secured via SSL
if (forceSecureAccessOnly && !request.isSecure()) {
SessionInfo sessionInfo = usess.getSessionInfo();
if (sessionInfo!=null) {
HttpSession session = sessionInfo.getSession();
if (session!=null) {
try{
session.invalidate();
} catch(IllegalStateException ise) {
// thrown when session already invalidated. fine. ignore.
}
}
}
DispatcherAction.redirectToDefaultDispatcher(response);
return;
}
SessionInfo sessionInfo = usess.getSessionInfo();
if (sessionInfo==null) {
DispatcherAction.redirectToDefaultDispatcher(response);
return;
}
UserBasedLogLevelManager.activateUsernameBasedLogLevel(sessionInfo.getLogin());
sessionInfo.setLastClickTime();
String origUrl = (String) usess.removeEntryFromNonClearedStore(AUTHDISPATCHER_ENTRYURL);
if (origUrl != null) {
// we had a direct jump request
// to avoid a endless redirect, remove the guest parameter if any
// this can happen if a guest has cookies disabled
String url = new URIHelper(origUrl).removeParameter(GUEST).toString();
DispatcherAction.redirectTo(response, url);
return;
}
String businessPath = (String) usess.removeEntryFromNonClearedStore(AUTHDISPATCHER_BUSINESSPATH);
if (businessPath != null) {
BusinessControl bc = BusinessControlFactory.getInstance().createFromString(businessPath);
ChiefController cc = (ChiefController) Windows.getWindows(usess).getAttribute("AUTHCHIEFCONTROLLER");
WindowControl wControl = cc.getWindowControl();