Search in sources :

Example 1 with RestModule

use of org.olat.restapi.RestModule in project OpenOLAT by OpenOLAT.

the class CoreFunctionsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // server informations
    FormLayoutContainer serverCont = FormLayoutContainer.createDefaultFormLayout("functions", getTranslator());
    formLayout.add(serverCont);
    formLayout.add("functions", serverCont);
    MultipleSelectionElement clusterEl = uifactory.addCheckboxesHorizontal("webdav", "core.webdav", serverCont, new String[] { "xx" }, new String[] { "" });
    clusterEl.setEnabled(false);
    clusterEl.select("xx", CoreSpringFactory.getImpl(WebDAVModule.class).isEnabled());
    MultipleSelectionElement jsMathEl = uifactory.addCheckboxesHorizontal("jsmath", "core.jsMath", serverCont, new String[] { "xx" }, new String[] { "" });
    jsMathEl.setEnabled(false);
    jsMathEl.select("xx", Boolean.TRUE);
    MultipleSelectionElement restEl = uifactory.addCheckboxesHorizontal("restapi", "core.restapi", serverCont, new String[] { "xx" }, new String[] { "" });
    restEl.setEnabled(false);
    RestModule restModule = CoreSpringFactory.getImpl(RestModule.class);
    restEl.select("xx", restModule.isEnabled());
}
Also used : RestModule(org.olat.restapi.RestModule) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 2 with RestModule

use of org.olat.restapi.RestModule in project OpenOLAT by OpenOLAT.

the class RestApiLoginFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException {
    if (request instanceof HttpServletRequest) {
        try {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            String requestURI = httpRequest.getRequestURI();
            RestModule restModule = (RestModule) CoreSpringFactory.getBean("restModule");
            if (restModule == null || !restModule.isEnabled() && !isRequestURIAlwaysEnabled(requestURI)) {
                httpResponse.sendError(403);
                return;
            }
            // initialize tracing with request, this allows debugging information as IP, User-Agent.
            Tracing.setUreq(httpRequest);
            I18nManager.attachI18nInfoToThread(httpRequest);
            ThreadLocalUserActivityLoggerInstaller.initUserActivityLogger(httpRequest);
            UserSession uress = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSessionIfAlreadySet(httpRequest);
            if (uress != null && uress.isAuthenticated()) {
                // use the available session
                followSession(httpRequest, httpResponse, chain);
            } else {
                if (isRequestURIInLoginSpace(requestURI)) {
                    followForAuthentication(requestURI, uress, httpRequest, httpResponse, chain);
                } else if (isRequestURIInOpenSpace(requestURI)) {
                    followWithoutAuthentication(httpRequest, httpResponse, chain);
                } else if (isRequestURIInIPProtectedSpace(requestURI, httpRequest, restModule)) {
                    upgradeIpAuthentication(httpRequest, httpResponse);
                    followWithoutAuthentication(httpRequest, httpResponse, chain);
                } else if (isRequestTokenValid(httpRequest)) {
                    String token = httpRequest.getHeader(RestSecurityHelper.SEC_TOKEN);
                    followToken(token, httpRequest, httpResponse, chain);
                } else if (isBasicAuthenticated(httpRequest, httpResponse, requestURI)) {
                    followBasicAuthenticated(request, response, chain);
                } else {
                    httpResponse.setHeader("WWW-Authenticate", "Basic realm=\"" + BASIC_AUTH_REALM + "\"");
                    httpResponse.sendError(401);
                }
            }
        } catch (Exception e) {
            log.error("", e);
            try {
                HttpServletResponse httpResponse = (HttpServletResponse) response;
                httpResponse.sendError(500);
            } catch (Exception ex) {
                log.error("", ex);
            }
        } finally {
            ThreadLocalUserActivityLoggerInstaller.resetUserActivityLogger();
            I18nManager.remove18nInfoFromThread();
            Tracing.setUreq(null);
            DBFactory.getInstance().commitAndCloseSession();
        }
    } else {
        throw new ServletException("Only accept HTTP Request");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RestModule(org.olat.restapi.RestModule) UserSessionManager(org.olat.core.util.session.UserSessionManager) ServletException(javax.servlet.ServletException) UserSession(org.olat.core.util.UserSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with RestModule

use of org.olat.restapi.RestModule in project openolat by klemens.

the class CoreFunctionsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // server informations
    FormLayoutContainer serverCont = FormLayoutContainer.createDefaultFormLayout("functions", getTranslator());
    formLayout.add(serverCont);
    formLayout.add("functions", serverCont);
    MultipleSelectionElement clusterEl = uifactory.addCheckboxesHorizontal("webdav", "core.webdav", serverCont, new String[] { "xx" }, new String[] { "" });
    clusterEl.setEnabled(false);
    clusterEl.select("xx", CoreSpringFactory.getImpl(WebDAVModule.class).isEnabled());
    MultipleSelectionElement jsMathEl = uifactory.addCheckboxesHorizontal("jsmath", "core.jsMath", serverCont, new String[] { "xx" }, new String[] { "" });
    jsMathEl.setEnabled(false);
    jsMathEl.select("xx", Boolean.TRUE);
    MultipleSelectionElement restEl = uifactory.addCheckboxesHorizontal("restapi", "core.restapi", serverCont, new String[] { "xx" }, new String[] { "" });
    restEl.setEnabled(false);
    RestModule restModule = CoreSpringFactory.getImpl(RestModule.class);
    restEl.select("xx", restModule.isEnabled());
}
Also used : RestModule(org.olat.restapi.RestModule) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 4 with RestModule

use of org.olat.restapi.RestModule in project openolat by klemens.

the class RestApiLoginFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException {
    if (request instanceof HttpServletRequest) {
        try {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            String requestURI = httpRequest.getRequestURI();
            RestModule restModule = (RestModule) CoreSpringFactory.getBean("restModule");
            if (restModule == null || !restModule.isEnabled() && !isRequestURIAlwaysEnabled(requestURI)) {
                httpResponse.sendError(403);
                return;
            }
            // initialize tracing with request, this allows debugging information as IP, User-Agent.
            Tracing.setUreq(httpRequest);
            I18nManager.attachI18nInfoToThread(httpRequest);
            ThreadLocalUserActivityLoggerInstaller.initUserActivityLogger(httpRequest);
            UserSession uress = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSessionIfAlreadySet(httpRequest);
            if (uress != null && uress.isAuthenticated()) {
                // use the available session
                followSession(httpRequest, httpResponse, chain);
            } else {
                if (isRequestURIInLoginSpace(requestURI)) {
                    followForAuthentication(requestURI, uress, httpRequest, httpResponse, chain);
                } else if (isRequestURIInOpenSpace(requestURI)) {
                    followWithoutAuthentication(httpRequest, httpResponse, chain);
                } else if (isRequestURIInIPProtectedSpace(requestURI, httpRequest, restModule)) {
                    upgradeIpAuthentication(httpRequest, httpResponse);
                    followWithoutAuthentication(httpRequest, httpResponse, chain);
                } else if (isRequestTokenValid(httpRequest)) {
                    String token = httpRequest.getHeader(RestSecurityHelper.SEC_TOKEN);
                    followToken(token, httpRequest, httpResponse, chain);
                } else if (isBasicAuthenticated(httpRequest, httpResponse, requestURI)) {
                    followBasicAuthenticated(request, response, chain);
                } else {
                    httpResponse.setHeader("WWW-Authenticate", "Basic realm=\"" + BASIC_AUTH_REALM + "\"");
                    httpResponse.sendError(401);
                }
            }
        } catch (Exception e) {
            log.error("", e);
            try {
                HttpServletResponse httpResponse = (HttpServletResponse) response;
                httpResponse.sendError(500);
            } catch (Exception ex) {
                log.error("", ex);
            }
        } finally {
            ThreadLocalUserActivityLoggerInstaller.resetUserActivityLogger();
            I18nManager.remove18nInfoFromThread();
            Tracing.setUreq(null);
            DBFactory.getInstance().commitAndCloseSession();
        }
    } else {
        throw new ServletException("Only accept HTTP Request");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RestModule(org.olat.restapi.RestModule) UserSessionManager(org.olat.core.util.session.UserSessionManager) ServletException(javax.servlet.ServletException) UserSession(org.olat.core.util.UserSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

RestModule (org.olat.restapi.RestModule)4 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 UserSession (org.olat.core.util.UserSession)2 UserSessionManager (org.olat.core.util.session.UserSessionManager)2