@ EnableOAuth2Sso和@EnableResourceServer(同一应用程序中的客户端和资源行为)

时间:2019-12-30 10:40:27

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

我知道也有一些类似的话题,但是它们都是关于实现方面的困难,而我的问题是更明智的。 而且通常与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&client和Resource API)进行自定义是否有意义?

我看到的三个选项:

enter image description here

谢谢。

0 个答案:

没有答案