• 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)));
    	}
    }
    ...
    
  • 相关阅读:
    python学习笔记
    win10优化设置
    jpa基本用法
    5_方法(函数)、参数传递
    12_文件基本权限
    10_管理用户和组
    9_用户和组的相关配置文件
    7_vim 编辑器使用技巧
    8_Xmanager 远程连接 Linux 系统工具使用方法
    5_Linux系统目录结构,相对/绝对路径
  • 原文地址:https://www.cnblogs.com/luguojun/p/12677193.html
Copyright © 2020-2023  润新知