1

我知道有一些类似的主题,但它们是关于实现困难的,而我的问题更适合架构师。它通常与springframework无关。

假设有一个应用程序同时实现了客户端\资源(就 OAuth2 而言)行为。它还支持用于测试目的的基本身份验证(它有自己的一组 static\ldap 用户)。身份验证提供程序作为单独的应用程序完成。

这种“三类”身份验证由

@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .requestMatcher(request -> {
                    String auth = request.getHeader("Authorization");
                    return (auth != null && auth.startsWith("Basic"));
                })
                .authorizeRequests()
                .antMatchers("/", "/login**").permitAll()
                .anyRequest().authenticated()
                .and().csrf().disable()
                .httpBasic()
        ;
    }
    ....
}

然后去

@Configuration
@EnableResourceServer
public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter {
    private final static Logger logger = LoggerFactory.getLogger(OAuth2ResourceServerConfig.class);

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .requestMatcher(request -> {
                    String auth = request.getHeader("Authorization");
                    return (auth != null && auth.startsWith("Bearer"));
                })
                .authorizeRequests()
                .anyRequest().authenticated();
    }
    ....
}

接着

@Configuration
@EnableOAuth2Sso
@Order(4)
public class OAuth2SsoConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/**").authorizeRequests()
                .antMatchers("/", "/login**").permitAll()
                .anyRequest().authenticated()
                .and().csrf().disable()
        ;
    }
    ....
}
  • 全部在一个包中(连同 UI)。

这很好用。但。拥有这样的环境真的好吗?此应用程序集成的一些系统本身已经具有“客户端”行为(如 SalesForce),因此 UI 和 @EnableOAuth2Sso 配置似乎是死重的。

我在安全漏洞方面遗漏了什么吗?我能够看到,一旦应用程序接受了一个不记名令牌,它就会创建会话,并且邮递员会在下一个请求时将 cookie 发送回应用程序,并且应用程序会管理此会话,即使另一个不记名令牌(对于另一个用户)已应用于授权标头。

通过 maven 配置文件或通过将其拆分到单独的应用程序(纯 UI 和客户端和资源 API)来自定义它是否有意义?

我看到的三个选项:

在此处输入图像描述

谢谢。

4

0 回答 0