use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class RestFileDownloadController method getSession.
protected UserSession getSession(HttpServletRequest request, HttpServletResponse response) {
UUID sessionId;
try {
sessionId = UUID.fromString(request.getParameter("s"));
} catch (Exception e) {
return null;
}
AppContext.setSecurityContext(new SecurityContext(sessionId));
try {
UserSession userSession = userSessionService.getUserSession(sessionId);
return userSession;
} catch (NoUserSessionException e) {
return null;
} finally {
AppContext.setSecurityContext(null);
}
}
use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class PortalExceptionResolver method resolveException.
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
if (ex instanceof NoUserSessionException) {
log.warn(ex.getMessage());
HttpSession httpSession = request.getSession();
httpSession.invalidate();
if (StringUtils.isNotEmpty(noUserSessionUrl))
return new ModelAndView("redirect:" + noUserSessionUrl);
else
return new ModelAndView("redirect:/");
} else if (ex instanceof NoMiddlewareConnectionException) {
log.error(ex.getMessage());
HttpSession httpSession = request.getSession();
httpSession.invalidate();
if (StringUtils.isNotEmpty(noMiddlewareConnectionUrl))
return new ModelAndView(noMiddlewareConnectionUrl);
else
return new ModelAndView("/");
} else {
log.error(ExceptionUtils.getStackTrace(ex));
}
return null;
}
use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class DynamicAttributesCacheStrategy method init.
@Override
public void init() {
clientCacheManager.getExecutorService().scheduleWithFixedDelay(() -> {
if (needToValidateCache) {
UserSession userSession = cacheUserSessionProvider.getUserSession();
if (userSession == null) {
// cache user session unavailable
return;
}
try {
AppContext.setSecurityContext(new SecurityContext(userSession));
loadObject();
} catch (NoUserSessionException e) {
log.warn("Cache user session expired", e);
} catch (Exception e) {
log.error("Unable to update dynamic attributes cache", e);
}
}
}, 0, 10, TimeUnit.SECONDS);
}
use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class DesktopTimer method handleTimerException.
protected void handleTimerException(RuntimeException ex) {
if (ExceptionUtils.indexOfType(ex, java.net.ConnectException.class) > -1) {
// If a ConnectException occurred, just log it and ignore
log.warn("onTimer error: " + ex.getMessage());
} else {
// Otherwise throw the exception, but first search for NoUserSessionException in chain,
// if found - stop the timer
int reIdx = ExceptionUtils.indexOfType(ex, RemoteException.class);
if (reIdx > -1) {
RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(ex).get(reIdx);
for (RemoteException.Cause cause : re.getCauses()) {
// noinspection ThrowableResultOfMethodCallIgnored
if (cause.getThrowable() instanceof NoUserSessionException) {
log.warn("NoUserSessionException in timer, timer will be stopped");
disposeTimer();
break;
}
}
} else if (ExceptionUtils.indexOfThrowable(ex, NoUserSessionException.class) > -1) {
log.warn("NoUserSessionException in timer, timer will be stopped");
disposeTimer();
}
throw ex;
}
}
use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class ServiceInterceptor method aroundInvoke.
private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
SecurityContext securityContext = AppContext.getSecurityContextNN();
boolean internalInvocation = securityContext.incServiceInvocation() > 0;
try {
if (internalInvocation) {
if (logInternalServiceInvocation) {
log.warn("Invoking '{}' from another service", ctx.getSignature());
}
ValidateServiceMethodContext validatedContext = getValidateServiceMethodContext(ctx);
validateMethodParameters(ctx, validatedContext);
Object res = ctx.proceed();
validateMethodResult(ctx, validatedContext, res);
return res;
} else {
statisticsAccumulator.incMiddlewareRequestsCount();
try {
// Using UserSessionsAPI directly to make sure the session's "last used" timestamp is propagated to the cluster
UserSession userSession = userSessions.getAndRefresh(securityContext.getSessionId(), true);
if (userSession == null) {
throw new NoUserSessionException(securityContext.getSessionId());
}
ValidateServiceMethodContext validatedContext = getValidateServiceMethodContext(ctx);
validateMethodParameters(ctx, validatedContext);
boolean checkTransactionOnExit = Stores.getAdditional().isEmpty() && !persistence.isInTransaction();
log.trace("Invoking: {}, session={}", ctx.getSignature(), userSession);
Object res = ctx.proceed();
validateMethodResult(ctx, validatedContext, res);
if (checkTransactionOnExit && persistence.isInTransaction()) {
log.warn("Open transaction left in {}", ctx.getSignature().toShortString());
}
return res;
} catch (Throwable e) {
logException(e, ctx);
// Propagate the special exception to avoid serialization errors on remote clients
throw new RemoteException(e);
}
}
} finally {
securityContext.decServiceInvocation();
}
}
Aggregations