Examples of SessionInformation


Examples of org.springframework.security.core.session.SessionInformation

    public void testObject() throws Exception {
        Object principal = "Some principal object";
        String sessionId = "1234567890";
        Date currentDate = new Date();

        SessionInformation info = new SessionInformation(principal, sessionId, currentDate);
        assertEquals(principal, info.getPrincipal());
        assertEquals(sessionId, info.getSessionId());
        assertEquals(currentDate, info.getLastRequest());

        Thread.sleep(10);

        info.refreshLastRequest();

        assertTrue(info.getLastRequest().after(currentDate));
    }
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

    @Before
    public void setup() throws Exception {
        authentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        sessionInformation = new SessionInformation(authentication.getPrincipal(), "unique", new Date(1374766134216L));

        strategy = new ConcurrentSessionControlAuthenticationStrategy(sessionRegistry);
    }
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

        assertThat(sessionInformation.isExpired()).isTrue();
    }

    @Test
    public void maxSessionsExpireLeastRecentExistingUser() {
        SessionInformation moreRecentSessionInfo = new SessionInformation(authentication.getPrincipal(), "unique", new Date(1374766999999L));
        when(sessionRegistry.getAllSessions(any(), anyBoolean())).thenReturn(Arrays.<SessionInformation>asList(moreRecentSessionInfo,sessionInformation));
        strategy.setMaximumSessions(2);

        strategy.onAuthentication(authentication, request, response);
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

        List<SessionInformation> sessions = new ArrayList<SessionInformation>();
        if (principal instanceof User) {
            Set<String> sessionIds = (Set<String>) client.get(((User) principal).getUuid());
            if (sessionIds != null) {
                for (String id : sessionIds) {
                    SessionInformation info = (SessionInformation) client.get(id);
                    if (info != null) {
                        sessions.add(info);
                    } else {
                        removeSessionInformation(id);
                    }
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

    @Override
    public void refreshLastRequest(String sessionId) {
        Assert.hasText(sessionId, "SessionId required as per interface contract");

        SessionInformation info = getSessionInformation(sessionId);

        if (info != null) {
            info.refreshLastRequest();
            client.replace(sessionId, 86400, info);
        }
    }
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

        if (getSessionInformation(sessionId) != null) {
            removeSessionInformation(sessionId);
        }

        client.set(sessionId, 86400, new SessionInformation(principal, sessionId, new Date()));

        Set<String> sessionsUsedByPrincipal = (Set<String>) client.get(((User) principal).getUuid());

        if (sessionsUsedByPrincipal == null) {
            sessionsUsedByPrincipal = new CopyOnWriteArraySet<String>();
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

    @Override
    public void removeSessionInformation(String sessionId) {
        Assert.hasText(sessionId, "SessionId required as per interface contract");

        SessionInformation info = getSessionInformation(sessionId);

        if (info == null) {
            return;
        }

        if (log.isTraceEnabled()) {
            log.debug("Removing session " + sessionId + " from set of registered sessions");
        }

        if (!isSuccess(client.delete(sessionId))) {
            log.error(String.format("Error removing session from cache: %s", sessionId));
        }

        Set<String> sessionsUsedByPrincipal = (Set<String>) client.get(((User) info.getPrincipal()).getUuid());

        if (sessionsUsedByPrincipal == null) {
            return;
        }

        if (log.isDebugEnabled()) {
            log.debug("Removing session " + sessionId + " from principal's set of registered sessions");
        }

        sessionsUsedByPrincipal.remove(sessionId);

        if (sessionsUsedByPrincipal.isEmpty()) {
            // No need to keep object in principals Map anymore
            if (log.isDebugEnabled()) {
                log.debug("Removing principal " + info.getPrincipal() + " from registry");
            }
            client.delete(((User) info.getPrincipal()).getUuid());
        } else {
            client.replace(((User) info.getPrincipal()).getUuid(), 86400, sessionsUsedByPrincipal);
        }

        if (log.isTraceEnabled()) {
            log.trace("Sessions used by '" + info.getPrincipal() + "' : " + sessionsUsedByPrincipal);
        }
    }
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

        HttpServletResponse response = (HttpServletResponse) res;

        HttpSession session = request.getSession(false);

        if (session != null) {
            SessionInformation info = sessionRegistry.getSessionInformation(session.getId());

            if (info != null) {
                if (info.isExpired()) {
                    // Expired - abort processing
                    doLogout(request, response);

                    String targetUrl = determineExpiredUrl(request, info);

                    if (targetUrl != null) {
                        redirectStrategy.sendRedirect(request, response, targetUrl);

                        return;
                    } else {
                        response.getWriter().print("This session has been expired (possibly due to multiple concurrent " +
                                "logins being attempted as the same user).");
                        response.flushBuffer();
                    }

                    return;
                } else {
                    // Non-expired - update last request date/time
                    info.refreshLastRequest();
                }
            }
        }

        chain.doFilter(request, response);
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

                    new Object[] {new Integer(allowableSessions)},
                    "Maximum sessions of {0} for this principal exceeded"));
        }

        // Determine least recently used session, and mark it for invalidation
        SessionInformation leastRecentlyUsed = null;

        for (int i = 0; i < sessions.size(); i++) {
            if ((leastRecentlyUsed == null)
                    || sessions.get(i).getLastRequest().before(leastRecentlyUsed.getLastRequest())) {
                leastRecentlyUsed = sessions.get(i);
            }
        }

        leastRecentlyUsed.expireNow();
    }
View Full Code Here

Examples of org.springframework.security.core.session.SessionInformation

        try {
        HttpServletRequest request=(HttpServletRequest)req;
            HttpServletResponse response=(HttpServletResponse)res;
            HttpSession session=request.getSession(false);
            if(session!=null){
                SessionInformation info=sessionRegistry.getSessionInformation(session.getId());
                if(info!=null){
                    if(info.isExpired()){
                        doLogout(request,response);
                        if(invalidSessionHandler!=null)
                            invalidSessionHandler.sessionInvalidated(request,response);
                        else{
                            response.getWriter().print("This session has been expired (possibly due to multiple concurrent " +
                                      "logins being attempted as the same user).");
                            response.flushBuffer();
                        }
                        return;
                    }else{
                        info.refreshLastRequest();
                    }
                }
            }
          chain.doFilter(request,response);   
    } catch (AccessDeniedException ex) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.