【问题标题】:Configuring Spring Security for Oauth and Http Basic authentication为 Oauth 和 Http Basic 身份验证配置 Spring Security
【发布时间】:2016-05-31 19:32:34
【问题描述】:

在我使用 spring-security 的 Spring-Boot 应用程序中,我希望一些 REST 调用 (API) 仅通过 http 基本身份验证进行身份验证,但所有其他请求应通过 OAUTH2(标准 Oauth2 webapp 重定向到授权端点)。

Http基本认证是使用http.httpBasic()激活的, oauth 使用 @EnableOAuth2Sso 注释激活。但是通过以下配置,我的 API 调用也被重定向到授权端点,这不是我的目标。有什么想法吗?

@EnableOauth2Sso
@Configuraiton
@EnableWebSecurity
public class SecurityConfig {
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.httpBasic().and().authorizeRequests().anyRequest().authenticated();
  }
}

【问题讨论】:

标签: java authentication oauth spring-security


【解决方案1】:

您可以使用 authorizeRequests().antMatchers() 并根据基于 OAuth 或 Http Basic Security 的 URI 模式对资源进行分类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-27
    • 2011-06-02
    • 1970-01-01
    • 2011-02-11
    • 2021-10-30
    • 2013-01-11
    • 2013-10-30
    • 2014-04-07
    相关资源
    最近更新 更多