【auth】auth默认集成jwt,并设置jwt时间和记住我功能的时间

pull/3/head
fengshuonan 2021-01-02 19:07:54 +08:00
parent 1a303301fd
commit 75ae49bfa9
4 changed files with 70 additions and 1 deletions

View File

@ -43,4 +43,9 @@ public interface AuthConstants {
*/
String DEFAULT_PASSWORD = "123456";
/**
* authjwt7
*/
Long DEFAULT_AUTH_JWT_TIMEOUT_SECONDS = 3600L * 24 * 7;
}

View File

@ -1,5 +1,6 @@
package cn.stylefeng.roses.kernel.auth.api.expander;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.config.api.context.ConfigContext;
@ -31,12 +32,43 @@ public class AuthConfigExpander {
}
}
/**
* authjwt
*
* @author fengshuonan
* @date 2021/1/2 18:52
*/
public static String getAuthJwtSecret() {
String sysJwtSecret = ConfigContext.me().getConfigValueNullable("SYS_AUTH_JWT_SECRET", String.class);
// 没配置就返回一个随机密码
if (sysJwtSecret == null) {
return RandomUtil.randomString(20);
} else {
return sysJwtSecret;
}
}
/**
* authjwt
* <p>
* 7
* <p>
* 7
*
* @author fengshuonan
* @date 2021/1/2 18:53
*/
public static Long getAuthJwtTimeoutSeconds() {
return ConfigContext.me().getSysConfigValueWithDefault("SYS_AUTH_JWT_TIMEOUT_SECONDS", Long.class, DEFAULT_AUTH_JWT_TIMEOUT_SECONDS);
}
/**
* session3600
* <p>
* 线
* <p>
*
* sessionsession
*
* @author fengshuonan
* @date 2020/10/20 9:32

View File

@ -31,6 +31,13 @@
<version>1.0.0</version>
</dependency>
<!--jwt的sdk-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>jwt-sdk</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>

View File

@ -15,6 +15,9 @@ import cn.stylefeng.roses.kernel.auth.session.cache.logintoken.MemoryLoginTokenC
import cn.stylefeng.roses.kernel.auth.session.cache.loginuser.MemoryLoginUserCache;
import cn.stylefeng.roses.kernel.auth.session.cookie.DefaultSessionCookieCreator;
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
import cn.stylefeng.roses.kernel.jwt.JwtTokenOperator;
import cn.stylefeng.roses.kernel.jwt.api.JwtApi;
import cn.stylefeng.roses.kernel.jwt.api.pojo.config.JwtConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -31,6 +34,25 @@ import java.util.Set;
@Configuration
public class GunsAuthAutoConfiguration {
/**
* jwt
*
* @author fengshuonan
* @date 2020/12/1 14:40
*/
@Bean
@ConditionalOnMissingBean(SessionManagerApi.class)
public JwtApi jwtApi() {
JwtConfig jwtConfig = new JwtConfig();
// 从系统配置表中读取配置
jwtConfig.setJwtSecret(AuthConfigExpander.getAuthJwtSecret());
jwtConfig.setExpiredSeconds(AuthConfigExpander.getAuthJwtTimeoutSeconds());
return new JwtTokenOperator(jwtConfig);
}
/**
* Bcrypt
*
@ -38,6 +60,7 @@ public class GunsAuthAutoConfiguration {
* @date 2020/12/21 17:45
*/
@Bean
@ConditionalOnMissingBean(SessionManagerApi.class)
public PasswordStoredEncryptApi passwordStoredEncryptApi() {
return new BcryptPasswordStoredEncrypt();
}
@ -49,6 +72,7 @@ public class GunsAuthAutoConfiguration {
* @date 2020/12/21 17:45
*/
@Bean
@ConditionalOnMissingBean(SessionManagerApi.class)
public PasswordTransferEncryptApi passwordTransferEncryptApi() {
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCytSVn3ff7eBJckAFYwgJjqE9Zq2uAL4g+hkfQqGALdT8NJKALFxNzeSD/xTBLAJrtALWbN1dvyktoVNPAuuzCZO1BxYZNaAU3IKFaj73OSPzca5SGY0ibMw0KvEPkC3sZQeqBqx+VqYAqan90BeG/r9p36Eb0wrshj5XmsFeo6QIDAQAB";
String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALK1JWfd9/t4ElyQAVjCAmOoT1mra4AviD6GR9CoYAt1Pw0koAsXE3N5IP/FMEsAmu0AtZs3V2/KS2hU08C67MJk7UHFhk1oBTcgoVqPvc5I/NxrlIZjSJszDQq8Q+QLexlB6oGrH5WpgCpqf3QF4b+v2nfoRvTCuyGPleawV6jpAgMBAAECgYBS9fUfetQcUWl0vwVhBu/FA+WSYxnMsEQ3gm7kVsX/i7Zxi4cgnt3QxXKkSg5ZQzaov6OPIuncY7UOAhMrbZtq/Hh8atdTVC/Ng/X9Bomodplq/+KTe/vIfWW5rlQAnMNFVaidxhCVRlRHNusapmj2vYwsiyI9kXUJNHryxtFC4QJBANtQuh3dtd79t3MVaC3TUD/EsGBe9TB3Eykbgv0muannC2Oq8Ci4vIp0NSA+FNCoB8ctgfKJUdBS8RLVnYyu3RcCQQDQmY+AuAXEpO9SgcYeRnQSOU2OSuC1wLt1MRVpPTdvE3bfRnkVxMrK0n3YilQWkQzfkERSG4kRFLIw605xPWn/AkEAiw3vQ9p8Yyu5MiXDjTKrchMyxZfPnHATXQANmJcCJ0DQDtymMxuWp66wtIXIStgPPnGTMAVzM0Qzh/6bS0Tf9wJAWj+1yFjVlghNyoJ+9qZAnYnRNhjLM5dZAxDjVI65pwLi0SKqTHLB0hJThBYE32aODUNba7KiEJPFrEiBvZh2fQJARbboHuHT0PqD1UTJGgodHlaw48kreBU+twext/9/jIqvwmFF88BmQgssHGW/tn4E6Qy3+rCCNWreEReY0gATYw==";
@ -62,6 +86,7 @@ public class GunsAuthAutoConfiguration {
* @date 2020/12/27 15:48
*/
@Bean
@ConditionalOnMissingBean(SessionManagerApi.class)
public SessionCookieCreator sessionCookieCreator() {
return new DefaultSessionCookieCreator();
}