|
|
@ -5,6 +5,8 @@ import org.apache.shiro.crypto.SecureRandomNumberGenerator;
|
|
|
|
import org.apache.shiro.mgt.RealmSecurityManager;
|
|
|
|
import org.apache.shiro.mgt.RealmSecurityManager;
|
|
|
|
import org.apache.shiro.session.Session;
|
|
|
|
import org.apache.shiro.session.Session;
|
|
|
|
import org.apache.shiro.subject.Subject;
|
|
|
|
import org.apache.shiro.subject.Subject;
|
|
|
|
|
|
|
|
import org.apache.shiro.subject.PrincipalCollection;
|
|
|
|
|
|
|
|
import org.apache.shiro.subject.SimplePrincipalCollection;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
|
|
import com.ruoyi.framework.shiro.realm.UserRealm;
|
|
|
|
import com.ruoyi.framework.shiro.realm.UserRealm;
|
|
|
@ -35,7 +37,7 @@ public class ShiroUtils
|
|
|
|
public static SysUser getSysUser()
|
|
|
|
public static SysUser getSysUser()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SysUser user = null;
|
|
|
|
SysUser user = null;
|
|
|
|
Object obj = getSession().getAttribute("sysUser");
|
|
|
|
Object obj = getSubjct().getPrincipal();
|
|
|
|
if (StringUtils.isNotNull(obj))
|
|
|
|
if (StringUtils.isNotNull(obj))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
user = new SysUser();
|
|
|
|
user = new SysUser();
|
|
|
@ -46,7 +48,12 @@ public class ShiroUtils
|
|
|
|
|
|
|
|
|
|
|
|
public static void setSysUser(SysUser user)
|
|
|
|
public static void setSysUser(SysUser user)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ShiroUtils.getSession().setAttribute("sysUser", user);
|
|
|
|
Subject subject = getSubjct();
|
|
|
|
|
|
|
|
PrincipalCollection principalCollection = subject.getPrincipals();
|
|
|
|
|
|
|
|
String realmName = principalCollection.getRealmNames().iterator().next();
|
|
|
|
|
|
|
|
PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
|
|
|
|
|
|
|
|
// 重新加载Principal
|
|
|
|
|
|
|
|
subject.runAs(newPrincipalCollection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void clearCachedAuthorizationInfo()
|
|
|
|
public static void clearCachedAuthorizationInfo()
|
|
|
|