123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package com.yaozhitech.spring5.config;
- import org.springframework.context.annotation.Configuration;
- @Configuration
- public class AuthorizationServerConfig {
-
- // @Bean
- // SecurityWebFilterChain configure(ServerHttpSecurity http) throws Exception {
- // http
- // // ...
- // .oauth2Client(withDefaults());
- // return http.build();
- // }
- // @Autowired
- // @Qualifier("authenticationManagerBean")
- // private AuthenticationManager authenticationManager;
- //
- // @Qualifier("dataSource")
- // @Autowired
- // DataSource dataSource;
- //
- // @Autowired
- // @Qualifier("userDetailsService")
- // UserDetailsService userDetailsService;
- //
- // /**
- // * jwt 对称加密密钥
- // */
- // @Value("${spring.security.oauth2.jwt.signingKey}")
- // private String signingKey;
- //
- // @Override
- // public void configure(AuthorizationServerSecurityConfigurer oauthServer) {
- // // 支持将client参数放在header或body中
- // oauthServer.allowFormAuthenticationForClients();
- // oauthServer.tokenKeyAccess("isAuthenticated()")
- // .checkTokenAccess("permitAll()");
- // }
- //
- // @Override
- // public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
- // // 配置客户端信息,从数据库中读取,对应oauth_client_details表
- // clients.jdbc(dataSource);
- // }
- //
- // @Override
- // public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
- // // 配置token的数据源、自定义的tokenServices等信息,配置身份认证器,配置认证方式,TokenStore,TokenGranter,OAuth2RequestFactory
- // endpoints.tokenStore(tokenStore())
- // .authorizationCodeServices(authorizationCodeServices())
- // .approvalStore(approvalStore())
- // .exceptionTranslator(customExceptionTranslator())
- // .tokenEnhancer(tokenEnhancerChain())
- // .authenticationManager(authenticationManager)
- // .userDetailsService(userDetailsService)
- // //update by joe_chen add granter
- // .tokenGranter(tokenGranter(endpoints));
- //
- // }
- //
- // /**
- // * 自定义OAuth2异常处理
- // *
- // * @return CustomWebResponseExceptionTranslator
- // */
- // @Bean
- // public WebResponseExceptionTranslator<OAuth2Exception> customExceptionTranslator() {
- // return new CustomWebResponseExceptionTranslator();
- // }
- //
- // /**
- // * 授权信息持久化实现
- // *
- // * @return JdbcApprovalStore
- // */
- // @Bean
- // public ApprovalStore approvalStore() {
- // return new JdbcApprovalStore(dataSource);
- // }
- //
- // /**
- // * 授权码模式持久化授权码code
- // *
- // * @return JdbcAuthorizationCodeServices
- // */
- // @Bean
- // protected AuthorizationCodeServices authorizationCodeServices() {
- // // 授权码存储等处理方式类,使用jdbc,操作oauth_code表
- // return new JdbcAuthorizationCodeServices(dataSource);
- // }
- //
- // /**
- // * token的持久化
- // *
- // * @return JwtTokenStore
- // */
- // @Bean
- // public TokenStore tokenStore() {
- // return new JwtTokenStore(accessTokenConverter());
- // }
- //
- // /**
- // * 自定义token
- // *
- // * @return tokenEnhancerChain
- // */
- // @Bean
- // public TokenEnhancerChain tokenEnhancerChain() {
- // TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
- // tokenEnhancerChain.setTokenEnhancers(Arrays.asList(new CustomTokenEnhancer(), accessTokenConverter()));
- // return tokenEnhancerChain;
- // }
- //
- // /**
- // * jwt token的生成配置
- // *
- // * @return
- // */
- // @Bean
- // public JwtAccessTokenConverter accessTokenConverter() {
- // JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
- // converter.setSigningKey(signingKey);
- // return converter;
- // }
- //
- // /**
- // * 配置自定义的granter,手机号验证码登陆
- // *
- // * @param endpoints
- // * @return
- // * @auth joe_chen
- // */
- // public TokenGranter tokenGranter(final AuthorizationServerEndpointsConfigurer endpoints) {
- // List<TokenGranter> granters = Lists.newArrayList(endpoints.getTokenGranter());
- // granters.add(new MobileTokenGranter(
- // authenticationManager,
- // endpoints.getTokenServices(),
- // endpoints.getClientDetailsService(),
- // endpoints.getOAuth2RequestFactory()));
- // return new CompositeTokenGranter(granters);
- // }
- }
|