Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#765] Redis Token 저장시 TTL 설정되도록 리팩토링 #766

Merged
merged 1 commit into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/pick-git/security
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.woowacourse.pickgit.authentication.domain.OAuthAccessTokenDao;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
Expand All @@ -10,14 +12,24 @@
public class RedisOAuthAccessTokenDao implements OAuthAccessTokenDao {

private final ValueOperations<String, String> opsForValue;
private final long expirationTimeInMilliSeconds;

public RedisOAuthAccessTokenDao(StringRedisTemplate redisTemplate) {
public RedisOAuthAccessTokenDao(
StringRedisTemplate redisTemplate,
@Value("${security.jwt.expiration-time}") long expirationTimeInMilliSeconds
) {
this.opsForValue = redisTemplate.opsForValue();
this.expirationTimeInMilliSeconds = expirationTimeInMilliSeconds;
}

@Override
public void insert(String token, String oauthAccessToken) {
opsForValue.set(token, oauthAccessToken);
opsForValue.set(
token,
oauthAccessToken,
expirationTimeInMilliSeconds,
TimeUnit.MILLISECONDS
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.woowacourse.pickgit.user.domain.User;
import com.woowacourse.pickgit.user.domain.repository.UserRepository;
import com.woowacourse.pickgit.user.domain.search.UserSearchEngine;
import java.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -65,7 +66,10 @@ void setUp() {
SECRET_KEY,
EXPIRATION_TIME_IN_MILLISECONDS
);
this.oAuthAccessTokenDao = new RedisOAuthAccessTokenDao(redisTemplate);
this.oAuthAccessTokenDao = new RedisOAuthAccessTokenDao(
redisTemplate,
Duration.ofHours(3).toMillis()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럼 AT은 3시간 동안 유지되는 건가요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵넵! 현재 토큰의 유효기간도 3시간이기때문에 동일하게 해두었습니다~

);
this.oAuthService = new OAuthService(
oAuthClient,
jwtTokenProvider,
Expand Down