'Error: Request failed with status code 404 Spring-Security enabled
I am developing an App in FrontEnd (ReactJS, AXIOS) and Backend (Spring). When I did a post to do login with success with :
axios({
method: "post",
url: "/api/login",
data: bodyFormData,
headers: { "Content-Type": "multipart/form-data" },
})
.then(function (response) {
//handle success
console.log(response);
})
.catch(function (response) {
//handle error
console.log(response);
})
I got this answer in Postman
{
"timestamp": "2022-05-23T01:48:27.986+00:00",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/"
}
I have these filters
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll().and()
.authorizeRequests()
.antMatchers("/console/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginProcessingUrl("/api/login").permitAll()
.and()
.logout().logoutUrl("/api/logout").permitAll();
http.csrf().disable();
http.headers().frameOptions().disable();
}
I want to receive just in /api/login the data of the user validated. Can it achieve that with the filters only or do I need to create a controller?
Solution 1:[1]
I solved it with two things. I created a endpoint with This code give me the actual user :
@RequestMapping("/actualuser")
public Object actualUser(){
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
System.out.println(auth.getDetails());
return auth.getPrincipal();
}
and I this filter in .formLogin() and logout .logout()
.successForwardUrl("/api/actualuser")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
