本文整理汇总了Java中org.apache.shiro.session.Session.getId方法的典型用法代码示例。如果您正苦于以下问题:Java Session.getId方法的具体用法?Java Session.getId怎么用?Java Session.getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.session.Session
的用法示例。
在下文中一共展示了Session.getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateSessions
import org.apache.shiro.session.Session; //导入方法依赖的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));
}
}
}
}
}
示例2: doUpdate
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
protected void doUpdate(Session session) {
if (session == null || session.getId() == null) {
return;
}
HttpServletRequest request = Servlets.getRequest();
if (request != null) {
String uri = request.getServletPath();
// 如果是静态文件,则不更新SESSION
if (Servlets.isStaticFile(uri)) {
return;
}
// 如果是视图文件,则不更新SESSION
if (StringUtils.startsWith(uri, Global.getConfig("web.view.prefix")) && StringUtils.endsWith(uri, Global.getConfig("web.view.suffix"))) {
return;
}
// 手动控制不更新SESSION
String updateSession = request.getParameter("updateSession");
if (Global.FALSE.equals(updateSession) || Global.NO.equals(updateSession)) {
return;
}
}
super.doUpdate(session);
logger.debug("update {} {}", session.getId(), request != null ? request.getRequestURI() : "");
}
示例3: delete
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
public void delete(Session session) {
if (session == null || session.getId() == null) {
return;
}
Jedis jedis = null;
try {
jedis = JedisUtils.getResource();
jedis.hdel(JedisUtils.getBytesKey(sessionKeyPrefix), JedisUtils.getBytesKey(session.getId().toString()));
jedis.del(JedisUtils.getBytesKey(sessionKeyPrefix + session.getId()));
logger.debug("delete {} ", session.getId());
} catch (Exception e) {
logger.error("delete {} ", session.getId(), e);
} finally {
JedisUtils.returnResource(jedis);
}
}
示例4: saveSession
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
/**
* save session
* @param session
* @throws UnknownSessionException
*/
private void saveSession(Session session) throws UnknownSessionException{
if(session == null || session.getId() == null){
logger.error("session or session id is null");
return;
}
byte[] key = getByteKey(session.getId());
byte[] value = JavaSerializeUtil.serialize(session);
session.setTimeout(expire*1000);
try {
this.jedisClient.set(key, value, expire);
}catch (Exception e){
e.printStackTrace();
}
}
示例5: saveSession
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
public void saveSession(Session session) {
if (session == null || session.getId() == null)
throw new NullPointerException("session is empty");
try {
byte[] key = generateRedisSessionKey(session.getId()).getBytes();
//不存在才添加。
if(null == session.getAttribute(UserSessionServiceImpl.SESSION_STATUS)){
//session状态
SessionStatus sessionStatus = new SessionStatus();
session.setAttribute(UserSessionServiceImpl.SESSION_STATUS, sessionStatus);
}
byte[] value = SerializeUtil.serialize(session);
long sessionTimeOut = session.getTimeout() / 1000;
Long expireTime = sessionTimeOut + SESSION_VAL_TIME_SPAN + (5 * 60);
getRedisManager().saveValueByKey(DB_INDEX, key, value, expireTime.intValue());
} catch (Exception e) {
logger.error("save session error,id:"+session.getId(), e);
}
}
示例6: delete
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
public void delete(Session session) {
if (session == null || session.getId() == null) {
return;
}
Jedis jedis = null;
try {
jedis = JedisUtils.getResource();
jedis.hdel(JedisUtils.getBytesKey(sessionKeyPrefix), JedisUtils.getBytesKey(session.getId().toString()));
jedis.del(JedisUtils.getBytesKey(sessionKeyPrefix + session.getId()));
logger.debug("delete {} ", session.getId());
} catch (Exception e) {
logger.error("delete {} ", session.getId(), e);
} finally {
JedisUtils.returnResource(jedis);
}
}
示例7: doDelete
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
protected void doDelete(Session session) {
if (session == null || session.getId() == null) {
return;
}
super.doDelete(session);
logger.debug("delete {} ", session.getId());
}
示例8: doCreate
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
protected Serializable doCreate(Session session) {
HttpServletRequest request = Servlets.getRequest();
if (request != null) {
String uri = request.getServletPath();
// 如果是静态文件,则不创建SESSION
if (Servlets.isStaticFile(uri)) {
return null;
}
}
super.doCreate(session);
logger.debug("doCreate {} {}", session, request != null ? request.getRequestURI() : "");
return session.getId();
}
示例9: delete
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
public void delete(Session session) {
if (session != null) {
Serializable id = session.getId();
if (id != null) {
RedisConnection redisConnection = getRedisConnection();
try {
redisConnection.del(buildRedisSessionKey(id));
} finally {
redisConnection.close();
}
}
}
}
示例10: saveSession
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
private void saveSession(Session session) {
if (session == null || session.getId() == null) throw new UnknownSessionException("session is empty");
byte[] sessionKey = buildRedisSessionKey(session.getId());
int sessionTimeOut = PropertiesUtil.getInt("session.maxInactiveInterval", EXPIRE_TIME);
byte[] value = SerializeUtil.serialize(session);
RedisConnection redisConnection = getRedisConnection();
try {
redisConnection.set(sessionKey, value, Expiration.seconds(sessionTimeOut), SetOption.UPSERT);
} finally {
redisConnection.close();
}
}
示例11: delete
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
public void delete(Session session) {
logger.info("delete session "+session.toString());
if(session == null || session.getId() == null){
logger.error("session or session id is null");
return;
}
jedisClient.del(this.getByteKey(session.getId()));
}
示例12: delete
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
public void delete(Session session) {
if (session == null) {
logger.error("Session 不能为null");
return;
}
Serializable id = session.getId();
if (id != null)
shiroSessionRepository.deleteSession(id);
}
示例13: saveSession
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
public void saveSession(Session session) {
if (session == null || session.getId() == null)
throw new NullPointerException("session is empty");
try {
cacheManager.getCache(this.activeSessionsCacheName).put(session.getId(), SerializeUtil.serialize(session));
} catch (Exception e) {
logger.error("save session error,id:"+session.getId(), e);
}
}
示例14: doUpdate
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
protected void doUpdate(Session session) {
if (session == null || session.getId() == null) {
return;
}
HttpServletRequest request = Servlets.getRequest();
if (request != null){
String uri = request.getServletPath();
// 如果是静态文件,则不更新SESSION
if (Servlets.isStaticFile(uri)){
return;
}
// 如果是视图文件,则不更新SESSION
if (StringUtils.startsWith(uri, Global.getInstance().getConfig("app.view.prefix"))
&& StringUtils.endsWith(uri, Global.getInstance().getConfig("app.view.suffix"))){
return;
}
// 手动控制不更新SESSION
String updateSession = request.getParameter("updateSession");
if (Global.FALSE.equals(updateSession) || Global.NO.equals(updateSession)){
return;
}
}
super.doUpdate(session);
logger.debug("update {} {}", session.getId(), request != null ? request.getRequestURI() : "");
}
示例15: doDelete
import org.apache.shiro.session.Session; //导入方法依赖的package包/类
@Override
protected void doDelete(Session session) {
if (session == null || session.getId() == null) {
return;
}
super.doDelete(session);
logger.debug("delete {} ", session.getId());
}