Java Spring Security OAuth类型安全SpEL builder
我们正在使用spring security+spring security oauth实现OAuth2资源服务器 用例非常简单:Java Spring Security OAuth类型安全SpEL builder,java,spring,spring-security,spring-security-oauth2,Java,Spring,Spring Security,Spring Security Oauth2,我们正在使用spring security+spring security oauth实现OAuth2资源服务器 用例非常简单: A.某些资源仅可用于授权客户 B.某些资源仅可用于(HTTP basic)经过身份验证的用户 C.所有其他资源仅可用于(HTTP basic)经过身份验证的用户 在Java配置中,为了实施安全约束,我们使用了很多SpEL,如下所示: @Override public void configure(HttpSecurity http) throws Exceptio
- A.某些资源仅可用于授权客户
- B.某些资源仅可用于(HTTP basic)经过身份验证的用户
- C.所有其他资源仅可用于(HTTP basic)经过身份验证的用户
@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();
}
虽然这很好,但我不喜欢:
WebSecurityConfigureAdapter
,ResourceServerConfigurerAdapter
)提供的HttpSecurity
生成器非常适合于简单约束,但复合/复杂约束最终会出现在SpEL中
使用spring-security-oauth2,除了SpEL,我不知道还有什么其他方法
问题:是否存在为OAuth2 SpEL提供某种类型安全的fluent builder的实用程序类
比如:
TypicalPerfectlyNamedSpringFrameworkDreamClass.builder()
.startExpressionGroup()
.hasOAuth2Scope("MY-SCOPE")
.endExpressionGroup()
.or()
.startExpressionGroup()
.isNotOAuth2Request()
.and()
.hasRole("ROLE_USER")
.endExpressionGroup()
.toString();
简短回答:“不,没有这样的实用程序。”简短回答:“不,没有这样的实用程序。”谢谢,可能在那个问题上绕得太多了谢谢,可能在那个问题上绕得太多了