| | |
| | | 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; |
| | |
| | | @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(); |
| | |
| | | @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>(); |
| | |
| | | } |
| | | 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; |
| | | } |
| | | |