相关疑难解决方法(0)

如何在同一个 Spring Boot 应用程序中使用多个“JWK Set Uri”值?

我需要使用两个不同的授权服务器(两个 Okta 实例)来验证来自作为后端 REST API 层的单个 Spring Boot 应用程序中的两个不同 Web 应用程序的身份验证令牌。

目前我有一台资源服务器使用以下配置:

@Configuration
@EnableWebSecurity
public class ResourceServerSecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception{
    http
      .authorizeRequests().antMatchers("/public/**").permitAll()
      .anyRequest().authenticated()
      .and()
      .oauth2ResourceServer().jwt();
  }
}
Run Code Online (Sandbox Code Playgroud)
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://dev-X.okta.com/oauth2/default
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://dev-X.okta.com/oauth2/default/v1/keys
Run Code Online (Sandbox Code Playgroud)

并具有依赖项spring-security-oauth2-resource-serverspring-security-oauth2-jose在我的 Spring Boot 应用程序中(版本 2.2.4.RELEASE)

我想要进入的最终状态是,根据请求中设置的自定义 HTTP 标头,我想选择我的 Spring Boot 应用程序使用哪个 Okta 实例来解码和验证 JWT 令牌。

理想情况下,我的配置文件中有两个属性,如下所示:

jwkSetUri.X=https://dev-X.okta.com/oauth2/default/v1/keys
jwtIssuerUri.X=https://dev-X.okta.com/oauth2/default

jwkSetUri.Y=https://dev-Y.okta.com/oauth2/default/v1/keys
jwtIssuerUri.Y=https://dev-Y.okta.com/oauth2/default
Run Code Online (Sandbox Code Playgroud)

我应该能够使用 aRequestHeaderRequestMatcher来匹配安全配置中的标头值。我无法锻炼的是如何使用oauth2ResourceServer与安全配置相匹配的两个不同实例。

spring spring-security oauth-2.0 spring-boot spring-security-oauth2

7
推荐指数
2
解决办法
4638
查看次数

在运行时配置Spring HTTP安全性

启动时应用所有http安全性:

protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
        .antMatchers("/admin/**").hasRole("admin")
}
Run Code Online (Sandbox Code Playgroud)

在运行时,我正在尝试添加更多...

applicationContext.getBean(WebSecurityConfigurerAdapter).http.authorizeRequests().antMatchers("bla").hasRole("admin")
Run Code Online (Sandbox Code Playgroud)

当执行该行时,它会将其添加到http.authorizeRequests(),但/ bla仍可由"非管理员"访问

重新启动服务器时,此更改将生效,因为它正在从数据库加载bla.

如何在不重新启动服务器的情况下立即使安全性生效?

spring spring-security

6
推荐指数
1
解决办法
1286
查看次数