mirror of https://gitee.com/stylefeng/roses
【7.0.4】【jwt】增加一个工厂类
parent
f708fd496f
commit
6391776a08
|
@ -46,7 +46,12 @@ public enum JwtExceptionEnum implements AbstractExceptionEnum {
|
|||
/**
|
||||
* jwt过期了
|
||||
*/
|
||||
JWT_EXPIRED_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + JwtConstants.JWT_EXCEPTION_STEP_CODE + "02", "jwt过期了!jwt为:{}");
|
||||
JWT_EXPIRED_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + JwtConstants.JWT_EXCEPTION_STEP_CODE + "02", "jwt过期了!jwt为:{}"),
|
||||
|
||||
/**
|
||||
* jwt参数为空
|
||||
*/
|
||||
JWT_PARAM_EMPTY(RuleConstants.BUSINESS_ERROR_TYPE_CODE + JwtConstants.JWT_EXCEPTION_STEP_CODE + "03", "jwt解析时,秘钥或过期时间为空");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package cn.stylefeng.roses.kernel.jwt.factory;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.jwt.JwtTokenOperator;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.JwtApi;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.exception.JwtException;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.exception.enums.JwtExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.pojo.config.JwtConfig;
|
||||
|
||||
|
||||
/**
|
||||
* jwt token操作工具的生产工厂
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/21 18:15
|
||||
*/
|
||||
public class JwtTokenApiFactory {
|
||||
|
||||
/**
|
||||
* 根据jwt秘钥和过期时间,获取jwt操作的工具
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/21 18:16
|
||||
*/
|
||||
public static JwtApi createJwtApi(String jwtSecret, Integer expiredSeconds) {
|
||||
|
||||
if (ObjectUtil.hasEmpty(jwtSecret, expiredSeconds)) {
|
||||
throw new JwtException(JwtExceptionEnum.JWT_PARAM_EMPTY);
|
||||
}
|
||||
|
||||
JwtConfig jwtConfig = new JwtConfig();
|
||||
jwtConfig.setJwtSecret(jwtSecret);
|
||||
jwtConfig.setExpiredSeconds(expiredSeconds.longValue());
|
||||
|
||||
return new JwtTokenOperator(jwtConfig);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue