AuthorizationServerConfig.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.yaozhitech.spring5.config;
  2. import org.springframework.context.annotation.Configuration;
  3. @Configuration
  4. public class AuthorizationServerConfig {
  5. // @Bean
  6. // SecurityWebFilterChain configure(ServerHttpSecurity http) throws Exception {
  7. // http
  8. // // ...
  9. // .oauth2Client(withDefaults());
  10. // return http.build();
  11. // }
  12. // @Autowired
  13. // @Qualifier("authenticationManagerBean")
  14. // private AuthenticationManager authenticationManager;
  15. //
  16. // @Qualifier("dataSource")
  17. // @Autowired
  18. // DataSource dataSource;
  19. //
  20. // @Autowired
  21. // @Qualifier("userDetailsService")
  22. // UserDetailsService userDetailsService;
  23. //
  24. // /**
  25. // * jwt 对称加密密钥
  26. // */
  27. // @Value("${spring.security.oauth2.jwt.signingKey}")
  28. // private String signingKey;
  29. //
  30. // @Override
  31. // public void configure(AuthorizationServerSecurityConfigurer oauthServer) {
  32. // // 支持将client参数放在header或body中
  33. // oauthServer.allowFormAuthenticationForClients();
  34. // oauthServer.tokenKeyAccess("isAuthenticated()")
  35. // .checkTokenAccess("permitAll()");
  36. // }
  37. //
  38. // @Override
  39. // public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
  40. // // 配置客户端信息,从数据库中读取,对应oauth_client_details表
  41. // clients.jdbc(dataSource);
  42. // }
  43. //
  44. // @Override
  45. // public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
  46. // // 配置token的数据源、自定义的tokenServices等信息,配置身份认证器,配置认证方式,TokenStore,TokenGranter,OAuth2RequestFactory
  47. // endpoints.tokenStore(tokenStore())
  48. // .authorizationCodeServices(authorizationCodeServices())
  49. // .approvalStore(approvalStore())
  50. // .exceptionTranslator(customExceptionTranslator())
  51. // .tokenEnhancer(tokenEnhancerChain())
  52. // .authenticationManager(authenticationManager)
  53. // .userDetailsService(userDetailsService)
  54. // //update by joe_chen add granter
  55. // .tokenGranter(tokenGranter(endpoints));
  56. //
  57. // }
  58. //
  59. // /**
  60. // * 自定义OAuth2异常处理
  61. // *
  62. // * @return CustomWebResponseExceptionTranslator
  63. // */
  64. // @Bean
  65. // public WebResponseExceptionTranslator<OAuth2Exception> customExceptionTranslator() {
  66. // return new CustomWebResponseExceptionTranslator();
  67. // }
  68. //
  69. // /**
  70. // * 授权信息持久化实现
  71. // *
  72. // * @return JdbcApprovalStore
  73. // */
  74. // @Bean
  75. // public ApprovalStore approvalStore() {
  76. // return new JdbcApprovalStore(dataSource);
  77. // }
  78. //
  79. // /**
  80. // * 授权码模式持久化授权码code
  81. // *
  82. // * @return JdbcAuthorizationCodeServices
  83. // */
  84. // @Bean
  85. // protected AuthorizationCodeServices authorizationCodeServices() {
  86. // // 授权码存储等处理方式类,使用jdbc,操作oauth_code表
  87. // return new JdbcAuthorizationCodeServices(dataSource);
  88. // }
  89. //
  90. // /**
  91. // * token的持久化
  92. // *
  93. // * @return JwtTokenStore
  94. // */
  95. // @Bean
  96. // public TokenStore tokenStore() {
  97. // return new JwtTokenStore(accessTokenConverter());
  98. // }
  99. //
  100. // /**
  101. // * 自定义token
  102. // *
  103. // * @return tokenEnhancerChain
  104. // */
  105. // @Bean
  106. // public TokenEnhancerChain tokenEnhancerChain() {
  107. // TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
  108. // tokenEnhancerChain.setTokenEnhancers(Arrays.asList(new CustomTokenEnhancer(), accessTokenConverter()));
  109. // return tokenEnhancerChain;
  110. // }
  111. //
  112. // /**
  113. // * jwt token的生成配置
  114. // *
  115. // * @return
  116. // */
  117. // @Bean
  118. // public JwtAccessTokenConverter accessTokenConverter() {
  119. // JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
  120. // converter.setSigningKey(signingKey);
  121. // return converter;
  122. // }
  123. //
  124. // /**
  125. // * 配置自定义的granter,手机号验证码登陆
  126. // *
  127. // * @param endpoints
  128. // * @return
  129. // * @auth joe_chen
  130. // */
  131. // public TokenGranter tokenGranter(final AuthorizationServerEndpointsConfigurer endpoints) {
  132. // List<TokenGranter> granters = Lists.newArrayList(endpoints.getTokenGranter());
  133. // granters.add(new MobileTokenGranter(
  134. // authenticationManager,
  135. // endpoints.getTokenServices(),
  136. // endpoints.getClientDetailsService(),
  137. // endpoints.getOAuth2RequestFactory()));
  138. // return new CompositeTokenGranter(granters);
  139. // }
  140. }