This commit is contained in:
MicLng committed 2021-10-26 12:53:59 +08:00
commit 42b5ee41da
1 file changed
+13 -1
@@ -4,8 +4,11 @@ import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import lombok.Cleanup;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStringCommands;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.code.RandomValueAuthorizationCodeServices;
import org.springframework.security.oauth2.provider.token.store.redis.JdkSerializationStrategy;
@@ -22,6 +25,12 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class PigxAuthorizationCodeServicesImpl extends RandomValueAuthorizationCodeServices {
/**
* 授权码模式时: 验证码有效期设置, 默认有效期为5分钟, 单位秒
*/
@Value("${pigx.authorizationCode.expirationTime:300}")
private Long expirationTime;
private final RedisConnectionFactory connectionFactory;
@Setter
@@ -39,7 +48,10 @@ public class PigxAuthorizationCodeServicesImpl extends RandomValueAuthorizationC
protected void store(String code, OAuth2Authentication authentication) {
@Cleanup
RedisConnection connection = connectionFactory.getConnection();
connection.set(serializationStrategy.serialize(prefix + code), serializationStrategy.serialize(authentication));
connection.set(serializationStrategy.serialize(prefix + code),
serializationStrategy.serialize(authentication),
Expiration.seconds(expirationTime),
RedisStringCommands.SetOption.UPSERT);
}
/**