Search in sources :

Example 61 with BusinessControl

use of org.olat.core.id.context.BusinessControl in project OpenOLAT by OpenOLAT.

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 62 with BusinessControl

use of org.olat.core.id.context.BusinessControl in project OpenOLAT by OpenOLAT.

the class RESTDispatcher method execute.

@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
    // 
    // create a ContextEntries String which can be used to create a BusinessControl -> move to
    // 
    String uriPrefix = DispatcherModule.getLegacyUriPrefix(request);
    final String origUri = request.getRequestURI();
    String encodedRestPart = origUri.substring(uriPrefix.length());
    String restPart = encodedRestPart;
    try {
        restPart = URLDecoder.decode(encodedRestPart, "UTF8");
    } catch (UnsupportedEncodingException e) {
        log.error("Unsupported encoding", e);
    }
    String[] split = restPart.split("/");
    if (split.length % 2 != 0) {
        // assert(split.length % 2 == 0);
        // The URL is not a valid business path
        DispatcherModule.sendBadRequest(origUri, response);
        log.warn("URL is not valid: " + restPart);
        return;
    }
    String businessPath = BusinessControlFactory.getInstance().formatFromSplittedURI(split);
    if (log.isDebug()) {
        log.debug("REQUEST URI: " + origUri);
        log.debug("REQUEST PREFIX " + restPart);
        log.debug("calc buspath " + businessPath);
    }
    // check if the businesspath is valid
    try {
        BusinessControl bc = BusinessControlFactory.getInstance().createFromString(businessPath);
        if (!bc.hasContextEntry()) {
            // The URL is not a valid business path
            DispatcherModule.sendBadRequest(origUri, response);
            return;
        }
    } catch (Exception e) {
        DispatcherModule.sendBadRequest(origUri, response);
        log.warn("Error with business path: " + origUri, e);
        return;
    }
    // 
    // create the olat ureq and get an associated main window to spawn the "tab"
    // 
    UserSession usess = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(request);
    if (usess != null) {
        ThreadLocalUserActivityLoggerInstaller.initUserActivityLogger(request);
    }
    UserRequest ureq = null;
    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;
    }
    // XX:GUIInterna.setLoadPerformanceMode(ureq);
    // Do auto-authenticate if url contains a X-OLAT-TOKEN Single-Sign-On REST-Token
    String xOlatToken = ureq.getParameter(RestSecurityHelper.SEC_TOKEN);
    if (xOlatToken != null) {
        // Lookup identity that is associated with this token
        RestSecurityBean securityBean = (RestSecurityBean) CoreSpringFactory.getBean(RestSecurityBean.class);
        Identity restIdentity = securityBean.getIdentity(xOlatToken);
        // 
        if (log.isDebug()) {
            if (restIdentity == null)
                log.debug("Found SSO token " + RestSecurityHelper.SEC_TOKEN + " in url, but token is not bound to an identity");
            else
                log.debug("Found SSO token " + RestSecurityHelper.SEC_TOKEN + " in url which is bound to identity::" + restIdentity.getName());
        }
        // 
        if (restIdentity != null) {
            // after the REST dispatcher finishes. No need to change it here.
            if (!usess.isAuthenticated() || !restIdentity.equalsByPersistableKey(usess.getIdentity())) {
                // Re-authenticate user session for this user and start a fresh
                // standard OLAT session
                int loginStatus = AuthHelper.doLogin(restIdentity, RestSecurityHelper.SEC_TOKEN, ureq);
                if (loginStatus == AuthHelper.LOGIN_OK) {
                    // fxdiff: FXOLAT-268 update last login date and register active user
                    UserDeletionManager.getInstance().setIdentityAsActiv(restIdentity);
                } else {
                    // error, redirect to login screen
                    DispatcherModule.redirectToDefaultDispatcher(response);
                }
            } else if (Windows.getWindows(usess).getChiefController() == null) {
                // Session is already available, but no main window (Head-less REST
                // session). Only create the base chief controller and the window
                Window currentWindow = AuthHelper.createAuthHome(ureq).getWindow();
                // the user is authenticated successfully with a security token, we can set the authenticated path
                currentWindow.setUriPrefix(WebappHelper.getServletContextPath() + DispatcherModule.PATH_AUTHENTICATED);
                Windows ws = Windows.getWindows(ureq);
                ws.registerWindow(currentWindow);
            // no need to call setIdentityAsActive as this was already done by RestApiLoginFilter...
            }
        }
    }
    boolean auth = usess.isAuthenticated();
    if (auth) {
        if (Windows.getWindows(usess).getChiefController() == null) {
            // Session is already available, but no main window (Head-less REST
            // session). Only create the base chief controller and the window
            setBusinessPathInUserSession(usess, businessPath, ureq.getParameter(WINDOW_SETTINGS));
            AuthHelper.createAuthHome(ureq);
            String url = getRedirectToURL(usess) + ";jsessionid=" + usess.getSessionInfo().getSession().getId();
            DispatcherModule.redirectTo(response, url);
        } else {
            // redirect to the authenticated dispatcher which support REST url
            String url = WebappHelper.getServletContextPath() + DispatcherModule.PATH_AUTHENTICATED + encodedRestPart;
            DispatcherModule.redirectTo(response, url);
        }
    } else {
        // prepare for redirect
        LoginModule loginModule = CoreSpringFactory.getImpl(LoginModule.class);
        setBusinessPathInUserSession(usess, businessPath, ureq.getParameter(WINDOW_SETTINGS));
        String invitationAccess = ureq.getParameter(AuthenticatedDispatcher.INVITATION);
        if (invitationAccess != null && loginModule.isInvitationEnabled()) {
            // try to log in as anonymous
            // use the language from the lang paramter if available, otherwhise use the system default locale
            Locale guestLoc = getLang(ureq);
            int loginStatus = AuthHelper.doInvitationLogin(invitationAccess, ureq, guestLoc);
            if (loginStatus == AuthHelper.LOGIN_OK) {
                Identity invite = usess.getIdentity();
                // fxdiff: FXOLAT-268 update last login date and register active user
                UserDeletionManager.getInstance().setIdentityAsActiv(invite);
                // logged in as invited user, continue
                String url = getRedirectToURL(usess);
                DispatcherModule.redirectTo(response, url);
            } else if (loginStatus == AuthHelper.LOGIN_NOTAVAILABLE) {
                DispatcherModule.redirectToServiceNotAvailable(response);
            } else {
                // error, redirect to login screen
                DispatcherModule.redirectToDefaultDispatcher(response);
            }
        } else {
            String guestAccess = ureq.getParameter(AuthenticatedDispatcher.GUEST);
            if (guestAccess == null || !loginModule.isGuestLoginLinksEnabled()) {
                DispatcherModule.redirectToDefaultDispatcher(response);
                return;
            } else if (guestAccess.equals(AuthenticatedDispatcher.TRUE)) {
                // try to log in as anonymous
                // use the language from the lang paramter if available, otherwhise use the system default locale
                Locale guestLoc = getLang(ureq);
                int loginStatus = AuthHelper.doAnonymousLogin(ureq, guestLoc);
                if (loginStatus == AuthHelper.LOGIN_OK) {
                    // logged in as anonymous user, continue
                    String url = getRedirectToURL(usess);
                    DispatcherModule.redirectTo(response, url);
                } else if (loginStatus == AuthHelper.LOGIN_NOTAVAILABLE) {
                    DispatcherModule.redirectToServiceNotAvailable(response);
                } else {
                    // error, redirect to login screen
                    DispatcherModule.redirectToDefaultDispatcher(response);
                }
            }
        }
    }
}
Also used : Window(org.olat.core.gui.components.Window) Locale(java.util.Locale) BusinessControl(org.olat.core.id.context.BusinessControl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LoginModule(org.olat.login.LoginModule) Windows(org.olat.core.gui.Windows) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UserSessionManager(org.olat.core.util.session.UserSessionManager) UserSession(org.olat.core.util.UserSession) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) UserRequestImpl(org.olat.core.gui.UserRequestImpl) RestSecurityBean(org.olat.restapi.security.RestSecurityBean)

Example 63 with BusinessControl

use of org.olat.core.id.context.BusinessControl in project OpenOLAT by OpenOLAT.

the class StudentCoursesController method openHome.

private void openHome(UserRequest ureq) {
    List<ContextEntry> ces = new ArrayList<ContextEntry>(4);
    ces.add(BusinessControlFactory.getInstance().createContextEntry(student));
    BusinessControl bc = BusinessControlFactory.getInstance().createFromContextEntries(ces);
    WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, getWindowControl());
    NewControllerFactory.getInstance().launch(ureq, bwControl);
}
Also used : BusinessControl(org.olat.core.id.context.BusinessControl) ArrayList(java.util.ArrayList) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 64 with BusinessControl

use of org.olat.core.id.context.BusinessControl in project openolat by klemens.

the class SearchUserTool method getMenuComponent.

@Override
public Component getMenuComponent(UserRequest ureq, VelocityContainer container) {
    if (searchC == null) {
        String resourceUrl = null;
        BusinessControl bc = wControl.getBusinessControl();
        if (bc != null) {
            resourceUrl = bc.getAsString();
        }
        searchC = new SearchInputController(ureq, wControl, resourceUrl, DisplayOption.STANDARD);
        searchC.setResourceContextEnable(false);
        searchC.setAssessmentListener(ureq);
    }
    String componentName = "search-menu-" + CodeHelper.getRAMUniqueID();
    String velocity_root = Util.getPackageVelocityRoot(SearchControllerFactory.class);
    String pagePath = velocity_root + "/search_tool.html";
    VelocityContainer search = new VelocityContainer(componentName, pagePath, container.getTranslator(), this);
    search.setDomReplacementWrapperRequired(false);
    search.put("search_input", searchC.getInitialComponent());
    container.put(componentName, search);
    return search;
}
Also used : SearchInputController(org.olat.search.ui.SearchInputController) BusinessControl(org.olat.core.id.context.BusinessControl) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 65 with BusinessControl

use of org.olat.core.id.context.BusinessControl in project openolat by klemens.

the class EventsModel method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component,
 *      org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source == showAllLink) {
        // activate homes tab in top navigation and active calendar menu item
        String resourceUrl = "[HomeSite:" + ureq.getIdentity().getKey() + "][calendar:0]";
        BusinessControl bc = BusinessControlFactory.getInstance().createFromString(resourceUrl);
        WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, getWindowControl());
        NewControllerFactory.getInstance().launch(ureq, bwControl);
    } else if (event == ComponentUtil.VALIDATE_EVENT && dirty) {
        List<KalendarEvent> events = getMatchingEvents(ureq, getWindowControl());
        tableController.setTableDataModel(new EventsModel(events));
    }
}
Also used : BusinessControl(org.olat.core.id.context.BusinessControl) ArrayList(java.util.ArrayList) List(java.util.List) WindowControl(org.olat.core.gui.control.WindowControl)

Aggregations

BusinessControl (org.olat.core.id.context.BusinessControl)80 WindowControl (org.olat.core.gui.control.WindowControl)56 OLATResourceable (org.olat.core.id.OLATResourceable)24 ContextEntry (org.olat.core.id.context.ContextEntry)22 RepositoryEntry (org.olat.repository.RepositoryEntry)16 ArrayList (java.util.ArrayList)14 Controller (org.olat.core.gui.control.Controller)8 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)6 Window (org.olat.core.gui.components.Window)6 HistoryPoint (org.olat.core.id.context.HistoryPoint)6 CourseNode (org.olat.course.nodes.CourseNode)6 Date (java.util.Date)4 UserRequest (org.olat.core.gui.UserRequest)4 DTab (org.olat.core.gui.control.generic.dtabs.DTab)4 DTabs (org.olat.core.gui.control.generic.dtabs.DTabs)4 Identity (org.olat.core.id.Identity)4 Roles (org.olat.core.id.Roles)4 BusinessControlFactory (org.olat.core.id.context.BusinessControlFactory)4 NodeRunConstructionResult (org.olat.course.run.navigation.NodeRunConstructionResult)4 IOException (java.io.IOException)3