Source:
<code>public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; boolean persistentAuth = FiltersHelper.isPersistentAuth(req); if (persistentAuth) { HttpSession session = req.getSession(true); try { int ttlValue = Integer.parseInt(req.getHeader("Session-TTL")) * SECONDS_IN_MINUTE; if (ttlValue >= MINIMAL_SESSION_TTL) { session.setMaxInactiveInterval(ttlValue); } } catch (NumberFormatException ex) { log.error("Session-TTL header was not passed. Not setting TTL value"); } String engineSessionId = (String)req.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY); if (engineSessionId != null) { session.setAttribute( SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY, engineSessionId ); } } chain.doFilter(request, response); try { <START> if (!persistentAuth && FiltersHelper.isAuthenticated(req)) { <END> InitialContext ctx = new InitialContext(); try { FiltersHelper.getBackend(ctx).runAction( VdcActionType.LogoutBySession, new VdcActionParametersBase( (String) req.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY) ) ); req.getSession().invalidate(); } finally { ctx.close(); } } else { HttpSession session = req.getSession(false); if (session != null && session.isNew() && session.getAttribute("async") != null && !Boolean.valueOf((boolean)session.getAttribute("async"))) { ((HttpServletResponse)response).addHeader(FiltersHelper.Constants.JSESSIONID_COOKIE, session.getId()); } } } catch (Exception ex) { log.error("Error in REST-API session management. ", ex); } }</code><technical_language>I I expect here: if (!persistentAuth) { if (FiltersHelper.isAuthenticated(req)) { else apply if persistent auth... no? I switch conditions positive first</technical_language>

Target:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; boolean persistentAuth = FiltersHelper.isPersistentAuth(req); if (persistentAuth) { HttpSession session = req.getSession(true); try { int ttlValue = Integer.parseInt(req.getHeader("Session-TTL")) * SECONDS_IN_MINUTE; if (ttlValue >= MINIMAL_SESSION_TTL) { session.setMaxInactiveInterval(ttlValue); } } catch (NumberFormatException ex) { log.error("Session-TTL header was not passed. Not setting TTL value"); } String engineSessionId = (String)req.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY); if (engineSessionId != null) { session.setAttribute( SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY, engineSessionId ); } else { if (session.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY) != null) request.setAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY, session.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY)); } } chain.doFilter(request, response); try { if (FiltersHelper.isAuthenticated(req)) { if (!persistentAuth) { InitialContext ctx = new InitialContext(); try { FiltersHelper.getBackend(ctx).runAction( VdcActionType.LogoutBySession, new VdcActionParametersBase( (String) req.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY) ) ); req.getSession().invalidate(); } finally { ctx.close(); } } else { HttpSession session = req.getSession(false); if (session != null && session.isNew() && req.getAttribute(FiltersHelper.Constants.REQUEST_ASYNC_KEY) == null || !Boolean.valueOf((boolean) req.getAttribute(FiltersHelper.Constants.REQUEST_ASYNC_KEY))) { ((HttpServletResponse) response).addHeader(FiltersHelper.Constants.HEADER_JSESSIONID_COOKIE, session.getId()); } } } } catch (Exception ex) { log.error("Error in REST-API session management. ", ex); } }