SessionUtil.java
957 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.framework.shiro;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import com.agent.entity.system.UserEntity;
/**
* Shiro Session会话工具类
* @author gerry.zhang
* @date 2014-7-7
* @version 1.0
*
*/
public class SessionUtil {
/**
* 根据key获取当前会话值
* @param key
* @return
*/
public static Object getKey(String key){
Subject subject = SecurityUtils.getSubject();
return subject.getSession().getAttribute(key);
}
/**
* Session 中存值
* @param key
* @param value
*/
public static void putKey(String key,Object value) {
Subject subject = SecurityUtils.getSubject();
subject.getSession().setAttribute(key, value);
}
/**
* 获取登录用户
* @return
*/
public static UserEntity getUser() {
Subject subject = SecurityUtils.getSubject();
UserEntity user = (UserEntity) subject.getSession().getAttribute("user");
return user;
}
}