【发布时间】:2014-10-05 12:37:14
【问题描述】:
在以前的 OAuth2 版本中,可以通过将自定义令牌授予者添加到 <authorization-server> 元素中的 xml 配置中来添加自定义令牌授予者。
我想知道如何使用 AuthorizationServerConfigurerAdapter 使用 Java Config 扩展授权服务器,而不会丢失包含隐式、客户端凭据、刷新令牌和授权代码授予类型的默认配置。
第一次尝试是使用 @Component 创建 TokenGranter:
@Component("customTokenGranter")
public class CustomTokenGranter {
//implementation
}
这会导致依赖解析异常,因为构造 Granter 所需的 tokenServices 无法自动装配。
第二次尝试使用configure方法
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception
{
endpoints
.tokenGranter(new CustomTokenGranter(endpoints.getTokenServices(),
endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory()));
}
使用这个,默认的授权类型将不会被注册。
我还尝试了较低阶的第二个配置,但没有成功。 我还能做些什么来添加我的自定义授权类型?
【问题讨论】:
标签: java spring spring-java-config spring-security-oauth2