Java Code Examples for org.apache.shiro.session.InvalidSessionException

The following examples show how to use org.apache.shiro.session.InvalidSessionException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: scaffold-cloud   Source File: UserUtil.java    License: MIT License 6 votes vote down vote up
public static Session getSession(){
    try{
        SecurityManager securityManager = ThreadContext.getSecurityManager();
        if(securityManager == null){
            return null;
        }

        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession(false);
        if (session == null){
            session = subject.getSession();
        }
        if (session != null){
            return session;
        }
    }catch (InvalidSessionException e){

    }
    return null;
}
 
Example 2
Source Project: super-cloudops   Source File: IamSecurityHolder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Bind key-values map to session
 *
 * @param sessionKey
 * @param keyValues
 */
public static void bindKVParameters(String sessionKey, Object... keyValues) throws InvalidSessionException {
	hasTextOf(sessionKey, "sessionKey");
	notEmptyOf(keyValues, "keyValues");
	isTrueOf(keyValues.length % 2 == 0, "Illegal 'keyValues' length");

	// Extract key values
	Map<Object, Object> parameters = new HashMap<>();
	for (int i = 0; i < keyValues.length - 1; i++) {
		if (i % 2 == 0) {
			Object key = keyValues[i];
			Object value = keyValues[i + 1];
			if (!isNull(key) && isNotBlank(key.toString()) && !isNull(value) && isNotBlank(value.toString())) {
				parameters.put(key, value);
			}
		}
	}

	// Binding
	bind(sessionKey, parameters);
}
 
Example 3
Source Project: easyweb   Source File: UserUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Session getSession(){
        try{
            Subject subject = SecurityUtils.getSubject();
            Session session = subject.getSession(false);
            if (session == null){
                session = subject.getSession();
            }
            if (session != null){
                return session;
            }
//			subject.logout();
        }catch (InvalidSessionException e){

        }
        return null;
    }
 
Example 4
Source Project: Shop-for-JavaWeb   Source File: UserUtils.java    License: MIT License 6 votes vote down vote up
public static Session getSession(){
		try{
			Subject subject = SecurityUtils.getSubject();
			Session session = subject.getSession(false);
			if (session == null){
				session = subject.getSession();
			}
			if (session != null){
				return session;
			}
//			subject.logout();
		}catch (InvalidSessionException e){
			
		}
		return null;
	}
 
Example 5
Source Project: zheng   Source File: BaseController.java    License: MIT License 6 votes vote down vote up
/**
 * 统一异常处理
 * @param request
 * @param response
 * @param exception
 */
@ExceptionHandler
public String exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
	LOGGER.error("统一异常处理:", exception);
	request.setAttribute("ex", exception);
	if (null != request.getHeader("X-Requested-With") && "XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"))) {
		request.setAttribute("requestHeader", "ajax");
	}
	// shiro没有权限异常
	if (exception instanceof UnauthorizedException) {
		return "/403.jsp";
	}
	// shiro会话已过期异常
	if (exception instanceof InvalidSessionException) {
		return "/error.jsp";
	}
	return "/error.jsp";
}
 
Example 6
Source Project: phone   Source File: ShiroSessionDAO.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Serializable doCreate(Session session) {
	logger.trace("shiro create session start");
	super.doCreate(session);
	//先本地缓存,再存redis
	RedisClientSupport jedis = SpringBeanUtil.getRedisClientSupport();
	if (jedis != null) {
		Serializable sessionId = generateSessionId(session);
		logger.trace("cache by jedis,and sessionId is {}",sessionId);
		assignSessionId(session, sessionId);
		String key = RedisKeyConfig.getShiroSessionCacheKey(sessionId);
		String value = SerializableUtils.serialize(session);
		try {
			jedis.putValue(key, value,session.getTimeout()/1000,TimeUnit.SECONDS);
		} catch (InvalidSessionException | CacheAccessException e) {
		}
	}
	return session.getId();
}
 
Example 7
Source Project: phone   Source File: ShiroSessionDAO.java    License: Apache License 2.0 6 votes vote down vote up
@Override
	public void update(Session session) {
		if (session instanceof ValidatingSession && !((ValidatingSession) session).isValid()) {
			return; // 如果会话过期/停止 没必要再更新了
		}
		super.update(session);
		RedisClientSupport jedis = SpringBeanUtil.getRedisClientSupport();
		if (jedis != null) {
			String key = RedisKeyConfig.getShiroSessionCacheKey(session.getId());
//			String value = JSON.toJSONString(session);
			String value = SerializableUtils.serialize(session);
			try {
				jedis.putValue(key, value,session.getTimeout()/1000,TimeUnit.SECONDS);
			} catch (InvalidSessionException | CacheAccessException e) {
			}
		}
	}
 
Example 8
Source Project: supplierShop   Source File: OnlineWebSessionManager.java    License: MIT License 5 votes vote down vote up
@Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException
{
    super.setAttribute(sessionKey, attributeKey, value);
    if (value != null && needMarkAttributeChanged(attributeKey))
    {
        OnlineSession session = getOnlineSession(sessionKey);
        session.markAttributeChanged();
    }
}
 
Example 9
Source Project: supplierShop   Source File: OnlineWebSessionManager.java    License: MIT License 5 votes vote down vote up
@Override
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
{
    Object removed = super.removeAttribute(sessionKey, attributeKey);
    if (removed != null)
    {
        OnlineSession s = getOnlineSession(sessionKey);
        s.markAttributeChanged();
    }

    return removed;
}
 
Example 10
Source Project: ruoyiplus   Source File: OnlineWebSessionManager.java    License: MIT License 5 votes vote down vote up
@Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException
{
    super.setAttribute(sessionKey, attributeKey, value);
    if (value != null && needMarkAttributeChanged(attributeKey))
    {
        OnlineSession s = (OnlineSession) doGetSession(sessionKey);
        s.markAttributeChanged();
    }
}
 
Example 11
Source Project: ruoyiplus   Source File: OnlineWebSessionManager.java    License: MIT License 5 votes vote down vote up
@Override
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
{
    Object removed = super.removeAttribute(sessionKey, attributeKey);
    if (removed != null)
    {
        OnlineSession s = (OnlineSession) doGetSession(sessionKey);
        s.markAttributeChanged();
    }

    return removed;
}
 
Example 12
Source Project: super-cloudops   Source File: IamSession.java    License: Apache License 2.0 5 votes vote down vote up
@JsonIgnore
@Override
public Collection<Object> getAttributeKeys() throws InvalidSessionException {
	Map<Object, Object> attributes = getAttributes();
	if (isNull(attributes)) {
		return emptySet();
	}
	return attributes.keySet();
}
 
Example 13
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public Date getStartTimestamp(SessionKey key) {
	try {
		return super.getStartTimestamp(key);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
		return null;
	}
}
 
Example 14
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public Date getLastAccessTime(SessionKey key) {
	try {
		return super.getLastAccessTime(key);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
		return null;
	}
}
 
Example 15
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public long getTimeout(SessionKey key) {
	try {
		return super.getTimeout(key);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
		return 0;
	}
}
 
Example 16
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public void setTimeout(SessionKey key, long maxIdleTimeInMillis) {
	try {
		super.setTimeout(key, maxIdleTimeInMillis);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
	}
}
 
Example 17
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public void touch(SessionKey key) {
	try {
		super.touch(key);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
	}
}
 
Example 18
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public String getHost(SessionKey key) {
	try {
		return super.getHost(key);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
		return null;
	}
}
 
Example 19
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public Collection<Object> getAttributeKeys(SessionKey key) {
	try {
		return super.getAttributeKeys(key);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
		return null;
	}
}
 
Example 20
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public Object getAttribute(SessionKey sessionKey, Object attributeKey) {
	try {
		return super.getAttribute(sessionKey, attributeKey);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
		return null;
	}
}
 
Example 21
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) {
	try {
		super.setAttribute(sessionKey, attributeKey, value);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
	}
}
 
Example 22
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) {
	try {
		return super.removeAttribute(sessionKey, attributeKey);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
		return null;
	}
}
 
Example 23
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public void checkValid(SessionKey key) {
	try {
		super.checkValid(key);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
	}
}
 
Example 24
Source Project: super-cloudops   Source File: AbstractIamSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
public void stop(SessionKey key) {
	try {
		super.stop(key);
	} catch (InvalidSessionException e) {
		// Ignore exceptions
	}
}
 
Example 25
Source Project: super-cloudops   Source File: IamSecurityHolder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets bind of session value
 *
 * @param sessionKey
 *            Keys to save and session
 * @param unbind
 *            Whether to UN-bundle
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T getBindValue(Object sessionKey, boolean unbind) throws InvalidSessionException {
	notNullOf(sessionKey, "sessionKey");
	try {
		return (T) getSession().getAttribute(sessionKey);
	} finally {
		if (unbind) {
			unbind(sessionKey);
		}
	}
}
 
Example 26
Source Project: super-cloudops   Source File: IamSecurityHolder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Bind value to session
 *
 * @param sessionKey
 * @param value
 */
public static <T> T bind(Object sessionKey, T value) throws InvalidSessionException {
	notNullOf(sessionKey, "sessionKey");
	if (!isNull(value)) {
		getSession().setAttribute(sessionKey, value);
	}
	return value;
}
 
Example 27
Source Project: es   Source File: OnlineWebSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException {
    super.setAttribute(sessionKey, attributeKey, value);
    if (value != null && needMarkAttributeChanged(attributeKey)) {
        OnlineSession s = (OnlineSession) doGetSession(sessionKey);
        s.markAttributeChanged();
    }
}
 
Example 28
@Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException
{
    super.setAttribute(sessionKey, attributeKey, value);
    if (value != null && needMarkAttributeChanged(attributeKey))
    {
        OnlineSession s = (OnlineSession) doGetSession(sessionKey);
        s.markAttributeChanged();
    }
}
 
Example 29
@Override
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
{
    Object removed = super.removeAttribute(sessionKey, attributeKey);
    if (removed != null)
    {
        OnlineSession s = (OnlineSession) doGetSession(sessionKey);
        s.markAttributeChanged();
    }

    return removed;
}
 
Example 30
Source Project: mysiteforme   Source File: SessionUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static Session getSession(){
    try{
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession(false);
        if (session == null){
            session = subject.getSession();
        }
        if (session != null){
            return session;
        }
    }catch (InvalidSessionException e){

    }
    return null;
}