Skip to content

Commit 837df9d

Browse files
authored
Merge pull request #205 from prgrms-web-devcourse-final-project/refactor/deleted-member-redirect(WR9-117)
fix: 회원탈퇴 시 리디렉션 url 설정 (WR9-120)
2 parents 5232aa8 + e539912 commit 837df9d

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

src/main/java/io/crops/warmletter/global/config/SecurityConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
7878
.oauth2Login(oauth2 -> oauth2
7979
.userInfoEndpoint(userInfo -> userInfo
8080
.userService(customOAuth2UserService))
81-
// 나중에 Handler 구현 후 추가될 부분
8281
.successHandler(customOAuth2AuthenticationSuccessHandler)
8382
.failureHandler(oAuth2AuthenticationFailureHandler)
8483
).addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.crops.warmletter.global.oauth.entity;
2+
3+
import org.springframework.security.core.GrantedAuthority;
4+
import org.springframework.security.oauth2.core.user.OAuth2User;
5+
6+
import java.util.Collection;
7+
import java.util.Collections;
8+
import java.util.Map;
9+
10+
public class OAuth2UserWithDeletedFlag implements OAuth2User {
11+
12+
private final Map<String, Object> attributes;
13+
private final String email;
14+
15+
public OAuth2UserWithDeletedFlag(Map<String, Object> attributes, String email) {
16+
this.attributes = attributes;
17+
this.email = email;
18+
}
19+
20+
@Override
21+
public Map<String, Object> getAttributes() {
22+
return attributes;
23+
}
24+
25+
@Override
26+
public Collection<? extends GrantedAuthority> getAuthorities() {
27+
// 권한 없음
28+
return Collections.emptyList();
29+
}
30+
31+
@Override
32+
public String getName() {
33+
return email;
34+
}
35+
36+
// 탈퇴 회원 여부 확인용 메서드
37+
public boolean isDeletedMember() {
38+
return true;
39+
}
40+
}

src/main/java/io/crops/warmletter/global/oauth/handler/CustomOAuth2AuthenticationSuccessHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.crops.warmletter.global.oauth.handler;
22

33
import io.crops.warmletter.global.jwt.service.TokenStorage;
4+
import io.crops.warmletter.global.oauth.entity.OAuth2UserWithDeletedFlag;
45
import io.crops.warmletter.global.oauth.entity.UserPrincipal;
56
import jakarta.servlet.ServletException;
67
import jakarta.servlet.http.HttpServletRequest;
@@ -27,6 +28,16 @@ public class CustomOAuth2AuthenticationSuccessHandler extends SavedRequestAwareA
2728

2829
@Override
2930
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
31+
32+
Object principal = authentication.getPrincipal();
33+
34+
// 탈퇴 회원인 경우 특별 처리
35+
if (principal instanceof OAuth2UserWithDeletedFlag) {
36+
String redirectUrl = redirectUri + "/auth-callback?error=deleted_member";
37+
getRedirectStrategy().sendRedirect(request, response, redirectUrl);
38+
return;
39+
}
40+
3041
oAuth2AuthenticationSuccessHandler.onAuthenticationSuccess(request, response, null, authentication); // 기존 successHandler 호출
3142

3243
// Access Token을 Authorization 헤더에서 가져오기

src/main/java/io/crops/warmletter/global/oauth/service/CustomOAuth2UserService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import io.crops.warmletter.domain.member.entity.SocialAccount;
55
import io.crops.warmletter.domain.member.enums.Role;
66
import io.crops.warmletter.domain.member.enums.SocialProvider;
7-
import io.crops.warmletter.domain.member.exception.DeletedMemberException;
87
import io.crops.warmletter.domain.member.facade.MemberFacade;
98
import io.crops.warmletter.domain.member.repository.MemberRepository;
9+
import io.crops.warmletter.global.oauth.entity.OAuth2UserWithDeletedFlag;
1010
import io.crops.warmletter.global.oauth.entity.UserPrincipal;
1111
import io.crops.warmletter.global.oauth.exception.OAuth2EmailNotFoundException;
1212
import io.crops.warmletter.global.oauth.exception.OAuth2ProcessingException;
@@ -23,6 +23,7 @@
2323
import org.springframework.transaction.annotation.Transactional;
2424
import org.springframework.util.StringUtils;
2525

26+
import java.util.Map;
2627
import java.util.Optional;
2728

2829
@Service
@@ -89,7 +90,7 @@ private OAuth2User process(OAuth2UserRequest userRequest, OAuth2User oauth2User)
8990

9091
// 탈퇴한 회원인지 확인
9192
if (!member.isActive()) {
92-
throw new DeletedMemberException();
93+
return createDeletedMemberPrincipal(oauth2User.getAttributes(), email);
9394
}
9495

9596
// 이메일이 변경되었을 경우 업데이트
@@ -106,4 +107,11 @@ private OAuth2User process(OAuth2UserRequest userRequest, OAuth2User oauth2User)
106107
return UserPrincipal.create(member, oauth2User.getAttributes());
107108
}
108109

110+
// 탈퇴한 회원용 특별한 UserPrincipal 생성
111+
private OAuth2User createDeletedMemberPrincipal(Map<String, Object> attributes, String email) {
112+
// 권한 없는 특별한 UserPrincipal 객체 생성
113+
// 이 객체는 나중에 CustomOAuth2AuthenticationSuccessHandler에서
114+
// 특별 처리될 수 있음
115+
return new OAuth2UserWithDeletedFlag(attributes, email);
116+
}
109117
}

0 commit comments

Comments
 (0)