4

Need a help of following.

I am using spring 4.1 with spring security 3.2.7 and annotations.

My js, css, images are not loading..I am getting this error.

Spring mvc with security and WEB-INF js and images access- Refused to execute script from 'http://localhost:8081/xyz/static/internal/js/jquery-1.10.2.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

With out spring security everything is working fine

These are the configurations at mvcconfig.

 @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/", "/resources/");
    registry.addResourceHandler("/static/**").addResourceLocations("/", "/WEB-INF/pages/static/");
}

@Bean
public ViewResolver viewResolver() {
    final InternalResourceViewResolver bean = new InternalResourceViewResolver();
    bean.setViewClass(JstlView.class);
    bean.setPrefix("/WEB-INF/pages/");
    bean.setSuffix(".jsp");
    return bean;
}

and these are at Security configuration.

 @Override
public void configure(final WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/WEB-INF/pages/static/**");
    web.ignoring().antMatchers("/resources/**");
}

and the web.xml is

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>mvc</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
    <filter-name>localizationFilter</filter-name>
    <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>localizationFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Very confused- when I am ignoring - web.ignoring().antMatchers("/WEB-INF/pages/static/**"); Why it is not able to load my static contents. Please help me on this.

Arun Bertil
  • 4,598
  • 4
  • 33
  • 59
Manu
  • 1,243
  • 5
  • 17
  • 43

1 Answers1

1

You should be aware that the Ant matchers are compared against the request path and not against the filesystem path of the resource. With that respect, proper configuration would be:

web.ignoring().antMatchers("/static/**");
Master Slave
  • 27,771
  • 4
  • 57
  • 55
  • :-) It is not related to this question.I am planning to add a feed back module about my web site.Who logged in can leave a feed back.Could you please refer, guide some reference, url, code. – Manu May 04 '15 at 12:09
  • np, will let the answer stick around as it still might help someone – Master Slave May 04 '15 at 12:11