org.zodiac.autoconfigure.security.jwt.SecurityJwtAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.security.jwt;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.zodiac.autoconfigure.security.condition.ConditionalOnSecurityJwtEnabled;
/**
* Jwt配置类
*
*/
@SpringBootConfiguration
@ConditionalOnSecurityJwtEnabled
//@AutoConfigureAfter(value = {SecurityJwtRedisAutoConfiguration.class})
//@EnableConfigurationProperties(value = {SecurityJwtProperties.class})
@ConditionalOnClass(value = {org.zodiac.security.util.SecurityJwtUtil.class, org.springframework.data.redis.connection.RedisConnectionFactory.class, org.springframework.data.redis.core.RedisOperations.class})
public class SecurityJwtAutoConfiguration implements SmartInitializingSingleton {
private final SecurityJwtProperties securityJwtProperties;
private final org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory;
public SecurityJwtAutoConfiguration(SecurityJwtProperties securityJwtProperties,
org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory) {
this.securityJwtProperties = securityJwtProperties;
this.redisConnectionFactory = redisConnectionFactory;
}
@Override
public void afterSingletonsInstantiated() {
/*redisTemplate 实例化*/
org.springframework.data.redis.core.RedisTemplate redisTemplate = new org.springframework.data.redis.core.RedisTemplate<>();
org.zodiac.security.jwt.serializer.JwtRedisKeySerializer redisKeySerializer = new org.zodiac.security.jwt.serializer.JwtRedisKeySerializer();
org.springframework.data.redis.serializer.JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new org.springframework.data.redis.serializer.JdkSerializationRedisSerializer();
/*key 序列化*/
redisTemplate.setKeySerializer(redisKeySerializer);
redisTemplate.setHashKeySerializer(redisKeySerializer);
/*value 序列化*/
redisTemplate.setValueSerializer(jdkSerializationRedisSerializer);
redisTemplate.setHashValueSerializer(jdkSerializationRedisSerializer);
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.afterPropertiesSet();
org.zodiac.security.util.SecurityJwtUtil.setSecurityJwtInfo(securityJwtProperties);
org.zodiac.security.util.SecurityJwtUtil.setRedisTemplate(redisTemplate);
}
}