#Spring Boot - using .permitAll() on requested endpoint but still getting a 401 error

1 messages · Page 1 of 1 (latest)

covert meadow
#

Code

package com.ronapps.ecommerceapi.security;
import ...
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {

    @Autowired
    private MyUserDetailsService myUserDetailsService; 
        
    @Bean
    public AuthenticationManager authenticationManager() throws Exception {
        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
        provider.setUserDetailsService(myUserDetailsService);
        provider.setPasswordEncoder(bcryptPasswordEncoder());
        return new ProviderManager(provider);
    }

    @Bean
    SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(auth -> auth
                        .requestMatchers( "/register_user", "/register_admin", "/login", "/home").permitAll()
                        .requestMatchers("/user/**").hasRole("USER")
                        .requestMatchers("/admin/**").hasRole("ADMIN")
                        .anyRequest().authenticated())
                       .httpBasic(Customizer.withDefaults())
                        .csrf(crsf -> crsf.disable());
        return http.build();
    }

    @Bean
    PasswordEncoder bcryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }
}```

I tried sending an  API request to my `register_user` endpoint but i'm getting a 401 error despite using `permitAll()`
north kelpBOT
#

<@&1004656351647117403> please have a look, thanks.

covert meadow
#

Spring Boot - using .permitAll() on requested endpoint but still getting a 401 error

worn echo
#

Which URL are you using?

digital socket
#

Can you try sending the request via Postman, if that works then you would have to set up CORS configuration.

north kelpBOT
#

@covert meadow

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

covert meadow
#

Sorry guys for inactivity

#

I fixed the issue by setting the cascade type to permit for my users and roles