在我们的应用程序中,我们希望锁定check_token端点,以便只有使用客户端凭据进行身份验证的客户端才能检查令牌的有效性。
文档指出在使用@EnableResourceServer
时默认启用表达式处理程序,并且有一些关于如何使用xml设置表达式处理的说明。
我需要做什么,使用java config来评估下面的表达式?
@Configuration
@EnableAuthorizationServer
public class OAuth2AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
...
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.checkTokenAccess("#oauth2.isClient()");
}
...
}
答案 0 :(得分:2)
以下情况并不漂亮,但似乎有效。
@EnableGlobalAuthentication
@Configuration
//@EnableAuthorizationServer
@Import({OAuth2AuthorizationServerConfiguration.SecurityConfiguration.class, AuthorizationServerEndpointsConfiguration.class})
public class OAuth2AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Configuration
public static class SecurityConfiguration extends AuthorizationServerSecurityConfiguration {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().expressionHandler(new OAuth2WebSecurityExpressionHandler());
super.configure(http);
}
}
AuthorizationServerSecurityConfiguration
提供对HttpSecurity
对象的访问,这是表达式处理程序需要插入的对象。
AuthorizationServerSecurityConfiguration
并设置表达式处理程序@EnableAuthorizationServer
注释(因为它还会导入AuthorizationServerSecurityConfiguration
)AuthorizationServerSecurityConfiguration
AuthorizationServerEndpointsConfiguration
(最初由@EnableAuthorizationServer