diff --git a/client/src/components/MyPage/MyPage.js b/client/src/components/MyPage/MyPage.js index 6c264ffc..4ec49af2 100644 --- a/client/src/components/MyPage/MyPage.js +++ b/client/src/components/MyPage/MyPage.js @@ -68,7 +68,7 @@ function MyPage() { const [withdrawModal, setWithdrawModal] = useState(false); - const [accompanyList, setAccompanyList] = useState(["안녕하세요","안녕하세요","안녕하세요","안녕하세요","안녕하세요"]) // 동행 신청 현황 + const [accompanyList, setAccompanyList] = useState(["1","2","3","4","5"]) // 동행 신청 현황 var ranklist = ""; var size = posts.length; @@ -505,13 +505,33 @@ function MyPage() { - {item} - - + + + + + Find Password + + +
+ + +
+
+
diff --git a/src/main/java/GraduationProject/TripPlannerZ/RedisConfig.java b/src/main/java/GraduationProject/TripPlannerZ/RedisConfig.java index 027d22ef..30b1f982 100644 --- a/src/main/java/GraduationProject/TripPlannerZ/RedisConfig.java +++ b/src/main/java/GraduationProject/TripPlannerZ/RedisConfig.java @@ -33,6 +33,12 @@ public RedisConnectionFactory redisConnectionFactory() { return redisTemplate; } + @Bean + public RedisTemplate blackList() { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory((redisConnectionFactory())); + return redisTemplate; + } } diff --git a/src/main/java/GraduationProject/TripPlannerZ/config/JwtAuthFilter.java b/src/main/java/GraduationProject/TripPlannerZ/config/JwtAuthFilter.java index dd6dbb70..028c89bb 100644 --- a/src/main/java/GraduationProject/TripPlannerZ/config/JwtAuthFilter.java +++ b/src/main/java/GraduationProject/TripPlannerZ/config/JwtAuthFilter.java @@ -1,5 +1,6 @@ package GraduationProject.TripPlannerZ.config; +import GraduationProject.TripPlannerZ.util.RedisUtil; import jakarta.servlet.Filter; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; @@ -16,6 +17,7 @@ public class JwtAuthFilter extends OncePerRequestFilter { private final UserAuthProvider userAuthProvider; + private final RedisUtil redisUtil; @Override protected void doFilterInternal(HttpServletRequest request, @@ -29,6 +31,12 @@ protected void doFilterInternal(HttpServletRequest request, String[] elements = header.split(" "); System.out.println("elements[1] = " + elements[1]); + if (elements.length == 2 && "Bearer".equals(elements[0])) { + if (redisUtil.existBlackList(elements[1])) { + throw new RuntimeException("유효하지 않은 토큰 입니다."); + } + } + // key가 Bearer이고 value가 멤버의 토큰값 if (elements.length == 2 && "Bearer".equals(elements[0])) { try { diff --git a/src/main/java/GraduationProject/TripPlannerZ/config/SecurityConfig.java b/src/main/java/GraduationProject/TripPlannerZ/config/SecurityConfig.java index 69110953..0fc39855 100644 --- a/src/main/java/GraduationProject/TripPlannerZ/config/SecurityConfig.java +++ b/src/main/java/GraduationProject/TripPlannerZ/config/SecurityConfig.java @@ -1,5 +1,6 @@ package GraduationProject.TripPlannerZ.config; +import GraduationProject.TripPlannerZ.util.RedisUtil; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -17,13 +18,14 @@ public class SecurityConfig { private final UserAuthenticationEntryPoint userAuthenticationEntryPoint; private final UserAuthProvider userAuthProvider; + private final RedisUtil redisUtil; @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http .exceptionHandling().authenticationEntryPoint(userAuthenticationEntryPoint) .and() - .addFilterBefore(new JwtAuthFilter(userAuthProvider), BasicAuthenticationFilter.class) + .addFilterBefore(new JwtAuthFilter(userAuthProvider, redisUtil), BasicAuthenticationFilter.class) .csrf().disable() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() diff --git a/src/main/java/GraduationProject/TripPlannerZ/controller/MemberController.java b/src/main/java/GraduationProject/TripPlannerZ/controller/MemberController.java index ba646567..94c0743f 100644 --- a/src/main/java/GraduationProject/TripPlannerZ/controller/MemberController.java +++ b/src/main/java/GraduationProject/TripPlannerZ/controller/MemberController.java @@ -2,19 +2,15 @@ import GraduationProject.TripPlannerZ.config.UserAuthProvider; import GraduationProject.TripPlannerZ.domain.MemberPreference; -import GraduationProject.TripPlannerZ.dto.member.Credential; -import GraduationProject.TripPlannerZ.dto.member.MemberDto; -import GraduationProject.TripPlannerZ.dto.member.MemberRegister; +import GraduationProject.TripPlannerZ.dto.member.*; import GraduationProject.TripPlannerZ.domain.Member; -import GraduationProject.TripPlannerZ.dto.member.ChangeMemberInfo; import GraduationProject.TripPlannerZ.delete.MemberLogin; -import GraduationProject.TripPlannerZ.dto.member.MemberTrip; -import GraduationProject.TripPlannerZ.dto.member.MyPage; import GraduationProject.TripPlannerZ.service.*; import GraduationProject.TripPlannerZ.service.TripService; import GraduationProject.TripPlannerZ.sseEmitter.SseEmitterService; +import GraduationProject.TripPlannerZ.util.RedisUtil; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import lombok.RequiredArgsConstructor; @@ -38,12 +34,10 @@ public class MemberController { private final MemberService memberService; - private final LoginService loginService; - private final TripService tripService; private final MemberPreferenceService memberPreferenceService; private final UserAuthProvider userAuthProvider; private final SseEmitterService sseEmitterService; - private final PartyService partyService; + private final AuthService authService; @@ -81,12 +75,10 @@ public SseEmitter subscribe() { } - @GetMapping("/members/logout") - public void logout(HttpServletRequest request) { - HttpSession session = request.getSession(false); - - if (session != null) - session.invalidate(); + @PostMapping("/members/logout") + public void logout(@RequestBody BlackList blackList) { + System.out.println("blackList.getToken() = " + blackList.getToken()); + authService.logout(blackList.getToken()); } @GetMapping("/members/tripInfo") diff --git a/src/main/java/GraduationProject/TripPlannerZ/dto/member/BlackList.java b/src/main/java/GraduationProject/TripPlannerZ/dto/member/BlackList.java new file mode 100644 index 00000000..61fab027 --- /dev/null +++ b/src/main/java/GraduationProject/TripPlannerZ/dto/member/BlackList.java @@ -0,0 +1,13 @@ +package GraduationProject.TripPlannerZ.dto.member; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BlackList { + + private String token; +} diff --git a/src/main/java/GraduationProject/TripPlannerZ/service/AuthService.java b/src/main/java/GraduationProject/TripPlannerZ/service/AuthService.java new file mode 100644 index 00000000..1668cf9c --- /dev/null +++ b/src/main/java/GraduationProject/TripPlannerZ/service/AuthService.java @@ -0,0 +1,16 @@ +package GraduationProject.TripPlannerZ.service; + +import GraduationProject.TripPlannerZ.util.RedisUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class AuthService { + + private final RedisUtil redisUtil; + + public void logout(String accessToken) { + redisUtil.setBlackList(accessToken, "BlackList", 3_600_000); + } +} diff --git a/src/main/java/GraduationProject/TripPlannerZ/util/RedisUtil.java b/src/main/java/GraduationProject/TripPlannerZ/util/RedisUtil.java index eac82a83..8b3e9ff0 100644 --- a/src/main/java/GraduationProject/TripPlannerZ/util/RedisUtil.java +++ b/src/main/java/GraduationProject/TripPlannerZ/util/RedisUtil.java @@ -14,6 +14,7 @@ public class RedisUtil { private final StringRedisTemplate redisTemplate; + private final StringRedisTemplate blackList; public String getData(String key) { ValueOperations valueOperations = redisTemplate.opsForValue(); @@ -27,6 +28,12 @@ public void setDataExpire(String key, String value, long duration) { valueOperations.set(key, value, expireDuration); } + public void setBlackList(String key, String value, long duration) { + ValueOperations valueOperations = blackList.opsForValue(); + Duration expireDuration = Duration.ofSeconds(duration); + valueOperations.set(key, "BlackList", expireDuration); + } + public void deleteData(String key) { // 데이터 삭제 redisTemplate.delete(key); @@ -36,4 +43,8 @@ public boolean existData(String key) { return Boolean.TRUE.equals(redisTemplate.hasKey(key)); } + public boolean existBlackList(String key) { + return Boolean.TRUE.equals(blackList.hasKey(key)); + } + }