use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class IdpSessionPingConnector method pingIdpSessionServer.
public void pingIdpSessionServer(String idpSessionId) {
log.debug("Ping IDP session {}", idpSessionId);
String idpBaseURL = webIdpConfig.getIdpBaseURL();
if (!idpBaseURL.endsWith("/")) {
idpBaseURL += "/";
}
String idpSessionPingUrl = idpBaseURL + "service/ping";
HttpPost httpPost = new HttpPost(idpSessionPingUrl);
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("idpSessionId", idpSessionId), new BasicNameValuePair("trustedServicePassword", webIdpConfig.getIdpTrustedServicePassword())), StandardCharsets.UTF_8);
httpPost.setEntity(formEntity);
HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
HttpClient client = HttpClientBuilder.create().setConnectionManager(connectionManager).build();
try {
HttpResponse httpResponse = client.execute(httpPost);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == 410) {
// we have to logout user
log.debug("IDP session is expired {}", idpSessionId);
if (userSessionSource.checkCurrentUserSession()) {
authenticationService.logout();
UserSession userSession = userSessionSource.getUserSession();
throw new NoUserSessionException(userSession.getId());
}
}
if (statusCode != 200) {
log.warn("IDP respond status {} on session ping", statusCode);
}
} catch (IOException e) {
log.warn("Unable to ping IDP {} session {}", idpSessionPingUrl, idpSessionId, e);
} finally {
connectionManager.shutdown();
}
}
use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class CubaTimer method handleOnTimerException.
protected void handleOnTimerException(RuntimeException e) {
int reIdx = ExceptionUtils.indexOfType(e, RemoteException.class);
if (reIdx > -1) {
RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(e).get(reIdx);
for (RemoteException.Cause cause : re.getCauses()) {
// noinspection ThrowableResultOfMethodCallIgnored
if (cause.getThrowable() instanceof NoUserSessionException) {
log.warn("NoUserSessionException in timer {}, timer will be stopped", getLoggingTimerId());
stop();
break;
}
}
} else if (ExceptionUtils.indexOfThrowable(e, NoUserSessionException.class) > -1) {
log.warn("NoUserSessionException in timer {}, timer will be stopped", getLoggingTimerId());
stop();
}
throw e;
}
use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class FileDownloadController method getSession.
protected UserSession getSession(HttpServletRequest request, HttpServletResponse response) throws IOException {
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 NoUserSessionHandler method doHandle.
@Override
protected void doHandle(App app, String className, String message, @Nullable Throwable throwable) {
try {
// we may show two or more dialogs if user pressed F5 and we have no valid user session
// just remove previous dialog and show new
List<Window> noUserSessionDialogs = app.getAppUI().getWindows().stream().filter(w -> w instanceof NoUserSessionExceptionDialog).collect(Collectors.toList());
for (Window dialog : noUserSessionDialogs) {
app.getAppUI().removeWindow(dialog);
}
showNoUserSessionDialog(app);
} catch (Throwable th) {
log.error("Unable to handle NoUserSessionException", throwable);
log.error("Exception in NoUserSessionHandler", th);
}
}
use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.
the class SecurityContextHandlerInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// filter resource requests
if (ClassUtils.isAssignableValue(ResourceHttpRequestHandler.class, handler)) {
return true;
}
PortalSecurityContext portalSecurityContext;
HttpSession httpSession = request.getSession();
Connection connection = (Connection) httpSession.getAttribute(Connection.NAME);
if (connection == null || connection.getSession() == null || !connection.isConnected()) {
connection = AppBeans.get(Connection.NAME);
connection.login(request.getLocale(), request.getRemoteAddr(), request.getHeader("User-Agent"));
httpSession.setAttribute(Connection.NAME, connection);
portalSecurityContext = new PortalSecurityContext(connection.getSession());
AppContext.setSecurityContext(portalSecurityContext);
} else {
PortalSession session = connection.getSession();
portalSecurityContext = new PortalSecurityContext(session);
AppContext.setSecurityContext(portalSecurityContext);
// ping only authenticated sessions
if (session != null && session.isAuthenticated()) {
UserSessionService userSessionSource = AppBeans.get(UserSessionService.NAME);
try {
userSessionSource.getMessages();
} catch (NoUserSessionException e) {
httpSession.invalidate();
response.sendRedirect(request.getRequestURI());
return false;
}
}
}
App app = new App(connection, request, response);
portalSecurityContext.setPortalApp(app);
return true;
}
Aggregations