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());
}
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");
}
}
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());
}
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");
}
}
Aggregations