0

` 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();
}

}

`

New contributor
priyanshu o is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented 3 hours ago
  • What is the exact issue you're having, can you add some reproduction steps? Commented 1 hour ago

0