在春季安全实施之后,它会阻止我的静态文件夹中的所有资源吗?

时间:2019-04-18 06:20:20

标签: spring-boot spring-security static resources

我正在使用弹簧靴'2.1.4.RELEASE'。实施Spring Security后,它会阻止我在静态文件夹中的所有资源。

这是我的spring安全适配器代码

package com.dbbl.payment.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


@EnableWebSecurity
public class WebSecurityConfigAdapter extends WebSecurityConfigurerAdapter {
    @Autowired
    private Authenticator authenticator;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authenticator);
    }

    protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable().authorizeRequests()
                .anyRequest().authenticated()
                .and()
                 .formLogin()
                .loginProcessingUrl("/login")
                .loginPage("/login").permitAll()
                 .and()
                .logout().logoutUrl("/logout")
                .logoutSuccessUrl("/login")
                .invalidateHttpSession(true)
                .and().httpBasic().disable();
    }
}

这是我的资源的文件夹结构

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以尝试将模板移至静态文件夹,然后尝试以下操作:

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