zoukankan      html  css  js  c++  java
  • Spring Security静态资源访问

    在使用Spring Security时要求所有请求都需要授权访问,此时会定义过滤规则如下

     1 protected void configure(HttpSecurity http) throws Exception {
     2     http
     3         .authorizeRequests()
     4             .anyRequest().authenticated()
     5             .and()
     6         .formLogin()
     7             // 指定登录页面
     8             .loginPage("/login")
     9             // 允许所有用户可以访问指定的登录页面
    10             .permitAll();
    11 }
    12        

    此时访问页面静态资源会由于授权失败进入到登录页面。

    Spring Security已定义了默认的不需要授权访问的路径,此时我们可以将静态资源放到这些路径下面就可以正常访问到,相关定义代码如下:

    1 public class SpringBootWebSecurityConfiguration {
    2     private static List<String> DEFAULT_IGNORED = Arrays.asList("/css/**", "/js/**", "/images/**", "/webjars/**", "/**/favicon.ico");
    3 
    4     ......
    5 }

    调用如下:

  • 相关阅读:
    Transformer详解
    PAT 1012
    PAT 1011
    PAT 1010
    Jordan Lecture Note-3: 梯度投影法
    PAT 1009
    PAT 1008
    Jordan Lecture Note-2: Maximal Margin Classifier
    PAT 1007
    PAT 1006
  • 原文地址:https://www.cnblogs.com/cheney256/p/8607771.html
Copyright © 2011-2022 走看看