Skip to content

Commit

Permalink
feat kookmin-sw#2 - 시큐리티 설정 변경
Browse files Browse the repository at this point in the history
기존에 SecurityConfig 클래스 안에 빈으로 등록하여 oauth2service를 사용하였는데 구조가 변경되면서 @service로 등록한 CustomOAuth2Service를 사용하도록 변경함
  • Loading branch information
leejh7 committed Mar 10, 2024
1 parent 1e4f192 commit 2836108
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/main/java/org/capstone/maru/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@


import lombok.extern.slf4j.Slf4j;
import org.capstone.maru.dto.security.KakaoOAuth2Response;
import org.capstone.maru.dto.security.SharedPostPrincipal;
import org.capstone.maru.security.CustomOAuth2UserService;
import org.capstone.maru.security.KakaoOAuth2Response;
import org.capstone.maru.security.SharedPostPrincipal;
import org.capstone.maru.service.MemberAccountService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
Expand All @@ -28,15 +29,14 @@ public class SecurityConfig {
@ConditionalOnProperty(name = "spring.h2.console.enabled", havingValue = "true")
public WebSecurityCustomizer configureH2ConsoleEnable() {
return web -> web.ignoring()
.requestMatchers(PathRequest.toH2Console());
.requestMatchers(PathRequest.toH2Console());
}

@Bean
public SecurityFilterChain securityFilterChain(
HttpSecurity httpSecurity,
OAuth2UserService<OAuth2UserRequest, OAuth2User> oAuth2UserService
CustomOAuth2UserService customOAuth2UserService
) throws Exception {
log.info("SecurityFilterChain 빈 등록 완료");
return httpSecurity
.authorizeHttpRequests(auth -> auth
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
Expand All @@ -48,7 +48,7 @@ public SecurityFilterChain securityFilterChain(
)
.oauth2Login(oAuth -> oAuth
.userInfoEndpoint(userInfo -> userInfo
.userService(oAuth2UserService)
.userService(customOAuth2UserService)
)
)
.csrf(
Expand All @@ -59,7 +59,6 @@ public SecurityFilterChain securityFilterChain(
.build();
}


@Bean
public OAuth2UserService<OAuth2UserRequest, OAuth2User> oAuth2UserService(
MemberAccountService memberAccountService,
Expand All @@ -74,7 +73,7 @@ public OAuth2UserService<OAuth2UserRequest, OAuth2User> oAuth2UserService(
oAuth2User.getAttributes());

String registrationId = userRequest.getClientRegistration()
.getRegistrationId(); // "kakao"
.getRegistrationId(); // "kakao"

String providerId = String.valueOf(kakaoOAuthResponse.id());
String memberId = registrationId + "_" + providerId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.capstone.maru.controller;

import org.capstone.maru.dto.security.SharedPostPrincipal;
import org.capstone.maru.security.SharedPostPrincipal;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -17,5 +17,5 @@ public String root() {
public String test(@AuthenticationPrincipal SharedPostPrincipal sharedPostPrincipal) {
return sharedPostPrincipal.getName();
}

}

0 comments on commit 2836108

Please sign in to comment.