系统用户会话命名sysUser
This commit is contained in:
@ -19,7 +19,7 @@ import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.ruoyi.framework.shiro.service.LoginService;
|
||||
import com.ruoyi.framework.shiro.service.SysLoginService;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.framework.web.exception.user.CaptchaException;
|
||||
import com.ruoyi.framework.web.exception.user.RoleBlockedException;
|
||||
@ -47,7 +47,7 @@ public class UserRealm extends AuthorizingRealm
|
||||
private ISysRoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private LoginService loginService;
|
||||
private SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 授权
|
||||
@ -127,7 +127,8 @@ public class UserRealm extends AuthorizingRealm
|
||||
log.info("对用户[" + username + "]进行登录验证..验证未通过{}", e.getMessage());
|
||||
throw new AuthenticationException(e.getMessage(), e);
|
||||
}
|
||||
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, password, getName());
|
||||
ShiroUtils.getSession().setAttribute("sysUser", user);
|
||||
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getLoginName(), password, getName());
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,10 @@ import com.ruoyi.system.service.ISysUserService;
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class LoginService
|
||||
public class SysLoginService
|
||||
{
|
||||
@Autowired
|
||||
private PasswordService passwordService;
|
||||
private SysPasswordService passwordService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
@ -22,7 +22,7 @@ import com.ruoyi.system.domain.SysUser;
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class PasswordService
|
||||
public class SysPasswordService
|
||||
{
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
@ -84,7 +84,7 @@ public class PasswordService
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println(new PasswordService().encryptPassword("admin", "admin123", "111111"));
|
||||
System.out.println(new PasswordService().encryptPassword("ry", "admin123", "222222"));
|
||||
System.out.println(new SysPasswordService().encryptPassword("admin", "admin123", "111111"));
|
||||
System.out.println(new SysPasswordService().encryptPassword("ry", "admin123", "222222"));
|
||||
}
|
||||
}
|
@ -4,8 +4,6 @@ import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
|
||||
import org.apache.shiro.mgt.RealmSecurityManager;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.bean.BeanUtils;
|
||||
@ -37,7 +35,7 @@ public class ShiroUtils
|
||||
public static SysUser getUser()
|
||||
{
|
||||
SysUser user = null;
|
||||
Object obj = getSubjct().getPrincipal();
|
||||
Object obj = getSession().getAttribute("sysUser");
|
||||
if (StringUtils.isNotNull(obj))
|
||||
{
|
||||
user = new SysUser();
|
||||
@ -46,14 +44,9 @@ public class ShiroUtils
|
||||
return user;
|
||||
}
|
||||
|
||||
public static void setUser(SysUser user)
|
||||
public static void setSysUser(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);
|
||||
ShiroUtils.getSession().setAttribute("sysUser", user);
|
||||
}
|
||||
|
||||
public static void clearCachedAuthorizationInfo()
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.ruoyi.framework.web.base;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.base.AjaxResult;
|
||||
@ -10,11 +15,6 @@ import com.ruoyi.framework.web.page.PageDomain;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.framework.web.page.TableSupport;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* web层通用数据处理
|
||||
@ -127,23 +127,23 @@ public class BaseController
|
||||
return StringUtils.format("redirect:{}", url);
|
||||
}
|
||||
|
||||
public SysUser getUser()
|
||||
public SysUser getSysUser()
|
||||
{
|
||||
return ShiroUtils.getUser();
|
||||
return (SysUser) ShiroUtils.getSession().getAttribute("sysUser");
|
||||
}
|
||||
|
||||
public void setUser(SysUser user)
|
||||
public void setSysUser(SysUser user)
|
||||
{
|
||||
ShiroUtils.setUser(user);
|
||||
ShiroUtils.setSysUser(user);
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return getUser().getUserId();
|
||||
return getSysUser().getUserId();
|
||||
}
|
||||
|
||||
public String getLoginName()
|
||||
{
|
||||
return getUser().getLoginName();
|
||||
return getSysUser().getLoginName();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user