Search in sources :

Example 6 with Window

use of org.olat.core.gui.components.Window in project OpenOLAT by OpenOLAT.

the class OlatMinimalTopNavController method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (source == closeLink) {
        // close window (a html page which calls Window.close onLoad
        ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(StaticMediaDispatcher.createStaticURIFor("closewindow.html")));
        // release all resources and close window
        WindowBackOffice wbo = getWindowControl().getWindowBackOffice();
        Window w = wbo.getWindow();
        Windows.getWindows(ureq).deregisterWindow(w);
        wbo.dispose();
    }
}
Also used : Window(org.olat.core.gui.components.Window) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) WindowBackOffice(org.olat.core.gui.control.WindowBackOffice)

Example 7 with Window

use of org.olat.core.gui.components.Window in project openolat by klemens.

the class AuthenticatedDispatcher method processBusinessPath.

private void processBusinessPath(String businessPath, UserRequest ureq, UserSession usess) {
    ChiefController chiefController = Windows.getWindows(usess).getChiefController();
    if (chiefController == null) {
        if (usess.isAuthenticated()) {
            AuthHelper.createAuthHome(ureq).getWindow();
            chiefController = Windows.getWindows(usess).getChiefController();
        } else {
            redirectToDefaultDispatcher(ureq.getHttpReq(), ureq.getHttpResp());
            return;
        }
    }
    WindowBackOffice windowBackOffice = chiefController.getWindow().getWindowBackOffice();
    if (chiefController.isLoginInterceptionInProgress()) {
        Window w = windowBackOffice.getWindow();
        // renderOnly
        w.dispatchRequest(ureq, true);
    } else {
        String wSettings = (String) usess.removeEntryFromNonClearedStore(WINDOW_SETTINGS);
        if (wSettings != null) {
            WindowSettings settings = WindowSettings.parse(wSettings);
            windowBackOffice.setWindowSettings(settings);
        }
        try {
            BusinessControl bc = null;
            String historyPointId = ureq.getHttpReq().getParameter("historyPointId");
            if (StringHelper.containsNonWhitespace(historyPointId)) {
                HistoryPoint point = ureq.getUserSession().getHistoryPoint(historyPointId);
                bc = BusinessControlFactory.getInstance().createFromContextEntries(point.getEntries());
            }
            if (bc == null) {
                bc = BusinessControlFactory.getInstance().createFromString(businessPath);
            }
            WindowControl wControl = windowBackOffice.getChiefController().getWindowControl();
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, wControl);
            NewControllerFactory.getInstance().launch(ureq, bwControl);
            // render the window
            Window w = windowBackOffice.getWindow();
            // renderOnly
            w.dispatchRequest(ureq, true);
        } catch (Exception e) {
            // try to render something
            try {
                Window w = windowBackOffice.getWindow();
                // renderOnly
                w.dispatchRequest(ureq, true);
            } catch (Exception e1) {
                redirectToDefaultDispatcher(ureq.getHttpReq(), ureq.getHttpResp());
            }
            log.error("", e);
        }
    }
}
Also used : Window(org.olat.core.gui.components.Window) BusinessControl(org.olat.core.id.context.BusinessControl) WindowBackOffice(org.olat.core.gui.control.WindowBackOffice) ChiefController(org.olat.core.gui.control.ChiefController) WindowControl(org.olat.core.gui.control.WindowControl) HistoryPoint(org.olat.core.id.context.HistoryPoint) IOException(java.io.IOException) InvalidRequestParameterException(org.olat.core.gui.components.form.flexible.impl.InvalidRequestParameterException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WindowSettings(org.olat.core.gui.WindowSettings)

Example 8 with Window

use of org.olat.core.gui.components.Window in project openolat by klemens.

the class AuthenticatedDispatcher method processValidDispatchURI.

private void processValidDispatchURI(UserRequest ureq, UserSession usess, HttpServletRequest request, HttpServletResponse response) {
    Windows ws = Windows.getWindows(ureq);
    Window window = ws.getWindow(ureq);
    if (window == null) {
        // probably a
        if (usess.isSavedSession() && !usess.getHistoryStack().isEmpty()) {
            redirectToDefaultDispatcher(request, response);
        } else {
            DispatcherModule.sendNotFound(request.getRequestURI(), response);
        }
    } else {
        window.dispatchRequest(ureq);
    }
}
Also used : Window(org.olat.core.gui.components.Window) Windows(org.olat.core.gui.Windows)

Example 9 with Window

use of org.olat.core.gui.components.Window in project openolat by klemens.

the class DMZDispatcher method execute.

/**
 * Main method called by OpenOLATServlet. This processess all requests for
 * users who are not authenticated.
 *
 * @param request
 * @param response
 * @param uriPrefix
 */
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
    if (rejectRequest(request, response)) {
        return;
    }
    UserRequest ureq = null;
    String uriPrefix = DispatcherModule.getLegacyUriPrefix(request);
    try {
        // upon creation URL is checked for
        ureq = new UserRequestImpl(uriPrefix, request, response);
    } catch (NumberFormatException nfe) {
        // a 404 message must be shown -> e.g. robots correct their links.
        if (log.isDebug()) {
            log.debug("Bad Request " + request.getPathInfo());
        }
        DispatcherModule.sendBadRequest(request.getPathInfo(), response);
        return;
    }
    try {
        // find out about which subdispatcher is meant
        // e.g. got here because of /dmz/...
        // maybe something like /dmz/registration/
        // 
        // add the context path to align with uriPrefix e.g. /olat/dmz/
        String pathInfo = request.getContextPath() + request.getPathInfo();
        ChiefControllerCreator subPathccc = null;
        // if /olat/dmz/
        boolean dmzOnly = pathInfo.equals(uriPrefix);
        if (!dmzOnly) {
            int sl = pathInfo.indexOf('/', uriPrefix.length());
            String sub;
            if (sl > 1) {
                // e.g. something like /registration/ or /pwchange/
                sub = pathInfo.substring(uriPrefix.length() - 1, sl + 1);
            } else {
                // e.g. something like /info.html from (/dmz/info.html)
                sub = pathInfo;
            }
            // chief controller creator for sub path, e.g.
            subPathccc = dmzServicesByPath.get(sub);
            if (subPathccc != null) {
                UserSession usess = ureq.getUserSession();
                Windows ws = Windows.getWindows(usess);
                synchronized (ws) {
                    // o_clusterOK by:fj per user session
                    ChiefController occ = subPathccc.createChiefController(ureq);
                    Window window = occ.getWindow();
                    window.setUriPrefix(uriPrefix);
                    ws.registerWindow(window);
                    window.dispatchRequest(ureq, true);
                    return;
                }
            }
        }
        // else a /olat/dmz/ request
        UserSession usess = ureq.getUserSession();
        Windows ws = Windows.getWindows(usess);
        // and make it useless under heavily load or 2 concurrent requests
        synchronized (usess) {
            // o_clusterOK by:fj per user session
            Window window;
            boolean windowHere = ws.isExisting(uriPrefix, ureq.getWindowID());
            boolean validDispatchUri = ureq.isValidDispatchURI();
            if (validDispatchUri && !windowHere) {
                // probably valid framework link from previous user && new Session(no window):
                // when a previous user logged off, and 30min later (when the httpsession is invalidated), the next user clicks e.g. on
                // the log-in link in the -same- browser window ->
                // -> there is no window -> create a new one
                window = null;
                CoreSpringFactory.getImpl(UserSessionManager.class).signOffAndClear(usess);
                usess.setLocale(LocaleNegotiator.getPreferedLocale(ureq));
                // update locale infos
                I18nManager.updateLocaleInfoToThread(usess);
                // request new windows since it is a new usersession, the old one was purged
                ws = Windows.getWindows(usess);
            } else if (validDispatchUri) {
                window = ws.getWindow(ureq);
            } else if (dmzOnly) {
                // e.g. /dmz/ -> start screen, clear previous session data
                window = null;
                CoreSpringFactory.getImpl(UserSessionManager.class).signOffAndClear(usess);
                usess.setLocale(LocaleNegotiator.getPreferedLocale(ureq));
                // update locale infos
                I18nManager.updateLocaleInfoToThread(usess);
                OAuthLoginModule oauthModule = CoreSpringFactory.getImpl(OAuthLoginModule.class);
                if (canRedirectConfigurableOAuth(request, response, oauthModule)) {
                    return;
                } else if (canRedirectOAuth(request, oauthModule)) {
                    OAuthSPI oauthSpi = oauthModule.getRootProvider();
                    HttpSession session = request.getSession();
                    OAuthResource.redirect(oauthSpi, response, session);
                    return;
                }
                // request new windows since it is a new usersession, the old one was purged
                ws = Windows.getWindows(usess);
            } else {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST);
                return;
            }
            if (window == null) {
                // no window found, -> start a new WorkFlow/Controller and obtain the window
                // main controller which also implements the windowcontroller for pagestatus and modal dialogs
                Object wSettings = usess.getEntry(WINDOW_SETTINGS);
                ChiefController occ = chiefControllerCreator.createChiefController(ureq);
                window = occ.getWindow();
                window.setUriPrefix(uriPrefix);
                ws.registerWindow(window);
                String businessPath = (String) usess.removeEntryFromNonClearedStore(DMZDISPATCHER_BUSINESSPATH);
                if (businessPath != null) {
                    List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(businessPath);
                    window.getDTabs().activate(ureq, null, ces);
                }
                // apply the settings forward
                usess.putEntryInNonClearedStore(WINDOW_SETTINGS, wSettings);
            }
            window.dispatchRequest(ureq);
        }
    } catch (InvalidRequestParameterException e) {
        try {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        } catch (IOException e1) {
            log.error("An exception occured while handling the invalid request parameter exception...", e1);
        }
    } catch (Throwable th) {
        try {
            ChiefController msgcc = MsgFactory.createMessageChiefController(ureq, th);
            // the controller's window must be failsafe also
            msgcc.getWindow().dispatchRequest(ureq, true);
        // do not dispatch (render only), since this is a new Window created as
        // a result of another window's click.
        } catch (Throwable t) {
            log.error("An exception occured while handling the exception...", t);
        }
    }
}
Also used : Window(org.olat.core.gui.components.Window) OAuthLoginModule(org.olat.login.oauth.OAuthLoginModule) HttpSession(javax.servlet.http.HttpSession) Windows(org.olat.core.gui.Windows) ChiefController(org.olat.core.gui.control.ChiefController) IOException(java.io.IOException) ContextEntry(org.olat.core.id.context.ContextEntry) UserSessionManager(org.olat.core.util.session.UserSessionManager) InvalidRequestParameterException(org.olat.core.gui.components.form.flexible.impl.InvalidRequestParameterException) ChiefControllerCreator(org.olat.core.gui.control.ChiefControllerCreator) UserSession(org.olat.core.util.UserSession) OAuthSPI(org.olat.login.oauth.OAuthSPI) UserRequest(org.olat.core.gui.UserRequest) UserRequestImpl(org.olat.core.gui.UserRequestImpl)

Example 10 with Window

use of org.olat.core.gui.components.Window in project openolat by klemens.

the class RESTDispatcher method getRedirectToURL.

private String getRedirectToURL(UserSession usess) {
    ChiefController cc = Windows.getWindows(usess).getChiefController();
    Window w = cc.getWindow();
    URLBuilder ubu = new URLBuilder(WebappHelper.getServletContextPath() + DispatcherModule.PATH_AUTHENTICATED, w.getInstanceId(), String.valueOf(w.getTimestamp()));
    StringOutput sout = new StringOutput(30);
    ubu.buildURI(sout, null, null);
    return sout.toString();
}
Also used : Window(org.olat.core.gui.components.Window) StringOutput(org.olat.core.gui.render.StringOutput) ChiefController(org.olat.core.gui.control.ChiefController) URLBuilder(org.olat.core.gui.render.URLBuilder)

Aggregations

Window (org.olat.core.gui.components.Window)30 UserSession (org.olat.core.util.UserSession)10 Windows (org.olat.core.gui.Windows)8 ChiefController (org.olat.core.gui.control.ChiefController)8 StringOutput (org.olat.core.gui.render.StringOutput)8 WindowBackOffice (org.olat.core.gui.control.WindowBackOffice)6 RedirectMediaResource (org.olat.core.gui.media.RedirectMediaResource)6 URLBuilder (org.olat.core.gui.render.URLBuilder)6 Identity (org.olat.core.id.Identity)6 BusinessControl (org.olat.core.id.context.BusinessControl)6 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 UserRequest (org.olat.core.gui.UserRequest)4 UserRequestImpl (org.olat.core.gui.UserRequestImpl)4 InvalidRequestParameterException (org.olat.core.gui.components.form.flexible.impl.InvalidRequestParameterException)4 WindowControl (org.olat.core.gui.control.WindowControl)4 ContextEntry (org.olat.core.id.context.ContextEntry)4 UserSessionManager (org.olat.core.util.session.UserSessionManager)4 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2