` Always gettiing redirected to the login and not able to disble csrf in spring boot authentication, authorization public urls also needauthentication @Configuration @EnableWebSecurity public class SecurityConfiguration {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers("/home/", "/register/**").permitAll()
.requestMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/user/**").hasRole("USER")
.anyRequest().authenticated()
)
.formLogin(form -> form
.permitAll()
)
.build();
}
@Bean
public UserDetailsService userDetailsService() {
UserDetails normalUser = User.builder()
.username("gc")
.password("$2a$12$pLlEDlW7J3LJMLMl0Uv8Xu.NO1TYDvrMmIpoDhpHZ3So65XlsR.Vy")
.roles("USER")
.build();
UserDetails adminUser = User.builder()
.username("admin")
.password("$2a$12$4MVGfzHJ2C370at3MTGHdeX6z/kon2X5KbVWZTGfqjWBhj.KnQBuC")
.roles("ADMIN", "USER")
.build();
return new InMemoryUserDetailsManager(normalUser, adminUser);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
`