자체 로그인과 소셜 로그인 동시 설정 문의
자체 인증과 OAurh2 로 구글 자원 인가 설정을 진행하였습니다.
Spring Security 기본 설정에 oauth2Login 만 활성화 하면 Spring Boot 가 기본으로 설정하는 로그인 화면이 나옵니다.

Spring Security 설정
구글 계정으로 시스템 인증까지는 필요 없어 access token 받는것까지만 진행
@Bean
SecurityFilterChain configureHttp(HttpSecurity httpSecurity) throws Exception {
httpSecurity.oauth2Login(Customizer.withDefaults());
return httpSecurity.build();
}
하지만 기존 Spring Security 설정에 oauth2Login 를 활성화 하면 404 에외가 발생하고 있고 있어 디버깅 해보니 강의에 설명된 Spring Security의 OAuth2 Client 관련 필터에 진입하지 못하고 있습니다.
Spring Security 설정
@Bean
SecurityFilterChain configureHttp(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.headers()
.frameOptions()
.disable()
.and()
.httpBasic()
.disable() // rest api 이 므로 기본설정 사용안함..
.csrf()
.disable() // CSRF 설정 Disable
.cors()
.and()
.exceptionHandling()
.authenticationEntryPoint(authenticationErrorHandler) // 인증 예외 처리
.accessDeniedHandler(jwtAccessDeniedHandler) // 인사 예외 처리
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS) // JWT token으로 인증하여 세션을 사용하지 않기 때문에 세션 설정을 Stateless 로 설정
.and()
.authorizeRequests() // 권한을 설정
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll() // CORS preflight 요청은 인증 처리를 하지 않는다.
// 인증이 필요 없는 URI Pattern
.antMatchers("/openapi/**").permitAll()
.antMatchers("/**/login/**", "/**/mlogin/**").permitAll()
.antMatchers("/moblmdm/**").permitAll()
.antMatchers("/secuCert/**").permitAll()
.antMatchers("/moblview/**", "/moblsecu/**").permitAll()
.antMatchers("/websocket/**").permitAll()
// ADMIN Role을 가진 경우에만 접근을 허용한다.
//.antMatchers("/mng/**").hasAnyRole("ADMIN")
.anyRequest().authenticated()
.and()
.apply(securityConfigurerAdapter());
httpSecurity.oauth2Login(Customizer.withDefaults());
// httpSecurity
// .oauth2Login()
// .authorizationEndpoint()
// .authorizationRequestResolver((new CustomOAuth2AuthorizationRequestResolver(clientRegistrationRepository, DEFAULT_AUTHORIZATION_REQUEST_BASE_URI)))
// .and()
// .userInfoEndpoint()
// .userService(new CustomOAuth2UserService());
return httpSecurity.build();
}
질문) 자체 로그인 설정과 소셜 로그인을 동시에 사용 할 수 있는 설정을 문의 드립니다.
참고로 자체 로그인 설정과 소셜 로그인 설정을 분리하고 아래와 같이 소설 로그인 설정에 우선 순위를 주면 소셜 로그인 기능은 활성하 되는데 존 자체 로그인 기능은 비활성화 됩니다.
@Bean
@Order(0)
SecurityFilterChain configureOauth(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.oauth2Login()
// .loginPage("/login")
// .failureUrl("/login")
.authorizationEndpoint()
.authorizationRequestResolver((new CustomOAuth2AuthorizationRequestResolver(clientRegistrationRepository, DEFAULT_AUTHORIZATION_REQUEST_BASE_URI)))
.and()
.userInfoEndpoint()
.userService(new CustomOAuth2UserService());
return httpSecurity.build();
답변 1
0
내용에 대한 이해는 대략 했는데 실제 코드를 실행해 봐야 정확한 원인을 알 수 있을 것 같습니다.
가능하시다면 깃헙 소스 공유 부탁드립니다.
그리고 자체 로그인이라 하시면 어떤 인증을 의미하신는가요?
필터기반으로 JWT 인증방식의 기능을 구현하신건가요?
참고로
섹션 9. OAuth 2.0 Client - Social Login (Google, Naver, KaKao) + FormLogin
- OAuth 2.0 Social Login 연동 구현 (5)
- OAuth 2.0 Social Login 연동 구현 (6)
에 보시면 자체 로그인(FormLogin) 과 소셜 로그인을 통합하여 인증을 처리하는 내용을 설명하고 있으니 참고해 주시기 바랍니다.
0
일단은 해결하였습니다. 답변주셔서 감사합니다.
원인은
Spring Boot 2.6.13에서서 소스를 공개하기 위하여 회사 업무에 관련괸 소스를 제외하면서 JSP 사용을 위한 설정을 제외하니 OAuth 2 Client Flitter 들이 정상적으로 실행되어 JSP 설정을 추가하니 되었을OAuth 2 Client Flitter 가 실행되지 않아서 강의의 내용에서 사용된 버전과 동일한 2.7.5에서서는 JSP 사용을 위한 설정이 있어고 이상없이 동작하고 있습니다.
다만 ,
OAuth 2 Client 동작과 JSP 는 무관하고 Spring Security 5.7 과 Spring Boot 2.7 변경 내역을 살펴 보아도 JSP 관련 패치는 없어 이상하기는 합니다.
authorization-server 라이브러리 질문이 있습니다.
0
78
1
loadUser 중 Missing attribute 'preferred_username' in attributes 에러 발생
0
81
2
JWT 조회 에 대한 질문
0
76
1
password grant 방식 에러 응답
0
96
3
FormLoginConfigure에서 생성하는 필터
0
79
2
현업에서 springboot를 3.5.5 를 사용해서 공부중인데...
0
288
2
Jdbc 관련 강의 및 깃헙 문의
0
78
1
OAuth2AuthorizedClient 이해 및 활용 강의 내용 질문
0
209
1
UserInfo 엔드포인트 요청 실습
0
75
1
RFC 문서에서의 AccessToken 발급 방식 궁금한점
0
152
1
강의자료.zip 를 다운로드 받았는데 압축이 풀리지 않습니다. 확인 부탁드려요
0
140
2
OIDC SSO 관련 질문 입니다.
0
131
1
AuthenticationEntryPoint 강의 누락 문의
0
123
1
cors설정방법
0
116
1
jwt decoder 토큰 검증 시 질문
0
222
1
클라이언트에서 userinfo 엔드포인트 호출 시 질문
0
187
2
JOSE 구성요소의 api에 관한 질문
0
141
2
스프링 부트 3버전으로 따라가시는 분들 참고하세요
1
532
1
CustomOAuth2AuthenticationFilter 구현 중 질문
0
146
2
AuthenticationManager 생성시점
0
118
1
FormLogin과 Oauth2Client 둘 중 사용하는 시점
0
128
1
postman userinfo 엔드포인트 질문
0
136
2
강의 수강신청하고 듣기 전입니다 질문있습니다.
0
115
1
인증 코드를 통해 발급 받은 토큰의 관리
0
200
1





