-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] 회원관리api에 redis추가, logout 구현
- Loading branch information
Showing
12 changed files
with
297 additions
and
133 deletions.
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
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
38 changes: 38 additions & 0 deletions
38
src/main/java/ewha/lux/once/domain/user/service/RedisService.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 ewha.lux.once.domain.user.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RedisService { | ||
private final RedisTemplate redisTemplate; | ||
private static final String REFRESH_TOKEN_PREFIX = "refreshToken:"; | ||
private static final String ACCESS_TOKEN_BLACKLIST_PREFIX = "blacklistAccessToken:"; | ||
|
||
|
||
public void setRefreshValueWithTTL(String user_id, String refreshToken, long timeout, TimeUnit unit) { | ||
String key = REFRESH_TOKEN_PREFIX + user_id; | ||
ValueOperations<String, Object> valueOperations = redisTemplate.opsForValue(); | ||
valueOperations.set(key, refreshToken, timeout, unit); | ||
} | ||
public void setAccessBlackValueWithTTL(String accessToken, String value, long timeout, TimeUnit unit) { | ||
String key = ACCESS_TOKEN_BLACKLIST_PREFIX + accessToken; | ||
ValueOperations<String, Object> valueOperations = redisTemplate.opsForValue(); | ||
valueOperations.set(key, value, timeout, unit); | ||
} | ||
|
||
public Object getValue(String key) { | ||
ValueOperations<String, Object> valueOperations = redisTemplate.opsForValue(); | ||
Object object = valueOperations.get(key); | ||
return object; | ||
} | ||
|
||
public void deleteValue(String key) { | ||
redisTemplate.delete(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
21 changes: 21 additions & 0 deletions
21
src/main/java/ewha/lux/once/global/config/JwtSecurityConfig.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,21 @@ | ||
package ewha.lux.once.global.config; | ||
|
||
import ewha.lux.once.domain.user.service.RedisService; | ||
import ewha.lux.once.global.security.JwtAuthFilter; | ||
import ewha.lux.once.global.security.JwtProvider; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.web.DefaultSecurityFilterChain; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
|
||
@RequiredArgsConstructor | ||
public class JwtSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> { | ||
private final JwtProvider jwtProvider; | ||
private final RedisService redisService; | ||
|
||
@Override | ||
public void configure(HttpSecurity http) throws Exception{ | ||
http.addFilterBefore(new JwtAuthFilter(jwtProvider, redisService), UsernamePasswordAuthenticationFilter.class); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/ewha/lux/once/global/config/RedisConfig.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,34 @@ | ||
package ewha.lux.once.global.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties; | ||
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.repository.configuration.EnableRedisRepositories; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
@EnableRedisRepositories | ||
public class RedisConfig { | ||
private final RedisProperties redisProperties; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(redisProperties.getHost(), redisProperties.getPort()); | ||
// return new LettuceConnectionFactory("localhost", redisProperties.getPort()); // 로컬 | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, Object> redisTemplate() { | ||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
return redisTemplate; | ||
} | ||
|
||
} |
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.