Last active
November 20, 2022 07:31
-
-
Save sandipchitale/33365d9e5ae5311dac3d6d2c8d9d7508 to your computer and use it in GitHub Desktop.
SPA Return 401 instead of redirect to login #spring-security
This file contains hidden or 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
@Bean | |
public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception { | |
LOGGER.debug("in configure HttpSecurity"); | |
// Return HttpStatus.UNAUTHORIZED (401) to SPAs. | |
http.exceptionHandling(eh -> | |
eh.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))); | |
// ... | |
http.formLogin(fl -> | |
fl | |
.successHandler((req, res, auth) -> res.setStatus(HttpStatus.OK.value())) | |
.failureHandler((req, res, auth) -> res.setStatus(HttpStatus.UNAUTHORIZED.value())) | |
); | |
return http.build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment