mirror of https://gitee.com/stylefeng/roses
【8.0】【auth】经过初始化参数后,更新jwt秘钥参数
parent
f82d97b096
commit
7b62b050cb
|
@ -7,7 +7,9 @@ import cn.hutool.core.date.DateUtil;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.AuthJwtTokenApi;
|
import cn.stylefeng.roses.kernel.auth.api.AuthJwtTokenApi;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander;
|
import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.pojo.payload.DefaultJwtPayload;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.payload.DefaultJwtPayload;
|
||||||
|
import cn.stylefeng.roses.kernel.config.api.ConfigInitCallbackApi;
|
||||||
import cn.stylefeng.roses.kernel.jwt.api.JwtApi;
|
import cn.stylefeng.roses.kernel.jwt.api.JwtApi;
|
||||||
|
import cn.stylefeng.roses.kernel.jwt.api.pojo.config.JwtConfig;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -23,7 +25,7 @@ import java.util.Map;
|
||||||
* @since 2023/5/9 10:05
|
* @since 2023/5/9 10:05
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class AuthJwtTokenService implements AuthJwtTokenApi {
|
public class AuthJwtTokenService implements AuthJwtTokenApi, ConfigInitCallbackApi {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private JwtApi jwtApi;
|
private JwtApi jwtApi;
|
||||||
|
@ -53,4 +55,17 @@ public class AuthJwtTokenService implements AuthJwtTokenApi {
|
||||||
return BeanUtil.toBeanIgnoreError(jwtPayload, DefaultJwtPayload.class);
|
return BeanUtil.toBeanIgnoreError(jwtPayload, DefaultJwtPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initBefore() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initAfter() {
|
||||||
|
JwtConfig jwtConfig = new JwtConfig();
|
||||||
|
jwtConfig.setJwtSecret(AuthConfigExpander.getAuthJwtSecret());
|
||||||
|
jwtConfig.setExpiredSeconds(AuthConfigExpander.getAuthJwtTimeoutSeconds());
|
||||||
|
jwtApi.updateJwtConfig(jwtConfig);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
package cn.stylefeng.roses.kernel.jwt.api;
|
package cn.stylefeng.roses.kernel.jwt.api;
|
||||||
|
|
||||||
import cn.stylefeng.roses.kernel.jwt.api.exception.JwtException;
|
import cn.stylefeng.roses.kernel.jwt.api.exception.JwtException;
|
||||||
|
import cn.stylefeng.roses.kernel.jwt.api.pojo.config.JwtConfig;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -98,4 +99,12 @@ public interface JwtApi {
|
||||||
*/
|
*/
|
||||||
boolean validateTokenIsExpired(String token);
|
boolean validateTokenIsExpired(String token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新jwt的配置
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2023/7/12 11:34
|
||||||
|
*/
|
||||||
|
void updateJwtConfig(JwtConfig jwtConfig);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ import static cn.stylefeng.roses.kernel.jwt.api.exception.enums.JwtExceptionEnum
|
||||||
*/
|
*/
|
||||||
public class JwtTokenOperator implements JwtApi {
|
public class JwtTokenOperator implements JwtApi {
|
||||||
|
|
||||||
private final JwtConfig jwtConfig;
|
private JwtConfig jwtConfig;
|
||||||
|
|
||||||
public JwtTokenOperator(JwtConfig jwtConfig) {
|
public JwtTokenOperator(JwtConfig jwtConfig) {
|
||||||
this.jwtConfig = jwtConfig;
|
this.jwtConfig = jwtConfig;
|
||||||
|
@ -116,4 +116,9 @@ public class JwtTokenOperator implements JwtApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateJwtConfig(JwtConfig jwtConfig) {
|
||||||
|
this.jwtConfig = jwtConfig;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue