Handles OAuth2 Failure

This commit is contained in:
2022-11-15 15:03:37 -03:00
parent 980d4d5da4
commit 00d175a886
2 changed files with 8 additions and 3 deletions

View File

@@ -87,7 +87,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http.oauth2Login() http.oauth2Login()
.authorizationEndpoint() .authorizationEndpoint()
.authorizationRequestRepository(this.oAuthRequestRepository) .authorizationRequestRepository(this.oAuthRequestRepository)
.and().successHandler(this::successHandler); .and().successHandler(this::successHandler)
.failureHandler(this::failureHandler);
} }
private void successHandler(HttpServletRequest request, private void successHandler(HttpServletRequest request,
@@ -104,6 +105,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
} }
private void failureHandler(
HttpServletRequest request,
HttpServletResponse response,
AuthenticationException e) {
throw new AuthenticationInvalidException("Invalid Authentication Attempt.");
}
@Bean @Bean
public AuthenticationManager authenticationManagerBean() throws Exception { public AuthenticationManager authenticationManagerBean() throws Exception {

View File

@@ -17,8 +17,6 @@ public class OAuthRequestRepository implements AuthorizationRequestRepository<OA
public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) { public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) {
String state = request.getParameter("state"); String state = request.getParameter("state");
log.info(state);
if (Objects.nonNull(state)) { if (Objects.nonNull(state)) {
return removeAuthorizationRequest(request); return removeAuthorizationRequest(request);
} }