本文整理汇总了Java中org.apache.shiro.session.InvalidSessionException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidSessionException类的具体用法?Java InvalidSessionException怎么用?Java InvalidSessionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidSessionException类属于org.apache.shiro.session包,在下文中一共展示了InvalidSessionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSession
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
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;
}
示例2: validateSessions
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
@Override
public void validateSessions() {
Collection<?> activeSessions = getActiveSessions();
if (null != activeSessions && !activeSessions.isEmpty()) {
for (Iterator<?> i$ = activeSessions.iterator(); i$.hasNext();) {
Session session = (Session) i$.next();
try {
SessionKey key = new DefaultSessionKey(session.getId());
validate(session, key);
} catch (InvalidSessionException e) {
if (null != cacheManager) {
SimpleSession s = (SimpleSession) session;
if (null != s.getAttribute(Constant.SESSION_ID))
cacheManager.getCache(null).remove(s.getAttribute(Constant.SESSION_ID));
}
}
}
}
}
示例3: exceptionHandler
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
/**
* 统一异常处理
* @param request
* @param response
* @param exception
*/
@ExceptionHandler
public String exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
_log.error("统一异常处理:", exception);
request.setAttribute("ex", exception);
if (null != request.getHeader("X-Requested-With") && request.getHeader("X-Requested-With").equalsIgnoreCase("XMLHttpRequest")) {
request.setAttribute("requestHeader", "ajax");
}
// shiro没有权限异常
if (exception instanceof UnauthorizedException) {
return "/403.jsp";
}
// shiro会话已过期异常
if (exception instanceof InvalidSessionException) {
return "/error.jsp";
}
return "/error.jsp";
}
示例4: exceptionHandler
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
/**
* 统一异常处理
* @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";
}
示例5: getSession
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
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;
}
示例6: getSession
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
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;
}
示例7: doCreate
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
@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();
}
示例8: update
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
@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) {
}
}
}
示例9: getKeyNames
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
protected Set<String> getKeyNames() {
Collection<Object> keySet;
try {
keySet = getSession().getAttributeKeys();
} catch (InvalidSessionException e) {
throw new IllegalStateException(e);
}
Set<String> keyNames;
if (keySet != null && !keySet.isEmpty()) {
keyNames = new HashSet<String>(keySet.size());
for (Object o : keySet) {
keyNames.add(o.toString());
}
} else {
keyNames = Collections.EMPTY_SET;
}
return keyNames;
}
示例10: resolveSession
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
/**
* Attempts to resolve any associated session based on the context and returns a
* context that represents this resolved {@code Session} to ensure it may be referenced if necessary by the
* invoked {@link SubjectFactory} that performs actual {@link Subject} construction.
* <p/>
* If there is a {@code Session} already in the context because that is what the caller wants to be used for
* {@code Subject} construction, or if no session is resolved, this method effectively does nothing
* returns the context method argument unaltered.
*
* @param context the subject context data that may resolve a Session instance.
* @return The context to use to pass to a {@link SubjectFactory} for subject creation.
* @since 1.0
*/
@SuppressWarnings({"unchecked"})
protected SubjectContext resolveSession(SubjectContext context) {
if (context.resolveSession() != null) {
log.debug("Context already contains a session. Returning.");
return context;
}
try {
//Context couldn't resolve it directly, let's see if we can since we have direct access to
//the session manager:
Session session = resolveContextSession(context);
if (session != null) {
context.setSession(session);
}
} catch (InvalidSessionException e) {
log.debug("Resolved SubjectContext context session is invalid. Ignoring and creating an anonymous " +
"(session-less) Subject instance.", e);
}
return context;
}
示例11: setAttribute
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
@Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException {
try {
super.setAttribute(sessionKey, attributeKey, value);
} catch (UnknownSessionException e) {
Subject subject = ThreadContext.getSubject();
if ((value instanceof PrincipalCollection) && sessionDAO != null && subject != null
&& (subject instanceof DelegatingSubject)) {
try {
SessionContext sessionContext = createSessionContext(((DelegatingSubject) subject).getHost());
Session session = newSessionInstance(sessionContext);
session.setAttribute(attributeKey, value);
session.setTimeout(getGlobalSessionTimeout());
((SimpleSession) session).setId(sessionKey.getSessionId());
sessionDAO.create(session);
} catch (Exception ex) {
throw e;
}
} else {
if (!(value instanceof SavedRequest)) {
throw e;
}
}
}
}
示例12: deleteSession
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
@DELETE
public Response deleteSession() {
// Delete the Shiro session
try {
Session session = SecurityUtils.getSubject().getSession();
Object cookieValue = session.getAttribute(HttpHeaders.SET_COOKIE);
SecurityUtils.getSubject().logout();
if(cookieValue != null) {
NewCookie cookie = NewCookie.valueOf(cookieValue.toString());
if (OBIBA_ID_COOKIE_NAME.equals(cookie.getName())) {
return Response.ok().header(HttpHeaders.SET_COOKIE,
new NewCookie(OBIBA_ID_COOKIE_NAME, null, "/", cookie.getDomain(), "Obiba session deleted", 0, cookie.isSecure())).build();
}
}
} catch(InvalidSessionException e) {
// Ignore
}
return Response.ok().build();
}
示例13: getStartTimestamp
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
public Date getStartTimestamp(SessionKey key) {
try {
return super.getStartTimestamp(key);
} catch (InvalidSessionException e) {
// 获取不到SESSION不抛出异常
return null;
}
}
示例14: getLastAccessTime
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
public Date getLastAccessTime(SessionKey key) {
try {
return super.getLastAccessTime(key);
} catch (InvalidSessionException e) {
// 获取不到SESSION不抛出异常
return null;
}
}
示例15: getTimeout
import org.apache.shiro.session.InvalidSessionException; //导入依赖的package包/类
public long getTimeout(SessionKey key) {
try {
return super.getTimeout(key);
} catch (InvalidSessionException e) {
// 获取不到SESSION不抛出异常
return 0;
}
}