-
Notifications
You must be signed in to change notification settings - Fork 0
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
π λ‘κ·Έμμ κΈ°λ₯ ꡬν #10
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b784c2b
add :: RedisProperties
ta2ye0n 3d84b50
add :: RedisConfig
ta2ye0n f38d088
add :: RedisUtil
ta2ye0n feba8b9
add :: UserUtil
ta2ye0n ebd5e20
add :: LogoutService
ta2ye0n 025a63c
add :: endpoint μ€μ
ta2ye0n 4350cd3
refactor :: @Transactional
ta2ye0n 46a9d0c
delete :: deleteBlackList λ©μλ
ta2ye0n 916008b
refactor :: μ΄λ
Έν
μ΄μ
μμ
ta2ye0n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/gcms/v3/domain/auth/service/LogoutService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.gcms.v3.domain.auth.service; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
|
||
public interface LogoutService { | ||
void execute(HttpServletRequest request); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/gcms/v3/domain/auth/service/impl/LogoutServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.gcms.v3.domain.auth.service.impl; | ||
|
||
import com.gcms.v3.domain.auth.domain.entity.RefreshToken; | ||
import com.gcms.v3.domain.auth.domain.repository.RefreshTokenRepository; | ||
import com.gcms.v3.domain.auth.exception.UserNotFoundException; | ||
import com.gcms.v3.domain.auth.service.LogoutService; | ||
import com.gcms.v3.domain.user.domain.entity.User; | ||
import com.gcms.v3.domain.user.util.UserUtil; | ||
import com.gcms.v3.global.redis.RedisUtil; | ||
import com.gcms.v3.global.security.jwt.JwtTokenProvider; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Transactional | ||
public class LogoutServiceImpl implements LogoutService { | ||
|
||
private final UserUtil userUtil; | ||
private final RefreshTokenRepository refreshTokenRepository; | ||
private final JwtTokenProvider jwtTokenProvider; | ||
private final RedisUtil redisUtil; | ||
|
||
public void execute(HttpServletRequest request) { | ||
String accessToken = jwtTokenProvider.resolveToken(request); | ||
|
||
User user = userUtil.getCurrentUser(); | ||
|
||
RefreshToken refreshToken = refreshTokenRepository.findByEmail(user.getEmail()) | ||
.orElseThrow(UserNotFoundException::new); | ||
|
||
refreshTokenRepository.delete(refreshToken); | ||
|
||
redisUtil.setBlackList(accessToken, "access_token", jwtTokenProvider.getExpiration(accessToken)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.gcms.v3.domain.user.util; | ||
|
||
import com.gcms.v3.domain.auth.exception.UserNotFoundException; | ||
import com.gcms.v3.domain.user.domain.entity.User; | ||
import com.gcms.v3.domain.user.domain.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UserUtil { | ||
|
||
private final UserRepository userRepository; | ||
|
||
public User getCurrentUser() { | ||
String email = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
return userRepository.findByEmail(email) | ||
.orElseThrow(UserNotFoundException::new); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gcms.v3.global.redis; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class RedisConfig { | ||
private final RedisProperties redisProperties; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(redisProperties.host(), redisProperties.port()); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, Object> redisTemplate() { | ||
RedisTemplate<String, Object> template = new RedisTemplate<>(); | ||
template.setValueSerializer(new StringRedisSerializer()); | ||
template.setHashValueSerializer(new StringRedisSerializer()); | ||
template.setConnectionFactory(redisConnectionFactory()); | ||
template.setEnableTransactionSupport(true); | ||
return template; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/gcms/v3/global/redis/RedisProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.gcms.v3.global.redis; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "spring.data.redis") | ||
KimTaeO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public record RedisProperties ( | ||
String host, | ||
int port | ||
){ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.gcms.v3.global.redis; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class RedisUtil { | ||
|
||
private final RedisTemplate<String, Object> redisBlackListTemplate; | ||
|
||
public boolean checkExistsValue(String value) { | ||
return !value.equals("false"); | ||
} | ||
|
||
public void setBlackList(String key, Object o, Long milliSeconds) { | ||
redisBlackListTemplate.setValueSerializer(new Jackson2JsonRedisSerializer(o.getClass())); | ||
redisBlackListTemplate.opsForValue().set(key, o, milliSeconds, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
public Object getBlackList(String key) { | ||
return redisBlackListTemplate.opsForValue().get(key); | ||
} | ||
|
||
public boolean hasKeyBlackList(String key) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ©μλλͺ ... λκ° κ΅¬λ¦½λλ€ |
||
return redisBlackListTemplate.hasKey(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ¬κΈ°μ template.setEnableTransactionSupport(true); νμ λ€μμ Service ν΄λμ€μ @transactional μ΄λ Έν μ΄μ λΆμ¬μ£Όλκ² μ’μ보μ¬μ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4350cd3
μΆκ°νμ΅λλ€
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@transactionμ Config λ©μλκ° μλλΌ LogOutServiceService ν΄λμ€μ λΆμ¬μ£ΌμΈμ!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
916008b
μμ νμ΅λλ€!