-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
server: | ||
port: 8080 | ||
port: 8090 | ||
spring: | ||
kafka: | ||
group-id: group-simple-chatting | ||
|
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
18 changes: 18 additions & 0 deletions
18
...ream-server/src/main/java/com/cjw/chatting/config/security/ChattingOAuth2UserService.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,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; | ||
} | ||
} |
30 changes: 22 additions & 8 deletions
30
chatting-stream-server/src/main/java/com/cjw/chatting/config/security/SecurityConfig.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 |
---|---|---|
@@ -1,30 +1,44 @@ | ||
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 | ||
.authorizeHttpRequests(a -> | ||
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"); | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
server: | ||
port: 8090 | ||
port: 8080 | ||
spring: | ||
kafka: | ||
group-id: group-simple-chatting | ||
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 | ||
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