Commit 9f392bd3 authored by liqin's avatar liqin 💬

bug fixed

parent 35817894
......@@ -6,28 +6,20 @@ import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
@Component
@Slf4j
public class JwtTokenUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(JwtTokenUtil.class);
private static String jwtTokenSecret;
private static String jwtTokenIssuer;
private static String jwtTokenExpiration;
@Resource
private StringRedisTemplate stringRedisTemplate;
@Value("${jwt.secret}")
public void setJwtTokenSecret(String jwtTokenSecret) {
JwtTokenUtil.jwtTokenSecret = jwtTokenSecret;
......@@ -56,7 +48,7 @@ public class JwtTokenUtil {
DecodedJWT jwt = verifier.verify(token);
return jwt.getClaim("user_id").asString();
} catch (Exception e) {
LOGGER.error(e.getMessage());
log.error(e.getMessage());
return null;
}
}
......@@ -95,13 +87,14 @@ public class JwtTokenUtil {
* @param username 用户名
* @return 加密的token
*/
public static String sign(String username, String employeeId) throws UnsupportedEncodingException {
public static String sign(String username, String employeeId) {
LocalDateTime currentTime = DateUtil80.getDateTimeOfTimestamp(System.currentTimeMillis());
Algorithm algorithm = Algorithm.HMAC512(jwtTokenSecret);
// 附带username信息
return JWT.create().withIssuer(jwtTokenIssuer)
// 创建时间
.withIssuedAt(DateUtil80.getCurrDateTime()).withSubject(username).withClaim("user_id", employeeId)
.withIssuedAt(DateUtil80.getCurrDateTime()).withSubject(username)
.withClaim("user_id", employeeId)
.withExpiresAt(DateUtil80.asDate(currentTime.plusMinutes(240))).sign(algorithm);
}
......@@ -111,7 +104,7 @@ public class JwtTokenUtil {
* @param username 用户名
* @return 加密的token
*/
public static String signByRememberMe(String username, Integer userId) throws UnsupportedEncodingException {
public static String signByRememberMe(String username, Integer userId) {
LocalDateTime currentTime = DateUtil80.getDateTimeOfTimestamp(System.currentTimeMillis());
Algorithm algorithm = Algorithm.HMAC512(jwtTokenSecret);
// 附带username信息
......
......@@ -86,11 +86,11 @@ public class TUser implements Serializable {
private Boolean permanent;
@ApiModelProperty("生效日期")
@TableField(value = "effective_date",updateStrategy = FieldStrategy.IGNORED)
@TableField(value = "effective_date", updateStrategy = FieldStrategy.IGNORED)
private LocalDate effectiveDate;
@ApiModelProperty("失效日期")
@TableField(value = "exired_date",updateStrategy = FieldStrategy.IGNORED)
@TableField(value = "exired_date", updateStrategy = FieldStrategy.IGNORED)
private LocalDate exiredDate;
@ApiModelProperty(value = "状态", allowableValues = "启用 ENABLE, 禁用DISABLE")
......@@ -137,7 +137,6 @@ public class TUser implements Serializable {
@TableField(exist = false)
private String orgName;
@ApiModelProperty("机构编码")
@TableField(exist = false)
private String orgCode;
......
......@@ -178,7 +178,6 @@ public class ChinaMobileRestApiController extends BaseController {
JSONObject resultMap = new JSONObject(true);
TUser user;
if (StringUtils.isNoneBlank(username)) {
try {
//访问一次,计数一次
// ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
......@@ -241,7 +240,8 @@ public class ChinaMobileRestApiController extends BaseController {
jsonObject.put("userName", user.getUserName());
jsonObject.put("expire", TimeUtils.format(LocalDateTime.now().plusMinutes(240), TimeUtils.FORMAT_ONE));
jsonObject.put("expireDate", user.getExiredDate());
jsonObject.put("orgCode", user.getOrgId());
jsonObject.put("orgId", user.getOrgId());
jsonObject.put("orgCode", user.getOrgCode());
jsonObject.put("orgName", user.getOrgName());
resultMap.put("resultCode", "200");
......
......@@ -45,7 +45,7 @@
</sql>
<select id="selectByUsername" resultMap="BaseResultMap">
select u.*,o.name org_name,a.full_name area_name,o.code org_code
select u.*, o.name org_name, o.code org_code, a.full_name area_name
from t_user u
left join t_organ o on o.id = u.org_id
left join t_area a on u.area_id = a.id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment