spring security authorization at spring security version 6.2

261 views Asked by At

@Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

    return http.csrf().disable()
            .authorizeHttpRequests()
            .requestMatchers("/home/normal")
            .permitAll()
            .and()
            .authorizeHttpRequests().requestMatchers("/products/**")
            .authenticated().and().formLogin().and().build();


}

how to write .csrf() ,.authorizeHttpRequests(),.formLogin() because it showing error that is deprecated and marked for removal.I m using springboot 3.2 version and spring security 6.2

1

There are 1 answers

0
Slevin On
@Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

    return http
            .csrf(CsrfConfigurer::disable)

            .authorizeHttpRequests(authorize -> authorize
                .requestMatchers("/home/normal").permitAll()
                .requestMatchers("/products/**").authenticated())

            .formLogin(login -> login
                .loginPage("/login").permitAll())

            .build();
}