0

1) I have configured application using pure java configuration. Everything seems to be working correctly except css/js/images. The application is available on Github at

https://github.com/rajendersaini/cabms/

Just want to point out the configuration

AppConfig - spring mvc config - register resources using

registry.addResourceHandler("/resources/**")
                .addResourceLocations("/WEB-INF/resources/").setCachePeriod(31556926);

and in SecurityConfig -

http.authorizeRequests()
                .antMatchers(LoginController.AUTHLOGIN,
                        ResourceConfig.RESOURCE_PATH_MATCHER).permitAll()
                .anyRequest().authenticated().and().formLogin()
                .loginPage(LoginController.AUTHLOGIN);

Can you please help fixing this issue?

3 Answers 3

1

Where do your static resources end up in your war file? I ask because you have them under the WEB-INF directory. I don't know if Spring will allow you to serve public content out of WEB-INF.

In my build, I have my static stuff under

src/main/webapp/resources/...
    /css
    /js
    /img

This way, they end up at the top level of the war file under the /resources directory. You could give that a shot.

Sign up to request clarification or add additional context in comments.

1 Comment

Spring allows them from any dir. Till now everything was working fine. When i introduced security everything seems to stopped working. Anyways thanks for looking into it, really appreciated.
0

1) Finally my application resources are working - few changes I have made, In my mvc app config, I don't know when I introduced this line and this was the culprit. I will investigate it later

   @Override
        public void configureDefaultServletHandling(
                        DefaultServletHandlerConfigurer configurer) {
                configurer.enable();
        }

2) Java webapp initializer was looking for mapping which should be "/*" instead of "/"

3) In headers and footer we need to have context appended to resource paths.

Comments

0

You don't specify a secure rule which will ignore an application security for static resources. Try to add code like this in your Spring Security configuration class:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.