当前位置:   article > 正文

OAuth端点注册_authorizationendpoint 父类

authorizationendpoint 父类
一、配置入口:
1. AuthorizationServerEndpointsConfiguration类:

生成AuthorizationEndpoint、TokenEndpoint、CheckTokenEndpoint、TokenKeyEndpoint 、

WhitelabelApprovalEndpoint、WhitelabelErrorEndpoint Bean 端点。
通过endpoints.getDefaultAuthorizationServerTokenServices();完成AuthorizationServerEndpointsConfigurer的初始化生成相关的对象。
  1. @Import(TokenKeyEndpointRegistrar.class)
  2. public class AuthorizationServerEndpointsConfiguration {
  3. //配置导出给全局使用
  4. private AuthorizationServerEndpointsConfigurer endpoints = new AuthorizationServerEndpointsConfigurer();
  5. @Autowired
  6. private ClientDetailsService clientDetailsService;
  7. @Autowired
  8. private List<AuthorizationServerConfigurer> configurers = Collections.emptyList();
  9. // AuthorizationServerEndpointsConfigurer 注入到AuthorizationServerConfigurer
  10. // 达到引用目的
  11. @PostConstruct
  12. public void init() {
  13. for (AuthorizationServerConfigurer configurer : configurers) {
  14. try {
  15. configurer.configure(endpoints);
  16. } catch (Exception e) {
  17. throw new IllegalStateException("Cannot configure enpdoints", e);
  18. }
  19. }
  20. endpoints.setClientDetailsService(clientDetailsService);
  21. }
  22. // AuthorizationServerEndpointsConfigurer endpoints 作为一个beean 存在
  23. @Bean
  24. public FactoryBean<AuthorizationServerTokenServices> defaultAuthorizationServerTokenServices() {
  25. return new AuthorizationServerTokenServicesFactoryBean(endpoints);
  26. }
  27. //端点的处理入口
  28. @Bean
  29. public FrameworkEndpointHandlerMapping oauth2EndpointHandlerMapping() throws Exception {
  30. return getEndpointsConfigurer().getFrameworkEndpointHandlerMapping();
  31. }
  32. }

2. 自定义EndPoint: TokenKeyEndpoint.class注册进bean容器就可以。

  1. @Component
  2. protected static class TokenKeyEndpointRegistrar implements BeanDefinitionRegistryPostProcessor {
  3. private BeanDefinitionRegistry registry;
  4. @Override
  5. public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
  6. String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory,
  7. JwtAccessTokenConverter.class, false, false);
  8. if (names.length > 0) {
  9. BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TokenKeyEndpoint.class);
  10. builder.addConstructorArgReference(names[0]);
  11. registry.registerBeanDefinition(TokenKeyEndpoint.class.getName(), builder.getBeanDefinition());
  12. }
  13. }
  14. @Override
  15. public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
  16. this.registry = registry;
  17. }
  18. }

二、实际配置AuthorizationServerEndpointsConfigurer类,(容器)

 

  1. public final class AuthorizationServerEndpointsConfigurer {
  2. private AuthorizationServerTokenServices tokenServices;
  3. private ConsumerTokenServices consumerTokenServices;
  4. private AuthorizationCodeServices authorizationCodeServices;
  5. private ResourceServerTokenServices resourceTokenServices;
  6. private TokenStore tokenStore;
  7. private TokenEnhancer tokenEnhancer;
  8. private AccessTokenConverter accessTokenConverter;
  9. private ApprovalStore approvalStore;
  10. private TokenGranter tokenGranter;
  11. private OAuth2RequestFactory requestFactory;
  12. private OAuth2RequestValidator requestValidator;
  13. private UserApprovalHandler userApprovalHandler;
  14. private AuthenticationManager authenticationManager;
  15. private ClientDetailsService clientDetailsService;
  16. private String prefix;
  17. private Map<String, String> patternMap = new HashMap<String, String>();
  18. private Set<HttpMethod> allowedTokenEndpointRequestMethods = new HashSet<HttpMethod>();
  19. private FrameworkEndpointHandlerMapping frameworkEndpointHandlerMapping;
  20. private boolean approvalStoreDisabled;
  21. private List<Object> interceptors = new ArrayList<Object>();
  22. private DefaultTokenServices defaultTokenServices;
  23. private UserDetailsService userDetailsService;
  24. private boolean tokenServicesOverride = false;
  25. private boolean userDetailsServiceOverride = false;
  26. private boolean reuseRefreshToken = true;
  27. private WebResponseExceptionTranslator<OAuth2Exception> exceptionTranslator;
  28. private RedirectResolver redirectResolver;
  29. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/84094
推荐阅读
相关标签
  

闽ICP备14008679号