|
@@ -1,5 +1,6 @@
|
|
|
package com.platform.shiro;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.auth0.jwt.JWT;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.platform.cache.J2CacheUtils;
|
|
@@ -7,10 +8,13 @@ import com.platform.shiro.jwt.JwtToken;
|
|
|
import com.platform.service.impl.ZhiHouseService;
|
|
|
import com.platform.utils.Constant;
|
|
|
import com.platform.utils.JwtUtil;
|
|
|
+import com.platform.utils.LettuceRedisClientUtils;
|
|
|
import com.platform.vos.CurrentUserLoginVo;
|
|
|
import com.platform.vos.TbUser;
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.oschina.j2cache.redis.RedisUtils;
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.authc.*;
|
|
@@ -49,41 +53,29 @@ public class UserRealm extends AuthorizingRealm {
|
|
|
*/
|
|
|
@Override
|
|
|
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
|
|
-// SysUserEntity user = (SysUserEntity) principals.getPrimaryPrincipal();
|
|
|
-// Long userId = user.getUserId();
|
|
|
-//
|
|
|
-//// Claims claims = JwtUtil.parseJWT(principals.toString());
|
|
|
-//// Long userId = Long.valueOf(claims.get("id", String.class));
|
|
|
-//
|
|
|
-// SysUserEntity user = (SysUserEntity) principals.getPrimaryPrincipal();
|
|
|
-//
|
|
|
-// List<String> permsList;
|
|
|
-//
|
|
|
-// //系统管理员,拥有最高权限
|
|
|
-// if (userId == Constant.SUPER_ADMIN) {
|
|
|
-// if (user.getUserId() == Constant.SUPER_ADMIN) {
|
|
|
-// List<SysMenuEntity> menuList = sysMenuDao.queryList(new HashMap<>());
|
|
|
-// permsList = new ArrayList<>(menuList.size());
|
|
|
-// for (SysMenuEntity menu : menuList) {
|
|
|
-// permsList.add(menu.getPerms());
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// permsList = sysUserDao.queryAllPerms(userId);
|
|
|
-// permsList = sysUserDao.queryAllPerms(user.getUserId());
|
|
|
-// }
|
|
|
-// //用户权限列表
|
|
|
-// Set<String> permsSet = new HashSet<String>();
|
|
|
-// if (permsList != null && permsList.size() != 0) {
|
|
|
-// for (String perms : permsList) {
|
|
|
-// if (StringUtils.isBlank(perms)) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// permsSet.addAll(Arrays.asList(perms.trim().split(",")));
|
|
|
-// }
|
|
|
-// }
|
|
|
+ TbUser user = (TbUser) principals.getPrimaryPrincipal();
|
|
|
+ Long userId = user.getId();
|
|
|
+ Set<String> permsSet = new HashSet<String>();
|
|
|
+ List<String> permsList;
|
|
|
|
|
|
+ //系统管理员,拥有最高权限
|
|
|
+
|
|
|
+ if (userId == Constant.SUPER_ADMIN) {
|
|
|
+ permsList = zhiHouseService.getAllPerms(null);
|
|
|
+ } else {
|
|
|
+ permsList = zhiHouseService.getAllPerms(userId);
|
|
|
+ }
|
|
|
+ //用户权限列表
|
|
|
+ if (permsList != null && permsList.size() != 0) {
|
|
|
+ for (String perms : permsList) {
|
|
|
+ if (StringUtils.isBlank(perms)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ permsSet.addAll(Arrays.asList(perms.trim().split(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
|
|
- //info.setStringPermissions(permsSet);
|
|
|
+ info.setStringPermissions(permsSet);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
@@ -96,9 +88,6 @@ public class UserRealm extends AuthorizingRealm {
|
|
|
String token = (String) auth.getCredentials();
|
|
|
Claims claims = JwtUtil.parseJWT(token);
|
|
|
String userId = claims.get("id", String.class);
|
|
|
- String username = claims.get("username", String.class);
|
|
|
- String password = claims.get("password", String.class);
|
|
|
-
|
|
|
//查询用户信息
|
|
|
TbUser userEntity = zhiHouseService.getByUserId(Long.valueOf(userId));
|
|
|
|