Spring Boot with Security не обслуживает мой статический контент - PullRequest
0 голосов
/ 20 декабря 2018

Привет, вот мой файл конфигурации безопасности, и я использую Spring Boot 2.0.6.RELEASE, и мои файлы статического содержимого находятся в статической папке только static-> css, js, images, fonts

У меня естьперепробовал все другие решения для постов, но ни один из них не помог мне, но статическое содержимое защищено, стили не применяются и т. д. заранее спасибо

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final String[] PUBLIC_MATCHER = {"/css/**","/js/**","/fonts/**","/images/**", "/"};

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .authorizeRequests()
            .antMatchers(PUBLIC_MATCHER)
            .permitAll().anyRequest().authenticated()
            .and()
            .csrf().disable().cors().disable()
            .formLogin().failureUrl("/login?error").defaultSuccessUrl("/dashboard")
            .loginPage("/login").permitAll()
            .and()
            .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll()
            .and()
            .rememberMe();

       }
    }
 }

1 Ответ

0 голосов
/ 20 декабря 2018

Добавьте этот метод в файл конфигурации безопасности, надеюсь, он будет работать

//this method allows static resources to be neglected by spring security
        @Override
        public void configure(WebSecurity web) throws Exception {
            web
                .ignoring()
                .antMatchers("/resources/**", "/static/**","/css/**","/js/**","/fonts/**","/images/**");
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...