Commit 9f392bd3 authored by liqin's avatar liqin 💬

bug fixed

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