Package io.undertow.server.session

Examples of io.undertow.server.session.Session


    @Test
    public void iterator() {
        Sessions<String> sessions = mock(Sessions.class);
        SessionManager manager = mock(SessionManager.class);
        Session session = mock(Session.class);
        String deployment = "deployment";
        String sessionId = "session";

        when(this.sso.getSessions()).thenReturn(sessions);
        when(sessions.getDeployments()).thenReturn(Collections.singleton(deployment));
        when(sessions.getSession(deployment)).thenReturn(sessionId);
        when(this.registry.getSessionManager(deployment)).thenReturn(manager);
        when(manager.getSession(sessionId)).thenReturn(session);
        when(session.getId()).thenReturn(sessionId);

        Iterator<Session> results = this.subject.iterator();

        assertTrue(results.hasNext());
        Session result = results.next();
        assertEquals(session.getId(), result.getId());
        assertFalse(results.hasNext());

        verifyZeroInteractions(this.batch);

        // Validate that returned sessions can be invalidated
        HttpServerExchange exchange = new HttpServerExchange(null);
        Session mutableSession = mock(Session.class);

        when(session.getSessionManager()).thenReturn(manager);
        when(manager.getSession(same(exchange), Matchers.<SessionConfig>any())).thenReturn(mutableSession);

        result.invalidate(exchange);
View Full Code Here


    }

    @Test
    public void contains() {
        String deployment = "deployment";
        Session session = mock(Session.class);
        SessionManager manager = mock(SessionManager.class);
        Sessions<String> sessions = mock(Sessions.class);

        when(session.getSessionManager()).thenReturn(manager);
        when(manager.getDeploymentName()).thenReturn(deployment);
        when(this.sso.getSessions()).thenReturn(sessions);
        when(sessions.getDeployments()).thenReturn(Collections.<String>emptySet());

        boolean result = this.subject.contains(session);
View Full Code Here

    @Test
    public void add() {
        String deployment = "deployment";
        String sessionId = "session";
        Session session = mock(Session.class);
        SessionManager manager = mock(SessionManager.class);
        Sessions<String> sessions = mock(Sessions.class);

        when(session.getId()).thenReturn(sessionId);
        when(session.getSessionManager()).thenReturn(manager);
        when(manager.getDeploymentName()).thenReturn(deployment);
        when(this.sso.getSessions()).thenReturn(sessions);

        this.subject.add(session);
View Full Code Here

    }

    @Test
    public void remove() {
        String deployment = "deployment";
        Session session = mock(Session.class);
        SessionManager manager = mock(SessionManager.class);
        Sessions<String> sessions = mock(Sessions.class);

        when(session.getSessionManager()).thenReturn(manager);
        when(manager.getDeploymentName()).thenReturn(deployment);
        when(this.sso.getSessions()).thenReturn(sessions);

        this.subject.remove(session);
View Full Code Here

    @Test
    public void getSession() {
        String deployment = "deployment";
        String sessionId = "session";
        Session session = mock(Session.class);
        SessionManager manager = mock(SessionManager.class);
        Sessions<String> sessions = mock(Sessions.class);

        when(session.getSessionManager()).thenReturn(manager);
        when(manager.getDeploymentName()).thenReturn(deployment);
        when(this.sso.getSessions()).thenReturn(sessions);
        when(sessions.getSession(deployment)).thenReturn(sessionId);
        when(manager.getSession(sessionId)).thenReturn(session);

        Session result = this.subject.getSession(manager);

        assertSame(session, result);

        verifyZeroInteractions(this.batch);
    }
View Full Code Here

                clearAccount(account);
            }
        }
        if (se.getSession() instanceof HttpSessionImpl) {
            final HttpSessionImpl impl = (HttpSessionImpl) se.getSession();
            Session session;
            if (WildFlySecurityManager.isChecking()) {
                session = WildFlySecurityManager.doChecked(new PrivilegedAction<Session>() {
                    @Override
                    public Session run() {
                        return impl.getSession();
                    }
                });
            } else {
                session = impl.getSession();
            }
            if (session != null) {
                AuthenticatedSessionManager.AuthenticatedSession authenticatedSession = (AuthenticatedSessionManager.AuthenticatedSession) session.getAttribute(CachedAuthenticatedSessionHandler.class.getName() + ".AuthenticatedSession");
                if(authenticatedSession != null) {
                    clearAccount(authenticatedSession.getAccount());
                }
            }
        }
View Full Code Here

    @Override
    protected void storeInitialLocation(final HttpServerExchange exchange) {
        final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
        HttpSessionImpl httpSession = servletRequestContext.getCurrentServletContext().getSession(exchange, true);
        Session session;
        if (System.getSecurityManager() == null) {
            session = httpSession.getSession();
        } else {
            session = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(httpSession));
        }
        session.setAttribute(SESSION_KEY, RedirectBuilder.redirect(exchange, exchange.getRelativePath()));
        SavedRequest.trySaveRequest(exchange);
    }
View Full Code Here

    protected void handleRedirectBack(final HttpServerExchange exchange) {
        final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
        HttpServletResponse resp = (HttpServletResponse) servletRequestContext.getServletResponse();
        HttpSessionImpl httpSession = servletRequestContext.getCurrentServletContext().getSession(exchange, false);
        if (httpSession != null) {
            Session session;
            if (System.getSecurityManager() == null) {
                session = httpSession.getSession();
            } else {
                session = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(httpSession));
            }
            String path = (String) session.getAttribute(SESSION_KEY);
            if (path != null) {
                try {
                    resp.sendRedirect(path);
                } catch (IOException e) {
                    throw new RuntimeException(e);
View Full Code Here

     * @param sessionId The session ID
     * @return The session
     */
    public HttpSessionImpl getSession(final String sessionId) {
        final SessionManager sessionManager = deployment.getSessionManager();
        Session session = sessionManager.getSession(sessionId);
        if (session != null) {
            return SecurityActions.forSession(session, this, false);
        }
        return null;
    }
View Full Code Here

            exchange.removeAttachment(sessionAttachmentKey);
            httpSession = null;
        }
        if (httpSession == null) {
            final SessionManager sessionManager = deployment.getSessionManager();
            Session session = sessionManager.getSession(exchange, c);
            if (session != null) {
                httpSession = SecurityActions.forSession(session, this, false);
                exchange.putAttachment(sessionAttachmentKey, httpSession);
            } else if (create) {
                final Session newSession = sessionManager.createSession(exchange, c);
                httpSession = SecurityActions.forSession(newSession, this, true);
                exchange.putAttachment(sessionAttachmentKey, httpSession);
            }
        }
        return httpSession;
View Full Code Here

TOP

Related Classes of io.undertow.server.session.Session

Copyright © 2018 www.massapicom. 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.