shiro cookie优化,员工授权等其他
This commit is contained in:
@@ -36,8 +36,10 @@ public class AuthRealm extends AuthorizingRealm {
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal) {
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
|
||||
Long userId = (Long) principal.getPrimaryPrincipal();
|
||||
// 获取用户Principal对象
|
||||
User user = (User) principal.getPrimaryPrincipal();
|
||||
User user = userService.getById(userId);
|
||||
|
||||
// 管理员拥有所有权限
|
||||
if(user.getId().equals(AdminConst.ADMIN_ID)){
|
||||
@@ -85,7 +87,7 @@ public class AuthRealm extends AuthorizingRealm {
|
||||
* 参数3:加盐处理
|
||||
* 参数4:固定写法
|
||||
*/
|
||||
return new SimpleAuthenticationInfo(user, user.getPassword(), salt, getName());
|
||||
return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), salt, getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.cwhelp.component.shiro;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
|
||||
/**
|
||||
* @author: yan.y
|
||||
* @Description:
|
||||
* @Date: Created in 0:28 2019/8/5
|
||||
*/
|
||||
public class ICSecurityUtils extends SecurityUtils {
|
||||
}
|
||||
@@ -4,10 +4,13 @@ import com.cwhelp.common.utils.EncryptUtil;
|
||||
import com.cwhelp.common.utils.SpringContextUtil;
|
||||
import com.cwhelp.modules.system.domain.Role;
|
||||
import com.cwhelp.modules.system.domain.User;
|
||||
import com.cwhelp.modules.system.service.UserService;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.SimpleAuthenticationInfo;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.mgt.RememberMeManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -15,8 +18,16 @@ import java.util.Set;
|
||||
* Shiro工具类
|
||||
* @author yan.y
|
||||
*/
|
||||
@Component
|
||||
public class ShiroUtil {
|
||||
|
||||
private static UserService userService;
|
||||
|
||||
@Autowired
|
||||
public void setUserService(UserService userService){
|
||||
ShiroUtil.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密算法
|
||||
*/
|
||||
@@ -49,7 +60,8 @@ public class ShiroUtil {
|
||||
* 获取ShiroUser对象
|
||||
*/
|
||||
public static User getSubject(){
|
||||
return (User) SecurityUtils.getSubject().getPrincipal();
|
||||
Long userId = (Long) SecurityUtils.getSubject().getPrincipal();
|
||||
return userService.getById(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.cwhelp.component.shiro.config;
|
||||
|
||||
import com.cwhelp.modules.system.domain.User;
|
||||
import com.cwhelp.modules.system.service.UserService;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
|
||||
@@ -14,10 +16,15 @@ import java.util.Optional;
|
||||
*/
|
||||
@Configuration
|
||||
public class AuditorConfig implements AuditorAware<User> {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public Optional<User> getCurrentAuditor() {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
User user = (User) subject.getPrincipal();
|
||||
Long userId = (Long) subject.getPrincipal();
|
||||
User user = userService.getById(userId);
|
||||
return Optional.ofNullable(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user