diff --git a/chatting-api/src/main/resources/application.yml b/chatting-api/src/main/resources/application.yml index 5ef9b59..bef66c3 100644 --- a/chatting-api/src/main/resources/application.yml +++ b/chatting-api/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8080 + port: 8090 spring: kafka: group-id: group-simple-chatting diff --git a/chatting-stream-server/build.gradle b/chatting-stream-server/build.gradle index d60bede..94748b9 100644 --- a/chatting-stream-server/build.gradle +++ b/chatting-stream-server/build.gradle @@ -4,7 +4,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-websocket' implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' testImplementation 'org.springframework.kafka:spring-kafka-test' } diff --git a/chatting-stream-server/src/main/java/com/cjw/chatting/config/security/ChattingOAuth2UserService.java b/chatting-stream-server/src/main/java/com/cjw/chatting/config/security/ChattingOAuth2UserService.java new file mode 100644 index 0000000..d10e11c --- /dev/null +++ b/chatting-stream-server/src/main/java/com/cjw/chatting/config/security/ChattingOAuth2UserService.java @@ -0,0 +1,18 @@ +package com.cjw.chatting.config.security; + +import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; +import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest; +import org.springframework.security.oauth2.core.OAuth2AuthenticationException; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.stereotype.Service; + +@Service +public class ChattingOAuth2UserService extends DefaultOAuth2UserService { + @Override + public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { + OAuth2User oAuth2User = super.loadUser(userRequest); + //custom한 로직 작성 + + return oAuth2User; + } +} diff --git a/chatting-stream-server/src/main/java/com/cjw/chatting/config/security/SecurityConfig.java b/chatting-stream-server/src/main/java/com/cjw/chatting/config/security/SecurityConfig.java index a5f22f7..75d2b06 100644 --- a/chatting-stream-server/src/main/java/com/cjw/chatting/config/security/SecurityConfig.java +++ b/chatting-stream-server/src/main/java/com/cjw/chatting/config/security/SecurityConfig.java @@ -1,15 +1,20 @@ package com.cjw.chatting.config.security; +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; +@RequiredArgsConstructor +@EnableWebSecurity @Configuration public class SecurityConfig { + private final ChattingOAuth2UserService chattingOAuth2UserService; + @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http @@ -17,14 +22,23 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { a.anyRequest().permitAll()) .csrf(AbstractHttpConfigurer::disable) .formLogin(AbstractHttpConfigurer::disable) - .httpBasic(AbstractHttpConfigurer::disable); + .httpBasic(AbstractHttpConfigurer::disable) + .oauth2Login(config -> { + config + .loginPage("/login") + .userInfoEndpoint(userInfoEndpointConfig -> + userInfoEndpointConfig.userService(chattingOAuth2UserService)) + .successHandler(successHandler()) + ; //커스텀 userService 등록 + + }); + return http.build(); } - @Bean - public AuthenticationManager authenticationManager(HttpSecurity httpSecurity) throws Exception { - AuthenticationManagerBuilder authenticationManagerBuilder = httpSecurity.getSharedObject(AuthenticationManagerBuilder.class); - authenticationManagerBuilder.authenticationProvider(null); - return authenticationManagerBuilder.build(); + public AuthenticationSuccessHandler successHandler() { + return ((request, response, authentication) -> { + //response.sendRedirect("https://naver.com"); + }); } } diff --git a/chatting-stream-server/src/main/resources/application.yml b/chatting-stream-server/src/main/resources/application.yml index 7b0a0f0..a61a835 100644 --- a/chatting-stream-server/src/main/resources/application.yml +++ b/chatting-stream-server/src/main/resources/application.yml @@ -1,5 +1,15 @@ server: - port: 8090 + port: 8080 spring: kafka: - group-id: group-simple-chatting \ No newline at end of file + group-id: group-simple-chatting + security: + oauth2: + client: + registration: + google: + client-id: 1001974487126-fcm3n94a02tuhffrv59fssrc6e5hsig0.apps.googleusercontent.com + client-secret: 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 + scope: + - profile + - email \ No newline at end of file diff --git a/core/src/main/resources/application-core.yml b/core/src/main/resources/application-core.yml index 4e2b2a0..9bcd8b1 100644 --- a/core/src/main/resources/application-core.yml +++ b/core/src/main/resources/application-core.yml @@ -1,10 +1,10 @@ spring: datasource: hikari: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/jpa?serverTimezone=UTC&characterEncoding=UTF-8 + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://localhost:8889/chatting?serverTimezone=UTC&characterEncoding=UTF-8 username: root - password: awdsd123 + password: root jpa: hibernate: naming: