org.springframework.security.oauth2.provider.token.TokenEnhancerChain Java Examples

The following examples show how to use org.springframework.security.oauth2.provider.token.TokenEnhancerChain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthorizationServerConfig.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
/**
 * 配置身份认证器,配置认证方式,TokenStore,TokenGranter,OAuth2RequestFactory
 * @param endpoints
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    if (jwtAccessTokenConverter != null) {
        if (tokenEnhancer != null) {
            TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
            tokenEnhancerChain.setTokenEnhancers(
                    Arrays.asList(tokenEnhancer, jwtAccessTokenConverter));
            endpoints.tokenEnhancer(tokenEnhancerChain);
        } else {
            endpoints.accessTokenConverter(jwtAccessTokenConverter);
        }
    }
    endpoints.tokenStore(tokenStore)
            .authenticationManager(authenticationManager)
            .userDetailsService(userDetailsService)
            .authorizationCodeServices(authorizationCodeServices)
            .exceptionTranslator(webResponseExceptionTranslator);
}
 
Example #2
Source File: PcAuthorizationServerConfig.java    From paascloud-master with Apache License 2.0 6 votes vote down vote up
/**
 * Configure.
 *
 * @param endpoints the endpoints
 *
 * @throws Exception the exception
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
	endpoints.tokenStore(tokenStore)
			.authenticationManager(authenticationManager)
			.userDetailsService(userDetailsService);

	if (jwtAccessTokenConverter != null && jwtTokenEnhancer != null) {
		TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
		List<TokenEnhancer> enhancers = new ArrayList<>();
		enhancers.add(jwtTokenEnhancer);
		enhancers.add(jwtAccessTokenConverter);
		enhancerChain.setTokenEnhancers(enhancers);
		endpoints.tokenEnhancer(enhancerChain).accessTokenConverter(jwtAccessTokenConverter);
	}
}
 
Example #3
Source File: AuthorizationServerConfig.java    From java-tutorial with MIT License 6 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.tokenStore(jdbcTokenStore)
            .authenticationManager(authenticationManager)
            .userDetailsService(userDetailsService);

    if (jwtAccessTokenConverter != null && jwtTokenEnhancer != null) {
        TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
        ArrayList enhancerList = new ArrayList();
        enhancerList.add(jwtTokenEnhancer);
        enhancerList.add(jwtAccessTokenConverter);
        tokenEnhancerChain.setTokenEnhancers(enhancerList);
        endpoints.tokenEnhancer(tokenEnhancerChain)
                .accessTokenConverter(jwtAccessTokenConverter);
    }
    // 配置TokenServices参数
    endpoints.tokenServices(defaultTokenServices());
}
 
Example #4
Source File: SophiaAuthorizationServerConfig.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
/**
 * 配置授权服务器端点
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    // 自定义jwt生成token方式
    TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), accessTokenConverter()));
    //指定认证管理器
    endpoints.authenticationManager(authenticationManager)
            .userDetailsService(sophiaUserDetailService)
            .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST)
            //指定token存储位置
            .tokenStore(tokenStore())
            .accessTokenConverter(accessTokenConverter())
            // 自定义jwt生成token方式
            .tokenEnhancer(tokenEnhancerChain)
            // 配置TokenServices参数 如果需要默认的uuid就不用注释了
            // .tokenServices(defaultTokenServices())
            .reuseRefreshTokens(false)
            //自定义异常处理
            .exceptionTranslator(new SophiaWebResponseExceptionTranslator());
}
 
Example #5
Source File: SophiaAuthorizationServerConfig.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
/**
 * 配置授权服务器端点
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    // 自定义jwt生成token方式
    TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), accessTokenConverter()));
    //指定认证管理器
    endpoints.authenticationManager(authenticationManager)
            .userDetailsService(sophiaUserDetailService)
            .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST)
            //指定token存储位置
            .tokenStore(tokenStore())
            .accessTokenConverter(accessTokenConverter())
            // 自定义jwt生成token方式
            .tokenEnhancer(tokenEnhancerChain)
            // 配置TokenServices参数 如果需要默认的uuid就不用注释了
            // .tokenServices(defaultTokenServices())
            .reuseRefreshTokens(false)
            //自定义异常处理
            .exceptionTranslator(new SophiaWebResponseExceptionTranslator());
}
 
Example #6
Source File: SophiaAuthorizationServerConfig.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
/**
 * 配置授权服务器端点
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    // 自定义jwt生成token方式
    TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), accessTokenConverter()));
    //指定认证管理器
    endpoints.authenticationManager(authenticationManager)
            .userDetailsService(sophiaUserDetailService)
            .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST)
            //指定token存储位置
            .tokenStore(tokenStore())
            .accessTokenConverter(accessTokenConverter())
            // 自定义jwt生成token方式
            .tokenEnhancer(tokenEnhancerChain)
            // 配置TokenServices参数 如果需要jw的token而不是默认生成的uuid 那把他注释
            //.tokenServices(defaultTokenServices())
            .tokenServices(defaultTokenServices())
            .reuseRefreshTokens(false)
    // ;  //自定义异常处理
            .exceptionTranslator(new SophiaWebResponseExceptionTranslator());
}
 
Example #7
Source File: AuthorizationServerConfiguration.java    From fw-spring-cloud with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.tokenStore(tokenStore)
            .authenticationManager(authenticationManager)
            .userDetailsService(userDetailsService);
    //扩展token返回结果
    if (jwtAccessTokenConverter != null && jwtTokenEnhancer != null) {
        TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
        List<TokenEnhancer> enhancerList = new ArrayList();
        enhancerList.add(jwtTokenEnhancer);
        enhancerList.add(jwtAccessTokenConverter);
        tokenEnhancerChain.setTokenEnhancers(enhancerList);
        //jwt
        endpoints.tokenEnhancer(tokenEnhancerChain)
                .accessTokenConverter(jwtAccessTokenConverter);
    }
}
 
Example #8
Source File: UaaConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    //pick up all  TokenEnhancers incl. those defined in the application
    //this avoids changes to this class if an application wants to add its own to the chain
    Collection<TokenEnhancer> tokenEnhancers = applicationContext.getBeansOfType(TokenEnhancer.class).values();
    TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(new ArrayList<>(tokenEnhancers));
    endpoints
        .authenticationManager(authenticationManager)
        .tokenStore(tokenStore())
        .tokenEnhancer(tokenEnhancerChain)
        .reuseRefreshTokens(false);             //don't reuse or we will run into session inactivity timeouts
}
 
Example #9
Source File: AuthorizationServerConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
protected TokenEnhancerChain tokenEnhancerChain(){
	TokenEnhancerChain chain = new TokenEnhancerChain();
	if(tokenEnhancers!=null){
		chain.setTokenEnhancers(tokenEnhancers);
	}
	return chain;
}
 
Example #10
Source File: OAuth2AuthorizationServerConfigInMemory.java    From spring-security-oauth with MIT License 5 votes vote down vote up
@Override
  public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
      // @formatter:off
final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer()));
endpoints.tokenStore(tokenStore())
		// .accessTokenConverter(accessTokenConverter())
		.tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager);
// @formatter:on
  }
 
Example #11
Source File: OAuth2Config.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
	TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
	tokenEnhancerChain.setTokenEnhancers(
			Arrays.asList(
					tokenEnhancer(), 
					accessTokenConverter()
				));
	
	
	endpoints.authenticationManager(authenticationManager)
			.tokenStore(mongoTokenStore)
			.tokenEnhancer(tokenEnhancerChain)
			.allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST);
}
 
Example #12
Source File: AuthorizationServerConfig.java    From incubator-wikift with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
    enhancerChain.setTokenEnhancers(Arrays.asList(accessTokenConverter));
    endpoints.tokenStore(tokenStore)
            .accessTokenConverter(accessTokenConverter)
            .tokenEnhancer(enhancerChain)
            .authenticationManager(authenticationManager);
}
 
Example #13
Source File: AuthServerOAuth2Config.java    From Building-Web-Apps-with-Spring-5-and-Angular with MIT License 5 votes vote down vote up
@Override
  public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer()));
endpoints.tokenStore(tokenStore())
		.tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager);
  }
 
Example #14
Source File: AuthServerOAuth2Config.java    From Building-Web-Apps-with-Spring-5-and-Angular with MIT License 5 votes vote down vote up
@Override
  public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer()));
endpoints.tokenStore(tokenStore())
		.tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager);
  }
 
Example #15
Source File: OAuth2AuthorizationServerConfiguration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

    TokenEnhancerChain chain = new TokenEnhancerChain();
    chain.setTokenEnhancers(
            Arrays.asList(enhancer, accessTokenConverter()));

    endpoints
            .authenticationManager(authenticationManager)
            .tokenStore(jwtTokenStore())
            .tokenEnhancer(chain)
            .accessTokenConverter(accessTokenConverter());
}
 
Example #16
Source File: OAuth2AuthorizationServer.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    TokenEnhancerChain chain = new TokenEnhancerChain();
    chain.setTokenEnhancers(Arrays.asList(
            new PoPTokenEnhancer(),
            accessTokenConverter(),
            new CleanTokenEnhancer()));

    endpoints
        .tokenEnhancer(chain);
}
 
Example #17
Source File: AuthorizationServerConfig.java    From SpringAll with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
    List<TokenEnhancer> enhancers = new ArrayList<>();
    enhancers.add(tokenEnhancer);
    enhancers.add(jwtAccessTokenConverter);
    enhancerChain.setTokenEnhancers(enhancers);
    endpoints.authenticationManager(authenticationManager)
            .tokenStore(jwtTokenStore)
            .accessTokenConverter(jwtAccessTokenConverter)
            .userDetailsService(userDetailService);
}
 
Example #18
Source File: JWTOAuth2Config.java    From spring-microservices-in-action with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(Arrays.asList(jwtTokenEnhancer, jwtAccessTokenConverter));   // Spring Security allows you to hook multiple token enhancers

    endpoints.tokenStore(tokenStore)                                                                  // The JWTTokenStoreConfig.tokenStore() will be injected in here
            .accessTokenConverter(jwtAccessTokenConverter)                                            // The JWTTokenStoreConfig.jwtAccessTokenConverter() will be injected in here
            .tokenEnhancer(tokenEnhancerChain)                                                        // The chain of token enhancers will be passed into the endpoint
            .authenticationManager(authenticationManager)
            .userDetailsService(userDetailsService);
}
 
Example #19
Source File: AuthorizationServerConfiguration.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
     * 用来配置授权(authorization)以及令牌(token)的访问端点和令牌服务(token services)
     *
     * @param endpoints
     * @throws Exception
     */
    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        // 配置tokenStore
//    endpoints.authenticationManager(authenticationManager).tokenStore(tokenStore())
//            .accessTokenConverter(accessTokenConverter()).userDetailsService(userDetailsService);
        //指定认证管理器
        endpoints.authenticationManager(authenticationManager);
        //指定token存储位置
        endpoints.tokenStore(tokenStore());

        endpoints.accessTokenConverter(accessTokenConverter());
        endpoints.userDetailsService(userDetailsService);
        //自定义token生成方式
        TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
        tokenEnhancerChain.setTokenEnhancers(Arrays.asList(customerEnhancer(), accessTokenConverter()));
        endpoints.tokenEnhancer(tokenEnhancerChain);

        // 配置TokenServices参数
        DefaultTokenServices tokenServices = (DefaultTokenServices) endpoints.getDefaultAuthorizationServerTokenServices();
        tokenServices.setTokenStore(endpoints.getTokenStore());
        tokenServices.setSupportRefreshToken(true);
        tokenServices.setClientDetailsService(endpoints.getClientDetailsService());
        tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer());
        tokenServices.setAccessTokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(1));//一天
        endpoints.tokenServices(tokenServices);
    }
 
Example #20
Source File: OAuth2Config.java    From spring-cloud-study with Apache License 2.0 5 votes vote down vote up
@Override
    public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        /**
         * 普通 jwt 模式
         */
//         endpoints.tokenStore(jwtTokenStore)
//                .accessTokenConverter(jwtAccessTokenConverter)
//                .userDetailsService(kiteUserDetailsService)
//                /**
//                 * 支持 password 模式
//                 */
//                .authenticationManager(authenticationManager);

        /**
         * jwt 增强模式
         */
        TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
        List<TokenEnhancer> enhancerList = new ArrayList<>();
        enhancerList.add(jwtTokenEnhancer);
        enhancerList.add(jwtAccessTokenConverter);
        enhancerChain.setTokenEnhancers(enhancerList);
        endpoints.tokenStore(jwtTokenStore)
                .userDetailsService(kiteUserDetailsService)
                /**
                 * 支持 password 模式
                 */
                .authenticationManager(authenticationManager)
                .tokenEnhancer(enhancerChain)
                .accessTokenConverter(jwtAccessTokenConverter);

        /**
         * redis token 方式
         */
//        endpoints.authenticationManager(authenticationManager)
//                .tokenStore(redisTokenStore)
//                .userDetailsService(kiteUserDetailsService);

    }
 
Example #21
Source File: OAuth2AuthorizationServerConfig.java    From oauth2lab with MIT License 5 votes vote down vote up
@Override
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer()));
    endpoints.tokenStore(tokenStore())
        .tokenEnhancer(tokenEnhancerChain)
        .authenticationManager(authenticationManager);
}
 
Example #22
Source File: FwAuthorizationConfiguration.java    From fw-cloud-framework with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
	TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
	tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), jwtAccessTokenConverter()));
	endpoints.tokenStore(redisTokenStore())
			.tokenEnhancer(tokenEnhancerChain)
			.authenticationManager(authenticationManager)
			.reuseRefreshTokens(false)
			.userDetailsService(userDetailsService);
}
 
Example #23
Source File: PigAuthorizationConfig.java    From pig with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    //token增强配置
    TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(
            Arrays.asList(tokenEnhancer(), jwtAccessTokenConverter()));

    endpoints
            .tokenStore(redisTokenStore())
            .tokenEnhancer(tokenEnhancerChain)
            .authenticationManager(authenticationManager)
            .reuseRefreshTokens(false)
            .userDetailsService(userDetailsService);
}
 
Example #24
Source File: UaaConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    //pick up all  TokenEnhancers incl. those defined in the application
    //this avoids changes to this class if an application wants to add its own to the chain
    Collection<TokenEnhancer> tokenEnhancers = applicationContext.getBeansOfType(TokenEnhancer.class).values();
    TokenEnhancerChain tokenEnhancerChain=new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(new ArrayList<>(tokenEnhancers));
    endpoints
        .authenticationManager(authenticationManager)
        .tokenStore(tokenStore())
        .tokenEnhancer(tokenEnhancerChain)
        .reuseRefreshTokens(false);             //don't reuse or we will run into session inactivity timeouts
}
 
Example #25
Source File: OAuth2Config.java    From spring-cloud-study with Apache License 2.0 5 votes vote down vote up
@Override
    public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        /**
         * 普通 jwt 模式
         */
//         endpoints.tokenStore(jwtTokenStore)
//                .accessTokenConverter(jwtAccessTokenConverter)
//                .userDetailsService(kiteUserDetailsService)
//                /**
//                 * 支持 password 模式
//                 */
//                .authenticationManager(authenticationManager);

        /**
         * jwt 增强模式
         */
        TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
        List<TokenEnhancer> enhancerList = new ArrayList<>();
        enhancerList.add(jwtTokenEnhancer);
        enhancerList.add(jwtAccessTokenConverter);
        enhancerChain.setTokenEnhancers(enhancerList);
        endpoints.tokenStore(jwtTokenStore)
                .userDetailsService(kiteUserDetailsService)
                /**
                 * 支持 password 模式
                 */
                .authenticationManager(authenticationManager)
                .tokenEnhancer(enhancerChain)
                .accessTokenConverter(jwtAccessTokenConverter);

        /**
         * redis token 方式
         */
//        endpoints.authenticationManager(authenticationManager)
//                .tokenStore(redisTokenStore)
//                .userDetailsService(kiteUserDetailsService);

    }
 
Example #26
Source File: Oauth2AuthorizationServerConfig.java    From spring-security-oauth2-demo with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
//        endpoints.authenticationManager(this.authenticationManager)
//                .tokenStore(tokenStore())
//                .accessTokenConverter(jwtAccessTokenConverter());

        TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
        tokenEnhancerChain.setTokenEnhancers(
                Arrays.asList(tokenEnhancer(), jwtAccessTokenConverter()));

        endpoints.tokenStore(tokenStore())
                .tokenEnhancer(tokenEnhancerChain)
                .authenticationManager(authenticationManager);
    }
 
Example #27
Source File: OAuth2AuthorizationServerConfig.java    From spring-security-oauth with MIT License 4 votes vote down vote up
@Override
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer()));
    endpoints.tokenStore(tokenStore()).tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager);
}
 
Example #28
Source File: OAuth2AuthorizationServerConfigJwt.java    From spring-security-oauth with MIT License 4 votes vote down vote up
@Override
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), accessTokenConverter()));
    endpoints.tokenStore(tokenStore()).tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager);
}
 
Example #29
Source File: AuthorizationConfig.java    From springcloud-oauth2 with MIT License votes vote down vote up
@Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        // 采用token转jwt,并添加一些自定义信息(token增强)(有默认非必须)
        TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
        tokenEnhancerChain.setTokenEnhancers(
                Arrays.asList(jwtAccessTokenConverter(),tokenEnhancer()));
        endpoints.tokenEnhancer(tokenEnhancerChain)
                // 配置token存储,一般配置redis存储
                .tokenStore(tokenStore())
                // 配置认证管理器
                .authenticationManager(authenticationManager)
                // 配置用户详情server,密码模式必须
                .userDetailsService(userDetailsService)
                // 配置授权码模式授权码服务,不配置默认为内存模式
                .authorizationCodeServices(authorizationCodeServices())
                // 配置grant_type模式,如果不配置则默认使用密码模式、简化模式、验证码模式以及刷新token模式,如果配置了只使用配置中,默认配置失效
                // 具体可以查询AuthorizationServerEndpointsConfigurer中的getDefaultTokenGranters方法
                .tokenGranter(tokenGranter(endpoints));
        // 配置TokenServices参数
        DefaultTokenServices tokenServices = new DefaultTokenServices();
        tokenServices.setTokenStore(endpoints.getTokenStore());
        // 是否支持刷新Token
        tokenServices.setSupportRefreshToken(true);
        tokenServices.setReuseRefreshToken(true);
        tokenServices.setClientDetailsService(endpoints.getClientDetailsService());
        tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer());
        // 设置accessToken和refreshToken的默认超时时间(如果clientDetails的为null就取默认的,如果clientDetails的不为null取clientDetails中的)
        tokenServices.setAccessTokenValiditySeconds((int) TimeUnit.HOURS.toSeconds(2));
        tokenServices.setRefreshTokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(30));
        endpoints.tokenServices(tokenServices);

    }