• 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)));
    	}
    }
    ...
    
  • 相关阅读:
    openstack常见问题
    30 个 Openstack 经典面试问题和解答
    linux系统内存爆满的解决办法!~
    iostat详解
    线上应用故障排查之一:高CPU占用
    对OpenStack运维架构的总结(转)
    zabbix基本监控各指标简解
    创建 OpenStack云主机
    centos7系统中忘记了root管理员账号密码的解决方式(转)
    MySQL高可用架构之MHA
  • 原文地址:https://www.cnblogs.com/luguojun/p/14294802.html
Copyright © 2020-2023  润新知