我们正在使用spring-security + spring-security-oauth实现OAuth2资源服务器。
用例非常简单:
使用Java配置,为了强制执行安全约束,我们使用了大量的SpEL:
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
// A. Only authorized clients
.antMatchers("/type-a").access("#oauth2.hasScope('READ_SOMETHING')")
// B. Both authorized clients and users
.antMatchers("/type-b").access("#oauth2.hasScope('READ_SOMETHING_ELSE') or (!#oauth2.isOAuth() and hasRole('ROLE_USER'))")
// ... (different flavors of B.) ...
// C. Everything else is for authenticated users
.anyRequest().hasRole("USER")
.and().httpBasic();
}
虽然这很好,但我不喜欢:
通常使用spring-security,安全配置基类(HttpSecurity
,WebSecurityConfigurerAdapter
)提供的ResourceServerConfigurerAdapter
构建器非常适合简单约束,但复合/复杂约束最终会出现在使用SpEL。
使用spring-security-oauth2我不知道除了SpEL以外的任何其他方式。
问题:是否有任何现有的实用程序类为OAuth2 SpEL提供某种类型安全的流畅构建器?
类似的东西:
TypicalPerfectlyNamedSpringFrameworkDreamClass.builder()
.startExpressionGroup()
.hasOAuth2Scope("MY-SCOPE")
.endExpressionGroup()
.or()
.startExpressionGroup()
.isNotOAuth2Request()
.and()
.hasRole("ROLE_USER")
.endExpressionGroup()
.toString();
答案 0 :(得分:1)
简短回答:"不,没有这样的效用"。