【7.0.4】【jwt】增加一个工厂类

pull/20/head
fengshuonan 2021-05-24 11:39:48 +08:00
parent f708fd496f
commit 6391776a08
2 changed files with 44 additions and 1 deletions

View File

@ -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解析时秘钥或过期时间为空");
/**
*

View File

@ -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 {
/**
* jwtjwt
*
* @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);
}
}