org.springframework.security.config.annotation.web.builders.WebSecurity.ignoring()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(211)

本文整理了Java中org.springframework.security.config.annotation.web.builders.WebSecurity.ignoring()方法的一些代码示例,展示了WebSecurity.ignoring()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSecurity.ignoring()方法的具体详情如下:
包路径:org.springframework.security.config.annotation.web.builders.WebSecurity
类名称:WebSecurity
方法名:ignoring

WebSecurity.ignoring介绍

[英]Allows adding RequestMatcher instances that Spring Security should ignore. Web Security provided by Spring Security (including the SecurityContext) will not be available on HttpServletRequest that match. Typically the requests that are registered should be that of only static resources. For requests that are dynamic, consider mapping the request to allow all users instead.
Example Usage:

webSecurityBuilder.ignoring() 
// ignore all URLs that start with /resources/ or /static/ 
.antMatchers("/resources/**", "/static/**");

Alternatively this will accomplish the same result:

webSecurityBuilder.ignoring() 
// ignore all URLs that start with /resources/ or /static/ 
.antMatchers("/resources/**").antMatchers("/static/**");

Multiple invocations of ignoring() are also additive, so the following is also equivalent to the previous two examples:

webSecurityBuilder.ignoring() 
// ignore all URLs that start with /resources/ 
.antMatchers("/resources/**"); 
webSecurityBuilder.ignoring() 
// ignore all URLs that start with /static/ 
.antMatchers("/static/**"); 
// now both URLs that start with /resources/ and /static/ will be ignored

[中]允许添加Spring安全性应该忽略的RequestMatcher实例。Spring Security提供的Web安全性(包括SecurityContext)在匹配的HttpServletRequest上不可用。通常,注册的请求应该是静态资源的请求。对于动态请求,请考虑将请求映射为允许所有用户。
示例用法:

webSecurityBuilder.ignoring() 
// ignore all URLs that start with /resources/ or /static/ 
.antMatchers("/resources/**", "/static/**");

或者,这将实现相同的结果:

webSecurityBuilder.ignoring() 
// ignore all URLs that start with /resources/ or /static/ 
.antMatchers("/resources/**").antMatchers("/static/**");

对ignoreing()的多次调用也是累加的,因此以下内容也相当于前两个示例:

webSecurityBuilder.ignoring() 
// ignore all URLs that start with /resources/ 
.antMatchers("/resources/**"); 
webSecurityBuilder.ignoring() 
// ignore all URLs that start with /static/ 
.antMatchers("/static/**"); 
// now both URLs that start with /resources/ and /static/ will be ignored

代码示例

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

@Override
public void configure(WebSecurity web) throws Exception {
  web.ignoring().antMatchers("/api/v1/signup");
}

代码示例来源:origin: alibaba/nacos

@Override
public void configure(WebSecurity web) {
  String ignoreURLs = env.getProperty("nacos.security.ignore.urls", "/**");
  for (String ignoreURL : ignoreURLs.trim().split(SECURITY_IGNORE_URLS_SPILT_CHAR)) {
    web.ignoring().antMatchers(ignoreURL.trim());
  }
}

代码示例来源:origin: 527515025/springBoot

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

代码示例来源:origin: apache/nifi

@Override
public void configure(WebSecurity webSecurity) throws Exception {
  // ignore the access endpoints for obtaining the access config, the access token
  // granting, and access status for a given user (note: we are not ignoring the
  // the /access/download-token and /access/ui-extension-token endpoints
  webSecurity
      .ignoring()
        .antMatchers("/access", "/access/config", "/access/token", "/access/kerberos", "/access/oidc/**", "/access/knox/**");
}

代码示例来源:origin: stackoverflow.com

web.ignoring().antMatchers("/css/**", "/js/**", "/img/**", "/lib/**");

代码示例来源:origin: spring-projects/spring-security

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

代码示例来源:origin: spring-projects/spring-security

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

代码示例来源:origin: spring-projects/spring-security

@Override
public void configure(WebSecurity web) throws Exception {
  // @formatter:off
  web
    .ignoring()
      .mvcMatchers("/path");
  // @formatter:on
}

代码示例来源:origin: szerhusenBC/jwt-spring-security-demo

@Override
  public void configure(WebSecurity web) throws Exception {
    // AuthenticationTokenFilter will ignore the below paths
    web
      .ignoring()
      .antMatchers(
        HttpMethod.POST,
        authenticationPath
      )

      // allow anonymous resource requests
      .and()
      .ignoring()
      .antMatchers(
        HttpMethod.GET,
        "/",
        "/*.html",
        "/favicon.ico",
        "/**/*.html",
        "/**/*.css",
        "/**/*.js"
      )

      // Un-secure H2 Database (for testing purposes, H2 console shouldn't be unprotected in production)
      .and()
      .ignoring()
      .antMatchers("/h2-console/**/**");
  }
}

代码示例来源:origin: spring-projects/spring-security

@Override
public void configure(WebSecurity web)	throws Exception {
  web
    .ignoring()
      .antMatchers("/ignore1", "/ignore2");
}

代码示例来源:origin: spring-projects/spring-security

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

代码示例来源:origin: stackoverflow.com

.ignoring()

代码示例来源:origin: stackoverflow.com

.ignoring()

代码示例来源:origin: spring-projects/spring-security

@Override
public void configure(WebSecurity web) throws Exception {
  // @formatter:off
  web
    .ignoring()
      .mvcMatchers("/path").servletPath("/spring")
      .mvcMatchers("/notused");
  // @formatter:on
}

代码示例来源:origin: stackoverflow.com

@Configuration
@EnableWebSecurity
public class MyWebSecurityConfiguration extends WebSecurityConfigurerAdapter {

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

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http
      .authorizeRequests()
        .antMatchers("/").permitAll()
        .antMatchers("/dashboard/home/**").hasAnyRole("USER", "ADMIN")
        .antMatchers("/dashboard/users/**").hasRole("ADMIN")
        .antMatchers("/rest/users/**").hasRole("ADMIN")
        .anyRequest().authenticated()
        .and()
      .formLogin()
        .loginPage("/")
        .permitAll();
  }

  // Possibly more overridden methods ...
}

代码示例来源:origin: mrdear/JavaWEB

/**
 * 在此配置不过滤的请求
 */
@Override
public void configure(WebSecurity web) throws Exception {
 //每一个请求对应一个空的filter链,这里一般不要配置过多,
 // 因为查找处是一个for循环,过多就导致每个请求都需要循环一遍直到找到
 web.ignoring().antMatchers("/","/login","/favicon.ico");
}

代码示例来源:origin: stackoverflow.com

.ignoring()
  .antMatchers("/static/**","/status");

代码示例来源:origin: zhangxd1989/springboot-dubbox

@Override
public void configure(WebSecurity web) throws Exception {
  //忽略权限校验的访问路径
  web
    .ignoring()
    .antMatchers(
      "/hello",
      "/favicon.ico",
      "/swagger**/**",
      "/*/api-docs",
      "/webjars/**",
      "/*/sms/captcha",
      "/*/user/password",
      "/*/currency/**"
    )
    .antMatchers(HttpMethod.POST, "/*/user")
  ;
}

相关文章