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()
.authorizationEndpoint()
.authorizationRequestRepository(this.oAuthRequestRepository)
.and().successHandler(this::successHandler);
.and().successHandler(this::successHandler)
.failureHandler(this::failureHandler);
}
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
public AuthenticationManager authenticationManagerBean() throws Exception {

View File

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