• spring cloud笔记 oauth2授权服务 默认tokenService配置源码


    AuthorizationServerEndpointsConfiguration

    ...
    private AuthorizationServerEndpointsConfigurer endpoints = new AuthorizationServerEndpointsConfigurer();
    ...
    //注册工厂
    @Bean
    public FactoryBean<AuthorizationServerTokenServices> defaultAuthorizationServerTokenServices() {
    	return new AuthorizationServerTokenServicesFactoryBean(endpoints);
    }
    ...
    protected static class AuthorizationServerTokenServicesFactoryBean
    			extends AbstractFactoryBean<AuthorizationServerTokenServices> {
    	...
    	// 创建tokenService实例
    	@Override
    	protected AuthorizationServerTokenServices createInstance() throws Exception {
    		return endpoints.getDefaultAuthorizationServerTokenServices();
    	}
    	...
    }
    ...
    

    AuthorizationServerEndpointsConfigurer

    ...
    public AuthorizationServerTokenServices getDefaultAuthorizationServerTokenServices() {
    	if (defaultTokenServices != null) {
    		return defaultTokenServices;
    	}
    	// 创建默认tokenService实例
    	this.defaultTokenServices = createDefaultTokenServices();
    	return this.defaultTokenServices;
    }
    ...
    private DefaultTokenServices createDefaultTokenServices() {
    	DefaultTokenServices tokenServices = new DefaultTokenServices();
    	tokenServices.setTokenStore(tokenStore());
    	tokenServices.setSupportRefreshToken(true);
    	tokenServices.setReuseRefreshToken(reuseRefreshToken);
    	tokenServices.setClientDetailsService(clientDetailsService());
    	tokenServices.setTokenEnhancer(tokenEnhancer());
    	addUserDetailsService(tokenServices, this.userDetailsService);
    	return tokenServices;
    }
    ...
    private void addUserDetailsService(DefaultTokenServices tokenServices, UserDetailsService userDetailsService) {
    	if (userDetailsService != null) {
    		PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
    		provider.setPreAuthenticatedUserDetailsService(new UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken>(
    				userDetailsService));
    		tokenServices
    				.setAuthenticationManager(new ProviderManager(Arrays.<AuthenticationProvider> asList(provider)));
    	}
    }
    ...
    
  • 相关阅读:
    Spring Boot 使用Redis
    openTSDB(转)
    httpClient 超时时间设置(转)
    HTTPClient 超时链接设置
    入坑python 自己写的小工具,纪念一下
    Linux下SVN创建新的项目
    java对象数组的概述和使用
    解决fastDFS客户端连接超时问题
    显示目录结构
    centos7开启80和8080端口
  • 原文地址:https://www.cnblogs.com/luguojun/p/16132863.html
Copyright © 2020-2023  润新知