feat: There is no way the user jwt
This commit is contained in:
@@ -1,12 +1,21 @@
|
|||||||
package com.adc.da.login.util;
|
package com.adc.da.login.util;
|
||||||
|
|
||||||
|
import com.adc.da.att.entity.TsUser;
|
||||||
|
import com.adc.da.sys.entity.UserEO;
|
||||||
|
import com.adc.da.sys.service.IUserEOService;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
import io.jsonwebtoken.ExpiredJwtException;
|
import io.jsonwebtoken.ExpiredJwtException;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* token 工具类
|
* token 工具类
|
||||||
@@ -25,6 +34,9 @@ public class JwtUtils {
|
|||||||
// 秘钥
|
// 秘钥
|
||||||
private static String secret = "HSyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9";
|
private static String secret = "HSyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IUserEOService userService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个token
|
* 创建一个token
|
||||||
*
|
*
|
||||||
@@ -35,8 +47,8 @@ public class JwtUtils {
|
|||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
Date expireDate = new Date(now.getTime() + expire);
|
Date expireDate = new Date(now.getTime() + expire);
|
||||||
return Jwts.builder().setHeaderParam("type", "JWT").setSubject(userId).setIssuedAt(now)
|
return Jwts.builder().setHeaderParam("type", "JWT").setSubject(userId).setIssuedAt(now)
|
||||||
.setExpiration(expireDate).signWith(
|
.setExpiration(expireDate).signWith(
|
||||||
SignatureAlgorithm.HS512, secret).compact();
|
SignatureAlgorithm.HS512, secret).compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,6 +67,31 @@ public class JwtUtils {
|
|||||||
return claims;
|
return claims;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUserIdByToken(){
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
String user = "";
|
||||||
|
if(attributes != null){
|
||||||
|
HttpServletRequest request = attributes.getRequest();
|
||||||
|
Claims claim = getClaimsByToken(request.getHeader("token"));
|
||||||
|
user = claim.getSubject();
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserEO getUserByToken(){
|
||||||
|
UserEO userEO = new UserEO();
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
if(attributes != null){
|
||||||
|
HttpServletRequest request = attributes.getRequest();
|
||||||
|
//添加token
|
||||||
|
Claims claim = getClaimsByToken(request.getHeader("token"));
|
||||||
|
String subject = claim.getSubject();
|
||||||
|
List<UserEO> userEOS = userService.getUser(subject);
|
||||||
|
userEO = userEOS.get(0);
|
||||||
|
}
|
||||||
|
return userEO;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断 token 是否过期
|
* 判断 token 是否过期
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
|||||||
import org.apache.shiro.session.InvalidSessionException;
|
import org.apache.shiro.session.InvalidSessionException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -46,6 +47,11 @@ public class UserUtils {
|
|||||||
public static final String CACHE_AREA_LIST = "areaList";
|
public static final String CACHE_AREA_LIST = "areaList";
|
||||||
public static final String CACHE_OFFICE_LIST = "officeList";
|
public static final String CACHE_OFFICE_LIST = "officeList";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see JwtUtils
|
||||||
|
*/
|
||||||
|
private static JwtUtils jwtUtils = SpringContextHolder1.getBean(JwtUtils.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see IUserEOService
|
* @see IUserEOService
|
||||||
*/
|
*/
|
||||||
@@ -82,7 +88,7 @@ public class UserUtils {
|
|||||||
// if (principal != null) {
|
// if (principal != null) {
|
||||||
// return principal.getLoginName();
|
// return principal.getLoginName();
|
||||||
// }
|
// }
|
||||||
return "admin";
|
return jwtUtils.getUserIdByToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,7 +107,7 @@ public class UserUtils {
|
|||||||
* 获取当前登录用户信息
|
* 获取当前登录用户信息
|
||||||
*/
|
*/
|
||||||
public static UserEO getUser() {
|
public static UserEO getUser() {
|
||||||
UserEO user = (UserEO) CacheUtils.getCache(CURRENT_USER);
|
UserEO user = jwtUtils.getUserByToken();
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = new UserEO();
|
user = new UserEO();
|
||||||
String userName = getUserName();
|
String userName = getUserName();
|
||||||
|
|||||||
+3
-3
@@ -149,9 +149,9 @@ public class TsUserServiceImpl extends ServiceImpl<TsUserDao, TsUser> implements
|
|||||||
* @return List<SarMenu>
|
* @return List<SarMenu>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SarMenu> getMenu(String userId) {
|
public List<SarMenu> getMenu(String userIds) {
|
||||||
/* UserEO userEO=UserUtils.getUser();
|
UserEO userEO=UserUtils.getUser();
|
||||||
String userId= userEO.getUsid();*/
|
String userId= userEO.getUsid();
|
||||||
List<String> positionIds=tsUserDao.selectPositionIds(userId);
|
List<String> positionIds=tsUserDao.selectPositionIds(userId);
|
||||||
/**
|
/**
|
||||||
* 当用户没有所属岗位,默认给一个other岗位,适用于特定权限外的其他用户
|
* 当用户没有所属岗位,默认给一个other岗位,适用于特定权限外的其他用户
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ public interface UserEODao extends BaseMapper<UserEO> {
|
|||||||
*/
|
*/
|
||||||
UserEO selectOrgByPrimaryKey(String usid);
|
UserEO selectOrgByPrimaryKey(String usid);
|
||||||
|
|
||||||
|
List<UserEO> getUser(String usid);
|
||||||
|
|
||||||
Integer selectOrgCountByPrimaryKey(String usid);
|
Integer selectOrgCountByPrimaryKey(String usid);
|
||||||
|
|
||||||
UserEO selectRoleMessageByPrimaryKey(String usid);
|
UserEO selectRoleMessageByPrimaryKey(String usid);
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ public interface IUserEOService extends IService<UserEO> {
|
|||||||
|
|
||||||
public UserEO getOrgIdByUserId(String userId);
|
public UserEO getOrgIdByUserId(String userId);
|
||||||
|
|
||||||
|
public List<UserEO> getUser(String userId);
|
||||||
|
|
||||||
public UserEO getUserByLoginNameNotDeleted(String userName);
|
public UserEO getUserByLoginNameNotDeleted(String userName);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -428,6 +428,11 @@ public class UserEOServiceImpl extends ServiceImpl<UserEODao, UserEO> implements
|
|||||||
return this.baseMapper.get(userId);
|
return this.baseMapper.get(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||||
|
public List<UserEO> getUser(String usid){
|
||||||
|
return this.baseMapper.getUser(usid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author liwenxuan
|
* @Author liwenxuan
|
||||||
|
|||||||
@@ -397,6 +397,13 @@
|
|||||||
AND usid !=#{usid}
|
AND usid !=#{usid}
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getUser" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
from TS_USER
|
||||||
|
where valid_flag=0 AND usid =#{usid}
|
||||||
|
</select>
|
||||||
<!-- 根据用户ID获取用户信息及角色、组织机构信息 -->
|
<!-- 根据用户ID获取用户信息及角色、组织机构信息 -->
|
||||||
<select id="getUserWithRoles" resultMap="UserRoleMap" parameterType="java.lang.String">
|
<select id="getUserWithRoles" resultMap="UserRoleMap" parameterType="java.lang.String">
|
||||||
select
|
select
|
||||||
|
|||||||
Reference in New Issue
Block a user