Example usage for org.apache.shiro.session Session stop

List of usage examples for org.apache.shiro.session Session stop

Introduction

In this page you can find the example usage for org.apache.shiro.session Session stop.

Prototype

void stop() throws InvalidSessionException;

Source Link

Document

Explicitly stops (invalidates) this session and releases all associated resources.

Usage

From source file:cn.mario256.blog.filter.AuthenticationFilter.java

License:Open Source License

/**
 * ??//from ww  w  .j  av a2 s  .c o m
 * 
 * @param token
 *            
 * @param subject
 *            Subject
 * @param servletRequest
 *            ServletRequest
 * @param servletResponse
 *            ServletResponse
 * @return ??
 */
@Override
protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject,
        ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
    Session session = subject.getSession();
    Map<Object, Object> attributes = new HashMap<Object, Object>();
    Collection<Object> keys = session.getAttributeKeys();
    for (Object key : keys) {
        attributes.put(key, session.getAttribute(key));
    }
    session.stop();
    session = subject.getSession();
    for (Map.Entry<Object, Object> entry : attributes.entrySet()) {
        session.setAttribute(entry.getKey(), entry.getValue());
    }
    return super.onLoginSuccess(token, subject, servletRequest, servletResponse);
}

From source file:com.app.filter.AuthenticationFilter.java

License:Open Source License

@Override
protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject,
        ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
    Session session = subject.getSession();
    Map<Object, Object> attributes = new HashMap<Object, Object>();
    Collection<Object> keys = session.getAttributeKeys();
    for (Object key : keys) {
        attributes.put(key, session.getAttribute(key));
    }//from   w  ww .j  a  va  2  s . c om
    session.stop();
    session = subject.getSession();
    for (Entry<Object, Object> entry : attributes.entrySet()) {
        session.setAttribute(entry.getKey(), entry.getValue());
    }
    return super.onLoginSuccess(token, subject, servletRequest, servletResponse);
}

From source file:com.bright.amp.authc.service.AuthService.java

@SuppressWarnings("rawtypes")
public void checkOnlineLoginName(String userName) {
    try {/*w ww  . j  av a2 s .com*/
        Collection<Session> sessions = sessionDAO.getActiveSessions();
        Iterator it = sessions.iterator();
        while (it.hasNext()) {
            Session session = (Session) it.next();
            Object userObj = session.getAttribute("userName");
            if (userObj != null && userObj.toString().equals(userName)) {
                String isSameName = "1";
                if ("0".equals(isSameName)) {
                    //?????
                    session.stop();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.caricah.iotracah.bootstrap.security.IOTSecurityManager.java

License:Apache License

protected void stopSession(Subject subject) {
    Session s = subject.getSession(false);
    if (s != null) {
        s.stop();
    }

}

From source file:com.dp2345.filter.AuthenticationFilter.java

License:Open Source License

/**
 * HttpSession?shirosession/*from ww  w. j a va2 s  .co  m*/
 */
@Override
protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject,
        ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
    Session session = subject.getSession();
    Map<Object, Object> attributes = new HashMap<Object, Object>();
    Collection<Object> keys = session.getAttributeKeys();
    for (Object key : keys) {
        attributes.put(key, session.getAttribute(key));
    }
    session.stop();
    session = subject.getSession();
    for (Entry<Object, Object> entry : attributes.entrySet()) {
        session.setAttribute(entry.getKey(), entry.getValue());
    }
    return super.onLoginSuccess(token, subject, servletRequest, servletResponse);
}

From source file:com.iscas.quickframe.config.MySingleSignOutHandler.java

License:Apache License

/**
 * Destroys the current HTTP session for the given CAS logout request.
 *
 * @param request HTTP request containing a CAS logout message.
 *///from   w w w  .  ja  v  a  2s . c o  m
public Session destroySession(final HttpServletRequest request, RedisCacheSessionDao redisCacheSessionDao) {
    Session sessionx = null;
    final String logoutMessage = CommonUtils.safeGetParameter(request, this.logoutParameterName);
    if (log.isTraceEnabled()) {
        log.trace("Logout request:\n" + logoutMessage);
    }

    final String token = XmlUtils.getTextForElement(logoutMessage, "SessionIndex");

    if (CommonUtils.isNotBlank(token)) {
        //           this.sessionMappingStorage.removeRedisSessionByMappingId(token);

        String sessionId = SpringRedisUtil.get(token, String.class);
        if (sessionId != null) {
            SpringRedisUtil.delete(token);
            //sessionx = redisCacheSessionDao.readSession(sessionId);
            sessionx = SpringRedisUtil.get(sessionId, Session.class);
            if (sessionx != null) {
                sessionx.setTimeout(-1);
                sessionx.stop();
            }
            SpringRedisUtil.delete(sessionId);
        }
        final HttpSession session = this.sessionMappingStorage.removeSessionByMappingId(token);

        if (session != null) {
            String sessionID = session.getId();

            if (log.isDebugEnabled()) {
                log.debug("Invalidating session [" + sessionID + "] for token [" + token + "]");
            }
            try {
                session.invalidate();
            } catch (final IllegalStateException e) {
                log.debug("Error invalidating session.", e);
            }
        }
    }
    return sessionx;
}

From source file:com.smilonet.common.zk.UserWorkspace.java

License:Open Source License

@Override
public void destroy() {
    this.grantedPermissionSet = null;
    Session session = getSubject().getSession(false);
    if (session != null) {
        session.stop();
    }// ww w  .ja  v a 2 s.c o  m

    if (log.isDebugEnabled()) {
        log.debug("destroy Workspace [" + this + "]");
    }
}

From source file:com.xc.xnode.shiro.AuthenticationFilter.java

License:Open Source License

@Override
protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject,
        ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
    Session session = subject.getSession();
    Map<Object, Object> attributes = new HashMap<Object, Object>();
    Collection<Object> keys = session.getAttributeKeys();
    for (Object key : keys) {
        attributes.put(key, session.getAttribute(key));
    }//from   w ww. jav a2s . c o m
    session.stop();
    session = subject.getSession();
    for (Entry<Object, Object> entry : attributes.entrySet()) {
        session.setAttribute(entry.getKey(), entry.getValue());
    }
    //      WebUtils.issueRedirect(servletRequest, servletResponse, getSuccessUrl(), null, true);
    //      return false;
    return super.onLoginSuccess(token, subject, servletRequest, servletResponse);
}

From source file:net.felsing.client_cert.Login.java

License:Open Source License

private void cleanUp(Session sessionId) {
    DefaultSecurityManager securityManager = (DefaultSecurityManager) SecurityUtils.getSecurityManager();
    DefaultSessionManager sessionManager = (DefaultSessionManager) securityManager.getSessionManager();
    Collection<Session> activeSessions = sessionManager.getSessionDAO().getActiveSessions();
    for (Session session : activeSessions) {
        if (sessionId.equals(session.getId())) {
            session.stop();
        }/*  ww w.  jav a 2s  .  c  o m*/
    }
}

From source file:net.osxx.filter.AuthenticationFilter.java

License:Open Source License

@Override
protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject,
        ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
    Session session = subject.getSession();
    Map<Object, Object> attributes = new HashMap<Object, Object>();
    Collection<Object> keys = session.getAttributeKeys();
    for (Object key : keys) {
        attributes.put(key, session.getAttribute(key));
    }/*  ww w. ja  va 2s  .c om*/
    session.stop();
    session = subject.getSession();
    for (Entry<Object, Object> entry : attributes.entrySet()) {
        session.setAttribute(entry.getKey(), entry.getValue());
    }
    Principal principal = (Principal) subject.getPrincipal();
    session.setAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME, principal);
    String username = principal.getUsername();
    HttpServletResponse rep = (HttpServletResponse) servletResponse;
    Cookie cookie = new Cookie(Member.USERNAME_COOKIE_NAME, username);
    cookie.setPath("/osxx");
    rep.addCookie(cookie);
    return super.onLoginSuccess(token, subject, servletRequest, servletResponse);
}