Pu Zhibing
3 天以前 25cf266e99714ac5d428e66b40ce272325c91dd8
ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/core/shiro/factory/ShiroFactroy.java
@@ -6,7 +6,9 @@
import com.stylefeng.guns.core.util.Convert;
import com.stylefeng.guns.core.util.SpringContextHolder;
import com.stylefeng.guns.modular.system.dao.MenuMapper;
import com.stylefeng.guns.modular.system.dao.RoleMapper;
import com.stylefeng.guns.modular.system.dao.UserMapper;
import com.stylefeng.guns.modular.system.model.Role;
import com.stylefeng.guns.modular.system.model.User;
import org.apache.shiro.authc.CredentialsException;
import org.apache.shiro.authc.LockedAccountException;
@@ -25,22 +27,25 @@
@DependsOn("springContextHolder")
@Transactional(readOnly = true)
public class ShiroFactroy implements IShiro {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private RoleMapper roleMapper;
    public static IShiro me() {
        return SpringContextHolder.getBean(IShiro.class);
    }
    @Override
    public User user(String account) {
        User user = userMapper.getByAccount(account);
        // 账号不存在
        if (null == user) {
            throw new CredentialsException();
@@ -55,13 +60,15 @@
    @Override
    public ShiroUser shiroUser(User user) {
        ShiroUser shiroUser = new ShiroUser();
        shiroUser.setId(user.getId());
        shiroUser.setAccount(user.getAccount());
        shiroUser.setDeptId(user.getDeptid());
        shiroUser.setDeptName(ConstantFactory.me().getDeptName(user.getDeptid()));
        shiroUser.setName(user.getName());
        shiroUser.setObjectId(user.getObjectId());
        shiroUser.setRoleType(user.getRoleType());
        Integer[] roleArray = Convert.toIntArray(user.getRoleid());
        List<Integer> roleList = new ArrayList<Integer>();
        List<String> roleNameList = new ArrayList<String>();
@@ -71,7 +78,8 @@
        }
        shiroUser.setRoleList(roleList);
        shiroUser.setRoleNames(roleNameList);
        List<Role> roles = roleMapper.selectBatchIds(roleList);
        shiroUser.setAdmin(roles.stream().filter(s -> s.getTips().equals("administrator")).findAny().isPresent());
        return shiroUser;
    }