mirror of https://gitee.com/y_project/RuoYi.git
系统用户会话命名sysUser
parent
6244e6bf18
commit
d870710af1
|
@ -27,7 +27,7 @@ public class SysIndexController extends BaseController
|
|||
public String index(ModelMap mmap)
|
||||
{
|
||||
// 取身份信息
|
||||
SysUser user = getUser();
|
||||
SysUser user = getSysUser();
|
||||
// 根据用户id取出菜单
|
||||
List<SysMenu> menus = menuService.selectMenusByUser(user);
|
||||
mmap.put("menus", menus);
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.base.AjaxResult;
|
||||
import com.ruoyi.common.config.Global;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.framework.shiro.service.PasswordService;
|
||||
import com.ruoyi.framework.shiro.service.SysPasswordService;
|
||||
import com.ruoyi.framework.util.FileUploadUtils;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
|
@ -42,7 +42,7 @@ public class SysProfileController extends BaseController
|
|||
private ISysUserService userService;
|
||||
|
||||
@Autowired
|
||||
private PasswordService passwordService;
|
||||
private SysPasswordService passwordService;
|
||||
|
||||
@Autowired
|
||||
private ISysDictDataService dictDataService;
|
||||
|
@ -53,7 +53,7 @@ public class SysProfileController extends BaseController
|
|||
@GetMapping()
|
||||
public String profile(ModelMap mmap)
|
||||
{
|
||||
SysUser user = getUser();
|
||||
SysUser user = getSysUser();
|
||||
user.setSex(dictDataService.selectDictLabel("sys_user_sex", user.getSex()));
|
||||
mmap.put("user", user);
|
||||
mmap.put("roleGroup", userService.selectUserRoleGroup(user.getUserId()));
|
||||
|
@ -65,7 +65,7 @@ public class SysProfileController extends BaseController
|
|||
@ResponseBody
|
||||
public boolean checkPassword(String password)
|
||||
{
|
||||
SysUser user = getUser();
|
||||
SysUser user = getSysUser();
|
||||
String encrypt = new Md5Hash(user.getLoginName() + password + user.getSalt()).toHex().toString();
|
||||
if (user.getPassword().equals(encrypt))
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ public class SysProfileController extends BaseController
|
|||
int rows = userService.resetUserPwd(user);
|
||||
if (rows > 0)
|
||||
{
|
||||
setUser(userService.selectUserById(user.getUserId()));
|
||||
setSysUser(userService.selectUserById(user.getUserId()));
|
||||
return success();
|
||||
}
|
||||
return error();
|
||||
|
@ -127,7 +127,7 @@ public class SysProfileController extends BaseController
|
|||
{
|
||||
if (userService.updateUserInfo(user) > 0)
|
||||
{
|
||||
setUser(userService.selectUserById(user.getUserId()));
|
||||
setSysUser(userService.selectUserById(user.getUserId()));
|
||||
return success();
|
||||
}
|
||||
return error();
|
||||
|
@ -149,7 +149,7 @@ public class SysProfileController extends BaseController
|
|||
user.setAvatar(avatar);
|
||||
if (userService.updateUserInfo(user) > 0)
|
||||
{
|
||||
setUser(userService.selectUserById(user.getUserId()));
|
||||
setSysUser(userService.selectUserById(user.getUserId()));
|
||||
return success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.ruoyi.common.base.AjaxResult;
|
|||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.ExcelUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.shiro.service.PasswordService;
|
||||
import com.ruoyi.framework.shiro.service.SysPasswordService;
|
||||
import com.ruoyi.framework.util.ShiroUtils;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
|
@ -46,7 +46,7 @@ public class SysUserController extends BaseController
|
|||
private ISysPostService postService;
|
||||
|
||||
@Autowired
|
||||
private PasswordService passwordService;
|
||||
private SysPasswordService passwordService;
|
||||
|
||||
@RequiresPermissions("system:user:view")
|
||||
@GetMapping()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue