javaspring-bootinsomnia

POST request unauthorized


I am working on a RestAPI endpoint for generating random values with Spring Boot and Bouncy Castle. I also have basic Spring Security activated.

When i make a GET request with the right credentials, everything works fine and the random value gets returned, but if i change it to PostMapping with the exact same underlying code and make a POST request - i get an unauthorized response, even tho the credentials are right.

I am using Insomnia for making HTTP requests.

Has anyone experienced something similar and knows how to fix it?


Solution

  • Creating a Configuration Class for Spring Security solved the problem.

    The following code worked:

    @Configuration
    @EnableWebSecurity
    public class SecurityConfiguration {
    
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
        http
                .csrf().disable();
        return http.build();
    }
    

    }