//获取当前登录用户的用户名
AppSecurityUtils.obtainLoginedUsername()
//获取当前用户token
AppSecurityUtils.obtainAccessToken()
AppSecurityUtils.java
import org.apache.shiro.subject.Subject;
/**
* @author yangty
*
*/
public class AppSecurityUtils {
/**
* 获取当前登录用户的用户名
* @return
*/
public static String obtainLoginedUsername() {
Subject currentUser = org.apache.shiro.SecurityUtils.getSubject();
if(currentUser == null || currentUser.getPrincipal() == null) {
return "";
}
AppShiroUser shiroUser = (AppShiroUser)currentUser.getPrincipal();
return shiroUser.getId();
}
/**
* 获取当前用户token
*
* @return
*/
public static String obtainAccessToken() {
Subject currentUser = org.apache.shiro.SecurityUtils.getSubject();
if(currentUser == null || currentUser.getPrincipal() == null) {
return