How to make spring security permit access to static resources?

I decided to add some css to my application but it isn’t working because of spring security. Here is what i tried to fix this. 1)adding to the mvcConfig

@Override public void addResourceHandlers(ResourceHandlerRegistry registry) {     registry             .addResourceHandler("/resources/**")             .addResourceLocations("/resources/"); } 

2)added this to webSecurityConfig

 @Override public void configure(WebSecurity web) throws Exception {     web             .ignoring()             .antMatchers("/resources/**"); } 

3)also i have this method

@Override protected void configure(HttpSecurity http) throws Exception {     http.csrf().disable()             .authorizeRequests()             .antMatchers("/","/registration","/resources/**").permitAll()             .anyRequest().authenticated()             .and()             .formLogin()             .loginPage("/login")             .permitAll()             .and()             .logout()             .permitAll(); } 
  1. also i added this to application.properties file: spring.mvc.static-path-pattern=/resources/**

none of this methods are working for me. if anyone dealt with this, please help

you can check out the whole project if it helps my project

p.s. i’m just a beginner in spring, so dont judge me

Add Comment
1 Answer(s)

You have to ignore the css directory too.

@Component public class SecurityConfig implements WebSecurityConfigurer {      @Override     public void configure(WebSecurity web) {         web             .ignoring()                  .antMatchers("/css/**")                 .antMatchers("/js/**")                 .antMatchers("/images/**")                 .antMatchers("/resources/**");     } } 
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.