【问题标题】:Spring security OAuth2 implementationSpring 安全 OAuth2 实现
【发布时间】:2017-08-06 01:17:40
【问题描述】:

使用 Spring Boot 1.5.2.RELEASE 和 Java 8

我试图了解,public void configure(HttpSecurity http)WebSecurityConfigurerAdapterResourceServerConfigurerAdapter 的方法是什么?

使用以下代码,ResourceServerConfigurerAdapterconfigure(HttpSecurity http) 方法优先于 WebSecurityConfigurerAdapter。我在ResourceServerConfiguration 中所做的所有更改都正在生效,看来WebSecurityConfigurerAdapter 被完全忽略了。

我们什么时候使用这些方法(用例)?而且,即使是授权类型password 也需要覆盖WebSecurityConfigurerAdapter.configure(..) 方法

使用security.oauth2.resource.filter-order = 3 如果没有这个属性,我会不断收到403 Access Denied

OAuth2 资源过滤器的默认顺序已从 3 更改为 SecurityProperties.ACCESS_OVERRIDE_ORDER - 1

网络安全配置

@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
public void configure(HttpSecurity http) throws Exception {
    http.csrf().disable()
    .authorizeRequests()
    .antMatchers("/unsecured").permitAll()
    .antMatchers("/users").hasRole("USER")
    .antMatchers("/api/secured").hasRole("ADMIN")
    .antMatchers("/api/admin").authenticated()
    .antMatchers("/greeting").authenticated();
  }
}

资源服务器

@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends
        ResourceServerConfigurerAdapter {

    public void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
            .authorizeRequests()
                .anyRequest().permitAll();          
    }
}

【问题讨论】:

    标签: java spring spring-security oauth oauth-2.0


    【解决方案1】:

    我想你在这里有答案,请查看给出的解决方案 Spring Security OAuth2, which decides security?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-08
      • 2020-07-02
      • 2012-06-15
      • 1970-01-01
      • 2014-04-22
      • 1970-01-01
      • 2015-11-14
      • 2017-08-06
      相关资源
      最近更新 更多