SpringBoot+SpringSecurity 정적 자원 의 실현 을 차단 하지 않 습 니 다.

문제 설명
SpringBoot 에 SpringSecurity 를 추가 한 후에 정적 자원 이 항상 여과 되 어 인터페이스 가 보기 싫 습 니 다.
在这里插入图片描述
디 렉 터 리 구조:
在这里插入图片描述
2.문제 해결
정상적으로 자원 을 차단 하지 않 습 니 다.저 는 자 료 를 찾 아 보 겠 습 니 다.기본적으로 다시 config 방법 을 사용 하면 됩 니 다.

package org.yolo.securitylogin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @Auther: Yolo
 * @Date: 2020/9/12 13:05
 * @Description:
 */
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
  @Bean
  PasswordEncoder passwordEncoder() {
    return NoOpPasswordEncoder.getInstance();
  }

  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    //        
    auth.inMemoryAuthentication()
        .withUser("yolo")
        .password("123").roles("admin");
  }

  @Override
  public void configure(WebSecurity web) throws Exception {
    //web.ignoring().antMatchers("/static/js/**", "/static/css/**", "/static/images/**");
    web.ignoring().antMatchers("/js/**", "/css/**","/images/**");
  }
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .anyRequest().authenticated()
        .and()
        .formLogin()
        .loginPage("/login.html")
        .permitAll()//            
        .and()
        .csrf().disable()
    ;
  }
}
일반적인 방법 은:

@Override
  public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/js/**", "/css/**","/images/**");
  }
在这里插入图片描述
configure 를 설정 한 후 target 을 제거 해 야 합 니 다.그렇지 않 으 면 유효 하지 않 습 니 다.
在这里插入图片描述
여기 서 SpringBoot+SpringSecurity 가 정적 자원 의 실현 을 차단 하지 않 는 다 는 글 을 소개 합 니 다.더 많은 SpringBoot+SpringSecurity 가 정적 자원 을 차단 하지 않 는 다 는 내용 은 예전 의 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 저 희 를 많이 지지 해 주시 기 바 랍 니 다!

좋은 웹페이지 즐겨찾기