use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class PaypalMapper method handle.
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
List<ContextEntry> entries = null;
UserSession usess = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(request);
try {
entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath);
if (relPath.indexOf(';') > 0) {
relPath = relPath.substring(0, relPath.indexOf(';'));
}
if (relPath.indexOf('?') > 0) {
relPath = relPath.substring(0, relPath.indexOf('?'));
}
String uuid = relPath.substring(1, relPath.length() - 5);
paypalManager.updateTransaction(uuid);
usess.putEntryInNonClearedStore("paypal-uuid", uuid);
} catch (Exception e) {
log.error("", e);
usess.putEntryInNonClearedStore("paypal-mapper-error", Boolean.TRUE);
}
String resourceUrl = BusinessControlFactory.getInstance().getBusinessPathAsURIFromCEList(entries);
MediaResource redirect = new RedirectMediaResource(Settings.getServerContextPathURI() + "/auth/" + resourceUrl);
return redirect;
}
use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class RestApiLoginFilter method followSession.
private void followSession(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
UserSession uress = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSessionIfAlreadySet(request);
if (uress != null && uress.isAuthenticated()) {
UserRequest ureq = null;
try {
// upon creation URL is checked for
String requestURI = request.getRequestURI();
ureq = new UserRequestImpl(requestURI, request, response);
} catch (NumberFormatException nfe) {
response.sendError(401);
return;
}
request.setAttribute(RestSecurityHelper.SEC_USER_REQUEST, ureq);
synchronized (uress) {
chain.doFilter(request, response);
}
} else {
response.sendError(401);
}
}
use of org.olat.core.util.UserSession 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.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class RestApiLoginFilter method followWithoutAuthentication.
private void followWithoutAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
UserSession uress = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSessionIfAlreadySet(request);
if (uress != null && uress.isAuthenticated()) {
// is authenticated by session cookie, follow its current session
followSession(request, response, chain);
return;
}
String token = request.getHeader(RestSecurityHelper.SEC_TOKEN);
RestSecurityBean securityBean = (RestSecurityBean) CoreSpringFactory.getBean(RestSecurityBean.class);
if (StringHelper.containsNonWhitespace(token) && securityBean.isTokenRegistrated(token, request.getSession(true))) {
// is authenticated by token, follow its current token
followToken(token, request, response, chain);
return;
}
// fxdiff FXOLAT-113: business path in DMZ
UserRequest ureq = null;
try {
// upon creation URL is checked for
String requestURI = request.getRequestURI();
ureq = new UserRequestImpl(requestURI, request, response);
} catch (NumberFormatException nfe) {
response.sendError(401);
return;
}
request.setAttribute(RestSecurityHelper.SEC_USER_REQUEST, ureq);
// no authentication, but no authentication needed, go further
chain.doFilter(request, response);
}
use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class StatusWebservice method getSystemSummaryVO.
/**
* Return the statistics about runtime: uptime, classes loaded, memory
* summary, threads count...
*
* @response.representation.200.qname {http://www.example.com}runtimeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The version of the instance
* @response.representation.200.example {@link org.olat.restapi.system.vo.Examples#SAMPLE_RUNTIMEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param request The HTTP request
* @return The informations about runtime, uptime, classes loaded, memory summary...
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSystemSummaryVO() {
StatusVO stats = new StatusVO();
// File
try {
long startFile = System.nanoTime();
File infoFile = setInfoFiles("ping");
WorkThreadInformations.unset();
stats.setWriteFileInMilliseconds(CodeHelper.nanoToMilliTime(startFile));
stats.setWriteFile(infoFile.exists());
infoFile.delete();
} catch (Exception e) {
stats.setWriteFile(false);
stats.setWriteFileInMilliseconds(-1l);
log.error("", e);
}
// Datebase
try {
stats.setWriteDb(true);
PropertyManager propertyManager = CoreSpringFactory.getImpl(PropertyManager.class);
List<Property> props = propertyManager.findProperties((Identity) null, (BusinessGroup) null, PING_RESOURCE, PING_REF, PING_REF);
if (props != null && props.size() > 0) {
for (Property prop : props) {
propertyManager.deleteProperty(prop);
}
DBFactory.getInstance().commit();
}
long startDB = System.nanoTime();
Property prop = propertyManager.createPropertyInstance(null, null, PING_RESOURCE, PING_REF, PING_REF, 0f, 0l, "-", "-");
DBFactory.getInstance().commit();
stats.setWriteDbInMilliseconds(CodeHelper.nanoToMilliTime(startDB));
propertyManager.deleteProperty(prop);
DBFactory.getInstance().commit();
} catch (Exception e) {
stats.setWriteDb(false);
stats.setWriteDbInMilliseconds(-1l);
log.error("", e);
}
// Secure authenticated user
UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
Set<UserSession> userSessions = sessionManager.getAuthenticatedUserSessions();
int secureAuthenticatedCount = 0;
for (UserSession usess : userSessions) {
SessionInfo sessInfo = usess.getSessionInfo();
if (sessInfo.isWebDAV() || sessInfo.isREST()) {
//
} else if (sessInfo.isSecure()) {
secureAuthenticatedCount++;
}
}
stats.setSecureAuthenticatedCount(secureAuthenticatedCount);
// Concurrent dispatch threads
SessionStatsManager sessionStatsManager = CoreSpringFactory.getImpl(SessionStatsManager.class);
stats.setConcurrentDispatchThreads(sessionStatsManager.getConcurrentCounter());
return Response.ok(stats).build();
}
Aggregations