#Spring Security without WebSecurityConfigurerAdapter

1 messages · Page 1 of 1 (latest)

nimble plumeBOT
#

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

nimble plumeBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

olive storm
#
@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        return http
                .csrf((csrf) -> csrf.disable())
                .cors((cors) -> cors.disable())
                .authorizeHttpRequests(
                        (authorizationManagerRequestMatchers -> authorizationManagerRequestMatchers
                                .requestMatchers(HttpMethod.GET, "/", "/open").permitAll()
                                .requestMatchers(HttpMethod.GET, "/secure").hasAnyRole("ADMIN", "USER"))
                ).sessionManagement((sessionManagement) -> sessionManagement
                        .sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                .build();
    }

    @Bean
    public PasswordEncoder encoder() {
        return NoOpPasswordEncoder.getInstance();
    }

    @Bean
    public UserDetailsService userDetailsService() {
        UserDetails user = User.builder()
                .username("user")
                .password("password")
                .roles("USER")
                .build();
        return new InMemoryUserDetailsManager(user);
    }
}
nimble plumeBOT
# olive storm ```java @Configuration @EnableWebSecurity public class SecurityConfig { @Be...

Detected code, here are some useful tools:

Formatted code
@Configuration
@EnableWebSecurity
public class SecurityConfig {
  @Bean
  protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    return http.csrf((csrf) -> csrf.disable()).cors((cors) -> cors.disable()).authorizeHttpRequests((authorizationManagerRequestMatchers -> authorizationManagerRequestMatchers.requestMatchers(HttpMethod.GET, "/", "/open").permitAll().requestMatchers(HttpMethod.GET, "/secure").hasAnyRole("ADMIN", "USER"))).sessionManagement((sessionManagement) -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)).build();
  }
  @Bean
  public PasswordEncoder encoder() {
    return NoOpPasswordEncoder.getInstance();
  }
  @Bean
  public UserDetailsService userDetailsService() {
    UserDetails user = User.builder().username("user").password("password").roles("USER").build();
    return new InMemoryUserDetailsManager(user);
  }
}
olive storm
#

I think error one of these methods

@Bean
  public PasswordEncoder encoder() {
    return NoOpPasswordEncoder.getInstance();
  }
  @Bean
  public UserDetailsService userDetailsService() {
    UserDetails user = User.builder().username("user").password("password").roles("USER").build();
    return new InMemoryUserDetailsManager(user);
  }
}
warm venture
#

👀

#

hey

#

where is the question?