Commit 2a9be7ca39867888c6a72fe1f35d6651f2971d91

Authored by fangcheng
1 parent d7886f353c
Exists in master

用户登录完成

Showing 11 changed files with 192 additions and 124 deletions

center.manager/src/main/java/com/lyms/cm/controller/LoginController.java View file @ 2a9be7c
... ... @@ -16,13 +16,11 @@
16 16 import org.springframework.web.bind.annotation.RequestMethod;
17 17 import org.springframework.web.bind.annotation.RequestParam;
18 18  
19   -import com.baomidou.mybatisplus.mapper.EntityWrapper;
20 19 import com.lyms.cm.entity.sys.SysUsers;
21 20 import com.lyms.cm.entity.sys.TreeNode;
  21 +import com.lyms.cm.enums.PermissionEnum;
22 22 import com.lyms.cm.service.sys.SysPermissionsService;
23   -import com.lyms.cm.service.sys.SysUsersService;
24 23 import com.lyms.constants.Constants;
25   -import com.lyms.constants.SysResourceType;
26 24 import com.lyms.shiro.ShiroWebUtils;
27 25 import com.lyms.util.StrUtils;
28 26 import com.lyms.web.controller.BaseController;
... ... @@ -33,9 +31,6 @@
33 31 private static final String VIEW_LOGIN = "/login/login";
34 32  
35 33  
36   -
37   - @Autowired
38   - private SysUsersService sysUsersService;
39 34  
40 35 @Autowired
41 36 private SysPermissionsService sysPermissionsService;
... ... @@ -47,7 +42,7 @@
47 42 return redirectTo(VIEW_LOGIN);
48 43 }
49 44 SysUsers user = ShiroWebUtils.getCurrentUser();
50   - List<TreeNode> menus = sysPermissionsService.getPermissionMenuTreeByPuri(SysResourceType.MANAGER_ROOT_MENU_RESOURCE_ID,user);
  45 + List<TreeNode> menus = sysPermissionsService.getPermissionMenuTreeByPuri(PermissionEnum.CENTER_MANAGER_ROOT.getCode(),user);
51 46 model.addAttribute("menus", menus);
52 47 return "/index";
53 48 }
center.manager/src/main/java/com/lyms/cm/controller/sys/SysRolesController.java View file @ 2a9be7c
... ... @@ -116,6 +116,9 @@
116 116 String roleId = StrUtils.uuid();
117 117 role.setId(roleId);
118 118 role.setIfdel(0);
  119 + if(null == role.getEnable()){
  120 + role.setEnable(1);
  121 + }
119 122 tag = sysRolesService.createRole(role, getRolePermissionList(roleId, getParameter("resource")));
120 123 return handleAjaxResult(ajaxResult, tag, OperationName.CREATE);
121 124 }
... ... @@ -128,7 +131,7 @@
128 131 public AjaxResult update(SysRoles role, AjaxResult ajaxResult) {
129 132 boolean tag = false;
130 133 if(null == role.getEnable()){
131   - role.setEnable(0);
  134 + role.setEnable(1);
132 135 }
133 136 tag = sysRolesService.updateRole(role, getRolePermissionList(role.getId(), getParameter("resource")));
134 137 return handleAjaxResult(ajaxResult, tag, OperationName.UPDATE);
center.manager/src/main/java/com/lyms/cm/dao/sys/SysPermissionsMapper.xml View file @ 2a9be7c
... ... @@ -22,10 +22,12 @@
22 22 ID AS id, NAME AS name, URI AS uri, TYPE AS type, PURI AS puri, ICON AS icon, IFDEL AS ifdel, ENABLE AS enable, EXTRA_DATA AS extraData, WEIGHT AS weight, FOREIGN_ID AS foreignId
23 23 </sql>
24 24  
  25 + <!-- 根据puri获取子菜单-->
25 26 <select id="getMenuTreeByPuri" resultType="TreeNode">
26 27 SELECT uri as id ,puri as pid, uri as url,name as text FROM SYS_PERMISSIONS where type=1 and puri = #{puri}
27 28 </select>
28 29  
  30 + <!-- 根据uid获取用户的权限列表-->
29 31 <select id="getUserPermission" resultType="SysPermissions">
30 32 select <include refid="Base_Column_List"></include> from SYS_PERMISSIONS where ID in (
31 33 select PERMISSION_ID from SYS_ROLE_PERMISSION_MAPS rp where ROLE_ID in (
center.manager/src/main/java/com/lyms/cm/service/sys/SysPermissionsService.java View file @ 2a9be7c
... ... @@ -6,6 +6,7 @@
6 6 import com.lyms.web.service.BaseService;
7 7 import java.io.Serializable;
8 8 import java.util.List;
  9 +import java.util.Set;
9 10  
10 11 /**
11 12 * <p>
12 13  
... ... @@ -17,15 +18,35 @@
17 18 */
18 19 public interface SysPermissionsService extends BaseService<SysPermissions> {
19 20  
20   - /**
  21 + /**
21 22 * <li>@Description:逻辑删除,ifDel = 1 为删除,否则为没有删除
22 23 * <li>@param id 删除主键id
23 24 * <li>@return 大于0修改成功,否则为失败
24 25 */
25   - public Integer deleteLogicById(Serializable id);
26   -
27   - public List<TreeNode> getPermissionMenuTreeByPuri(String puri, SysUsers user);
28   -
29   -
  26 + public Integer deleteLogicById(Serializable id);
  27 +
  28 + /**
  29 + * <li>@Description:根据puri和user的id获取所有有权限的菜单
  30 + * <li>@param puri
  31 + * <li>@param user
  32 + * <li>@return
  33 + * <li>创建人:方承
  34 + * <li>创建时间:2017年3月10日
  35 + * <li>修改人:
  36 + * <li>修改时间:
  37 + */
  38 + public List<TreeNode> getPermissionMenuTreeByPuri(String puri, SysUsers user);
  39 +
  40 + /**
  41 + * <li>@Description:权限列表Set,方便Shiro使用
  42 + * <li>@param uid
  43 + * <li>@return
  44 + * <li>创建人:方承
  45 + * <li>创建时间:2017年3月9日
  46 + * <li>修改人:
  47 + * <li>修改时间:
  48 + */
  49 + public Set<String> getUserPermissionSet(String uid);
  50 +
30 51 }
center.manager/src/main/java/com/lyms/cm/service/sys/SysRolesService.java View file @ 2a9be7c
... ... @@ -50,6 +50,8 @@
50 50 * <li>修改时间:
51 51 */
52 52 public boolean updateRole(SysRoles role,List<SysRolePermissionMaps> rpList);
  53 +
  54 +
53 55  
54 56 }
center.manager/src/main/java/com/lyms/cm/service/sys/SysUsersService.java View file @ 2a9be7c
... ... @@ -17,6 +17,18 @@
17 17 * @since 2017-03-02
18 18 */
19 19 public interface SysUsersService extends BaseService<SysUsers> {
  20 +
  21 +
  22 + /**
  23 + * <li>@Description:根据登录名称查找未逻辑删除用户
  24 + * <li>@param name
  25 + * <li>@return
  26 + * <li>创建人:方承
  27 + * <li>创建时间:2017年3月10日
  28 + * <li>修改人:
  29 + * <li>修改时间:
  30 + */
  31 + public SysUsers getUserByUsername(String name);
20 32  
21 33 /**
22 34 * 添加用户
... ... @@ -74,6 +86,18 @@
74 86 * <li>修改时间:
75 87 */
76 88 public boolean isAllowUpdate(String account,String userid);
  89 +
  90 +
  91 + /**
  92 + * <li>@Description:根据用户id获取角色id列表
  93 + * <li>@param uid
  94 + * <li>@return
  95 + * <li>创建人:方承
  96 + * <li>创建时间:2017年3月10日
  97 + * <li>修改人:
  98 + * <li>修改时间:
  99 + */
  100 + public List<String> getRoleIdListByUserid(String uid);
77 101  
78 102 }
center.manager/src/main/java/com/lyms/cm/service/sys/impl/SysPermissionsServiceImpl.java View file @ 2a9be7c
... ... @@ -31,7 +31,17 @@
31 31 }
32 32  
33 33  
34   - public List<TreeNode> getMenuTreeByPid(String puri) {
  34 + /**
  35 + * <li>@Description:根据puri获取所有菜单
  36 + * <li>@param puri
  37 + * <li>@return
  38 + * <li>创建人:方承
  39 + * <li>创建时间:2017年3月10日
  40 + * <li>修改人:
  41 + * <li>修改时间:
  42 + */
  43 + public List<TreeNode> getAllMenuTreeByPuri(String puri) {
  44 + //treenode的id保存的uri,pid保存的puri
35 45 List<TreeNode> allMenu = baseMapper.getMenuTreeByPuri(puri);
36 46 //迭代获取子节点
37 47 for (TreeNode menuNode : allMenu) {
... ... @@ -44,9 +54,14 @@
44 54 return allMenu;
45 55 }
46 56  
47   - /**
48   - * @param treeNodeList 迭代处理子节点
49   - */
  57 + /**
  58 + * <li>@Description:迭代处理所有子菜单
  59 + * <li>@param treeNodeList
  60 + * <li>创建人:方承
  61 + * <li>创建时间:2017年3月10日
  62 + * <li>修改人:
  63 + * <li>修改时间:
  64 + */
50 65 private void getSubMenuTreeByNodeList(List<TreeNode> treeNodeList) {
51 66 if(treeNodeList != null && treeNodeList.size() > 0){
52 67 //迭代获取子节点
53 68  
... ... @@ -60,13 +75,12 @@
60 75 }
61 76 }
62 77  
63   - //权限菜单
64 78 @Override
65 79 public List<TreeNode> getPermissionMenuTreeByPuri(String puri, SysUsers user) {
66 80 //用户权限列表
67 81 Map<String,String> permissionsMap = getUserPermissionMap(getUserPermissionSet(user.getId()));
68 82 //所有菜单
69   - List<TreeNode> allMenu = baseMapper.getMenuTreeByPuri(puri);
  83 + List<TreeNode> allMenu = getAllMenuTreeByPuri(puri);
70 84 //初始化要返回的有权限的菜单
71 85 List<TreeNode> allPermissionMenu = InstanceUtils.newArrayList();
72 86 //迭代获取子节点
... ... @@ -89,9 +103,15 @@
89 103 return allPermissionMenu;
90 104  
91 105 }
92   - /**
93   - * @param treeNodeList 迭代处理获取有权限的子节点
94   - */
  106 + /**
  107 + * <li>@Description:迭代处理获取有权限的子节点
  108 + * <li>@param treeNodeList
  109 + * <li>@param permissionMap
  110 + * <li>创建人:方承
  111 + * <li>创建时间:2017年3月10日
  112 + * <li>修改人:
  113 + * <li>修改时间:
  114 + */
95 115 private void getPermissionSubMenuTreeByNodeList(List<TreeNode> treeNodeList,Map<String,String> permissionMap) {
96 116 if(treeNodeList != null && treeNodeList.size() > 0){
97 117 //迭代获取子节点
... ... @@ -124,15 +144,7 @@
124 144 return baseMapper.getUserPermission(uid);
125 145 }
126 146  
127   - /**
128   - * <li>@Description:权限列表Set,方便Shiro使用
129   - * <li>@param uid
130   - * <li>@return
131   - * <li>创建人:方承
132   - * <li>创建时间:2017年3月9日
133   - * <li>修改人:
134   - * <li>修改时间:
135   - */
  147 + @Override
136 148 public Set<String> getUserPermissionSet(String uid){
137 149 Set<String> pSet = InstanceUtils.newHashSet();
138 150 List<SysPermissions> pList = getUserPermission(uid);
center.manager/src/main/java/com/lyms/cm/service/sys/impl/SysRolesServiceImpl.java View file @ 2a9be7c
1 1 package com.lyms.cm.service.sys.impl;
2 2  
3   -import com.lyms.cm.entity.sys.SysRolePermissionMaps;
4   -import com.lyms.cm.entity.sys.SysRoles;
5   -import com.lyms.cm.dao.sys.SysRolesMapper;
6   -import com.lyms.cm.service.sys.SysRolePermissionMapsService;
7   -import com.lyms.cm.service.sys.SysRolesService;
8   -import com.baomidou.mybatisplus.mapper.EntityWrapper;
9   -import com.baomidou.mybatisplus.service.impl.ServiceImpl;
  3 +import java.io.Serializable;
  4 +import java.util.List;
10 5  
11 6 import org.springframework.beans.factory.annotation.Autowired;
12 7 import org.springframework.stereotype.Service;
13 8 import org.springframework.transaction.annotation.Transactional;
14 9  
15   -import java.io.Serializable;
16   -import java.util.List;
  10 +import com.baomidou.mybatisplus.mapper.EntityWrapper;
  11 +import com.baomidou.mybatisplus.service.impl.ServiceImpl;
  12 +import com.lyms.cm.dao.sys.SysRolesMapper;
  13 +import com.lyms.cm.entity.sys.SysRolePermissionMaps;
  14 +import com.lyms.cm.entity.sys.SysRoles;
  15 +import com.lyms.cm.service.sys.SysRolePermissionMapsService;
  16 +import com.lyms.cm.service.sys.SysRolesService;
17 17  
18 18 /**
19 19 * <p>
... ... @@ -53,5 +53,7 @@
53 53 }
54 54 return true;
55 55 }
  56 +
  57 +
56 58 }
center.manager/src/main/java/com/lyms/cm/service/sys/impl/SysUsersServiceImpl.java View file @ 2a9be7c
... ... @@ -10,16 +10,14 @@
10 10  
11 11 import com.baomidou.mybatisplus.mapper.EntityWrapper;
12 12 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
13   -import com.lyms.cm.dao.sys.SysUserRoleMapsMapper;
14 13 import com.lyms.cm.dao.sys.SysUsersMapper;
15   -import com.lyms.cm.entity.sys.SysRolePermissionMaps;
16 14 import com.lyms.cm.entity.sys.SysUserRoleMaps;
17 15 import com.lyms.cm.entity.sys.SysUsers;
18   -import com.lyms.cm.enums.StatusEnum;
19 16 import com.lyms.cm.enums.ValidityEnum;
20 17 import com.lyms.cm.service.sys.SysUserRoleMapsService;
21 18 import com.lyms.cm.service.sys.SysUsersService;
22 19 import com.lyms.exception.SystemException;
  20 +import com.lyms.util.InstanceUtils;
23 21 import com.lyms.util.MD5Utils;
24 22 import com.lyms.util.StrUtils;
25 23  
26 24  
27 25  
... ... @@ -35,16 +33,15 @@
35 33 public class SysUsersServiceImpl extends ServiceImpl<SysUsersMapper, SysUsers> implements SysUsersService {
36 34  
37 35 @Autowired
38   - private SysUsersMapper userMapper;
39   -
  36 + private SysUsersMapper userMapper;
  37 +
40 38 @Autowired
41 39 private SysUserRoleMapsService sysUserRoleMapsService;
42   -
43 40  
44 41 /**
45 42 * 系统默认密码
46 43 */
47   - private static final String DEFAULT_PWD = "123456";
  44 + private static final String DEFAULT_PWD = "123456";
48 45  
49 46 // 模块基础操作信息
50 47 private boolean empty(SysUsers user) {
... ... @@ -67,7 +64,7 @@
67 64  
68 65 @Override
69 66 @Transactional
70   - public boolean addUser(SysUsers user,List<SysUserRoleMaps> userRoleMapsList) throws SystemException {
  67 + public boolean addUser(SysUsers user, List<SysUserRoleMaps> userRoleMapsList) throws SystemException {
71 68 if (empty(user))
72 69 return false;
73 70 // 设置user ID
... ... @@ -90,7 +87,7 @@
90 87  
91 88 @Override
92 89 @Transactional
93   - public boolean updateUser(SysUsers user,List<SysUserRoleMaps> userRoleMapsList) throws SystemException {
  90 + public boolean updateUser(SysUsers user, List<SysUserRoleMaps> userRoleMapsList) throws SystemException {
94 91 if (empty(user))
95 92 return false;
96 93 if (null == user.getType()) {//没有勾选管理,就是用户
... ... @@ -99,7 +96,7 @@
99 96 if (null == user.getEnable()) {
100 97 user.setEnable(1);
101 98 }
102   - if (StrUtils.isNotEmpty(user.getPwd()) ) {
  99 + if (StrUtils.isNotEmpty(user.getPwd())) {
103 100 // 初始密码
104 101 this.initPwd(user);
105 102 }
... ... @@ -120,7 +117,6 @@
120 117 * userMapper.selectById(userId); }
121 118 */
122 119  
123   -
124 120 @Override
125 121 @Transactional
126 122 public boolean delete(String userId) throws SystemException {
127 123  
128 124  
129 125  
130 126  
... ... @@ -149,19 +145,19 @@
149 145 }
150 146  
151 147 @Override
152   - public boolean isAllowUpdate(String account,String userid) {
  148 + public boolean isAllowUpdate(String account, String userid) {
153 149 boolean flag = true;
154   - if(StrUtils.isNotEmpty(userid) ){//修改用户
  150 + if (StrUtils.isNotEmpty(userid)) {//修改用户
155 151 SysUsers oldDbUser = selectById(userid);
156   - if(!oldDbUser.getAccount().equalsIgnoreCase(account)){//登录账号改变
  152 + if (!oldDbUser.getAccount().equalsIgnoreCase(account)) {//登录账号改变
157 153 flag = !isExistAccount(account);
158 154 }
159   - }else{//新增
  155 + } else {//新增
160 156 flag = !isExistAccount(account);
161 157 }
162 158 return flag;
163 159 }
164   -
  160 +
165 161 /**
166 162 * <li>@Description:是否存在登录名
167 163 * <li>@param account
168 164  
... ... @@ -170,13 +166,31 @@
170 166 * <li>创建时间:2017年3月9日
171 167 * <li>修改人:
172 168 * <li>修改时间:
173   - */
174   - private boolean isExistAccount(String account){
175   - SysUsers entity = selectOne(new EntityWrapper<SysUsers>().where("account={0}", "'" + account + "'").and("ifDel=0"));
  169 + */
  170 + private boolean isExistAccount(String account) {
  171 + SysUsers entity = selectOne(
  172 + new EntityWrapper<SysUsers>().where("account={0}", "'" + account + "'").and("ifDel=0"));
176 173 if (null == entity) {
177 174 return false;
178 175 }
179 176 return true;
  177 + }
  178 +
  179 + @Override
  180 + public SysUsers getUserByUsername(String name) {
  181 + SysUsers user = selectOne(new EntityWrapper<SysUsers>().where("account={0}", name).and("ifDel=0"));
  182 + return user;
  183 + }
  184 +
  185 + @Override
  186 + public List<String> getRoleIdListByUserid(String uid) {
  187 + List<SysUserRoleMaps> urList = sysUserRoleMapsService
  188 + .selectList(new EntityWrapper<SysUserRoleMaps>().where("user_id={0}", uid));
  189 + List<String> roleIdList = InstanceUtils.newArrayList();
  190 + for (SysUserRoleMaps ur : urList) {
  191 + roleIdList.add(ur.getRoleId());
  192 + }
  193 + return roleIdList;
180 194 }
181 195  
182 196 }
center.manager/src/main/java/com/lyms/cm/shiro/ShiroRealm.java View file @ 2a9be7c
... ... @@ -2,7 +2,9 @@
2 2  
3 3 import java.util.Arrays;
4 4 import java.util.HashSet;
  5 +import java.util.List;
5 6  
  7 +import org.apache.commons.lang3.ArrayUtils;
6 8 import org.apache.shiro.authc.AccountException;
7 9 import org.apache.shiro.authc.AuthenticationException;
8 10 import org.apache.shiro.authc.AuthenticationInfo;
9 11  
... ... @@ -22,9 +24,12 @@
22 24 import com.baomidou.mybatisplus.mapper.EntityWrapper;
23 25 import com.lyms.cm.entity.sys.SysUsers;
24 26 import com.lyms.cm.enums.StatusEnum;
  27 +import com.lyms.cm.service.sys.SysPermissionsService;
25 28 import com.lyms.cm.service.sys.SysUsersService;
26 29 import com.lyms.shiro.HashUtils;
27 30 import com.lyms.shiro.ShiroWebUtils;
  31 +import com.lyms.util.CollectionUtils;
  32 +import com.lyms.util.MD5Utils;
28 33 import com.lyms.util.StrUtils;
29 34  
30 35 /**
... ... @@ -36,18 +41,6 @@
36 41 */
37 42 public class ShiroRealm extends AuthorizingRealm {
38 43  
39   - @Override
40   - protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
41   - // TODO Auto-generated method stub
42   - return null;
43   - }
44   -
45   - @Override
46   - protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
47   - // TODO Auto-generated method stub
48   - return null;
49   - }
50   -
51 44 @SuppressWarnings("unused")
52 45 private static Logger logger = LoggerFactory.getLogger(ShiroRealm.class);
53 46  
54 47  
55 48  
... ... @@ -59,58 +52,60 @@
59 52 }
60 53  
61 54 @Autowired
62   - private SysUsersService sysUsersService;
  55 + private SysUsersService sysUsersService;
63 56  
  57 + private SysPermissionsService sysPermissionsService;
  58 +
64 59 // @Autowired
65 60 // private ResourceService resourceService;
66 61  
67   -// @Override
68   -// protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
69   -// // String username = (String) principals.getPrimaryPrincipal();
70   -// // User user = userService.getUserByUserName(username);
71   -// // // 授权
72   -// // SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
73   -// // if(StrUtils.isNotEmpty(user.getRoles())){
74   -// // authorizationInfo.setRoles(new HashSet<String>(Arrays.asList(user.getRoles().split(","))));
75   -// // }
76   -// // authorizationInfo.setStringPermissions(resourceService.getResourcePermissionSet(userService.getUserResourceIdSet(user)));
77   -// // return authorizationInfo;
78   -// }
79   -//
80   -// @Override
81   -// protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
82   -// UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
83   -// String username = token.getUsername();
84   -// SysUsers user = sysUsersService
85   -// .selectOne(new EntityWrapper<SysUsers>().where("name={0}", username).and("ifDel=0"));
86   -// if (StatusEnum.isDisEnabled(user.getEnable())) {
87   -// throw new AccountException("用户已经被禁用,请联系管理员!");
88   -// }
89   -// StringBuilder pwd = new StringBuilder(100);
90   -// for (int i = 0; i < token.getPassword().length; i++) {
91   -// pwd.append(token.getPassword()[i]);
92   -// }
93   -// if (!StrUtils.equals(user.getPwd(), HashUtils.md5(pwd.toString()))) {
94   -// throw new AccountException("用户名密码不一致");
95   -// }
96   -// ShiroWebUtils.saveCurrentUser(user);
97   -// AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, pwd.toString(), username);
98   -// return authcInfo;
99   -// // User user = userService.getUserByUserName(username);
100   -// // if (user == null) {
101   -// // throw new UnknownAccountException("未知用户");
102   -// // }
103   -// // StringBuilder pwd = new StringBuilder(100);
104   -// // for (int i = 0; i < token.getPassword().length; i++) {
105   -// // pwd.append(token.getPassword()[i]);
106   -// // }
107   -// // if (!StrUtils.equals(user.getPassword(), HashUtils.md5(pwd.toString()))) {
108   -// // throw new AccountException("用户名密码不一致");
109   -// // }
110   -// // ShiroWebUtils.saveCurrentUser(user);
111   -// // AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, pwd.toString(), username);
112   -// // return authcInfo;
113   -// }
  62 + @Override
  63 + protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  64 + String username = (String) principals.getPrimaryPrincipal();
  65 + SysUsers user = sysUsersService.getUserByUsername(username);
  66 + // 授权
  67 + SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
  68 + List<String> roleIdList = sysUsersService.getRoleIdListByUserid(user.getId());
  69 + if (CollectionUtils.isNotEmpty(roleIdList)) {
  70 + authorizationInfo.setRoles(new HashSet<String>(roleIdList));
  71 + }
  72 + authorizationInfo.setStringPermissions(sysPermissionsService.getUserPermissionSet(user.getId()));
  73 + return authorizationInfo;
  74 + }
  75 +
  76 + @Override
  77 + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
  78 + UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
  79 + String username = token.getUsername();
  80 + SysUsers user = sysUsersService.getUserByUsername(username);
  81 + if (StatusEnum.isDisEnabled(user.getEnable())) {
  82 + throw new AccountException("用户已经被禁用,请联系管理员!");
  83 + }
  84 + StringBuilder pwd = new StringBuilder(100);
  85 + for (int i = 0; i < token.getPassword().length; i++) {
  86 + pwd.append(token.getPassword()[i]);
  87 + }
  88 + if (!StrUtils.equals(user.getPwd(), MD5Utils.md5(pwd.toString()))){
  89 + throw new AccountException("用户名密码不一致");
  90 + }
  91 + ShiroWebUtils.saveCurrentUser(user);
  92 + AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, pwd.toString(), username);
  93 + return authcInfo;
  94 + // User user = userService.getUserByUserName(username);
  95 + // if (user == null) {
  96 + // throw new UnknownAccountException("未知用户");
  97 + // }
  98 + // StringBuilder pwd = new StringBuilder(100);
  99 + // for (int i = 0; i < token.getPassword().length; i++) {
  100 + // pwd.append(token.getPassword()[i]);
  101 + // }
  102 + // if (!StrUtils.equals(user.getPassword(), HashUtils.md5(pwd.toString()))) {
  103 + // throw new AccountException("用户名密码不一致");
  104 + // }
  105 + // ShiroWebUtils.saveCurrentUser(user);
  106 + // AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, pwd.toString(), username);
  107 + // return authcInfo;
  108 + }
114 109  
115 110 }
center.manager/src/main/resources/xml/app-shiro.xml View file @ 2a9be7c
... ... @@ -45,13 +45,11 @@
45 45 </property>
46 46 <property name="filterChainDefinitions">
47 47 <value>
48   - <!-- /login = anon
49   - /sysUsers/** =anon
  48 + /login = anon
50 49 /logout = logout
51 50 /static/** = anon
52 51 /authenticated = authc
53   - /** = user,forceLogout -->
54   - /** = anon
  52 + /** = user,forceLogout
55 53 </value>
56 54 </property>
57 55 </bean>