Java Code Examples for org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer#tokenStore()

The following examples show how to use org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer#tokenStore() . 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 cloud-service with MIT License 6 votes vote down vote up
@Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(this.authenticationManager);
        endpoints.tokenStore(tokenStore());
        // 授权码模式下,code存储
//		endpoints.authorizationCodeServices(new JdbcAuthorizationCodeServices(dataSource));
        endpoints.authorizationCodeServices(redisAuthorizationCodeServices);
        if (storeWithJwt) {
            endpoints.accessTokenConverter(accessTokenConverter());
        } else {
            // 2019.07.13 将当前用户信息追加到登陆后返回数据里
            endpoints.tokenEnhancer((accessToken, authentication) -> {
                addLoginUserInfo(accessToken, authentication);
                return accessToken;
            });
        }
    }
 
Example 2
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 3
Source File: AuthorizationServerConfiguration.java    From oauth2lab with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(authenticationManager);
    endpoints.tokenStore(tokenStore);
    endpoints.tokenGranter(tokenGranter);

    AuthorizationCodeServices codeServices = authorizationCodeServices;

    endpoints.authorizationCodeServices(codeServices);
}
 
Example 4
Source File: AuthServerConfig.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
	super.configure(endpoints);
	endpoints.authenticationManager(authenticationManagerBean);
	endpoints.tokenStore(tokenStore());
	endpoints.tokenEnhancer(new TokenEnhancer() {

		@Override
		public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
			if (authentication.getPrincipal() instanceof User) {
				final User user = (User) authentication.getPrincipal();

				final Set<String> scopes = new HashSet<String>();
				for (GrantedAuthority authority : user.getAuthorities()) {
					final String role = authority.getAuthority();

					if (role.startsWith("ROLE_")) {
						scopes.add(role.substring(5).toLowerCase());
					}
					else {
						scopes.add(role.toLowerCase());
					}
				}
				((DefaultOAuth2AccessToken) accessToken).setScope(scopes);

			}
			return accessToken;
		}
	});
}
 
Example 5
Source File: OAuth2AuthorizationServerConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
	if (this.tokenConverter != null) {
		endpoints.accessTokenConverter(this.tokenConverter);
	}
	if (this.tokenStore != null) {
		endpoints.tokenStore(this.tokenStore);
	}
	if (this.details.getAuthorizedGrantTypes().contains("password")) {
		endpoints.authenticationManager(this.authenticationManager);
	}
}
 
Example 6
Source File: AuthorizationServerConfiguration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(authenticationManager);
    endpoints.tokenStore(tokenStore);
    endpoints.tokenGranter(tokenGranter);

    AuthorizationCodeServices codeServices = authorizationCodeServices;

    endpoints.authorizationCodeServices(codeServices);
}
 
Example 7
Source File: AuthServerConfig.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
	super.configure(endpoints);
	endpoints.authenticationManager(authenticationManagerBean);
	endpoints.tokenStore(tokenStore());
	endpoints.tokenEnhancer(new TokenEnhancer() {

		@Override
		public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
			if (authentication.getPrincipal() instanceof User) {
				final User user = (User) authentication.getPrincipal();

				final Set<String> scopes = new HashSet<String>();
				for (GrantedAuthority authority : user.getAuthorities()) {
					final String role = authority.getAuthority();

					if (role.startsWith("ROLE_")) {
						scopes.add(role.substring(5).toLowerCase());
					}
					else {
						scopes.add(role.toLowerCase());
					}
				}
				((DefaultOAuth2AccessToken) accessToken).setScope(scopes);

			}
			return accessToken;
		}
	});
}
 
Example 8
Source File: AuthorizationServerConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
	if(tokenStore!=null){
		endpoints.tokenStore(tokenStore);
	}
	endpoints.tokenEnhancer(tokenEnhancerChain());
	
	this.oauth2Properties.getAuthorizationServer().getPathMappings().forEach((defPath, customPath) -> {
		endpoints.pathMapping(defPath, customPath);
	});
}
 
Example 9
Source File: AuthorizationServerConfiguration.java    From lolibox with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
        throws Exception {
    if (this.tokenStore != null) {
        endpoints.tokenStore(this.tokenStore);
    }
    endpoints.authenticationManager(this.authenticationManager);
}
 
Example 10
Source File: AuthorizationServerConfig.java    From platform with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    endpoints.authenticationManager(this.authenticationManager);
    endpoints.tokenStore(tokenStore());
    endpoints.accessTokenConverter(accessTokenConverter());
    // 默认情况下,只有第一次请求到的Refresh Token可用,
    // 后续刷新后获取到的Refresh Token都无法使用的
    // 这里可以根据实际情况做选择
    endpoints.reuseRefreshTokens(false);
}
 
Example 11
Source File: AuthorizationServerConfiguration.java    From spring-boot-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    // 设置令牌
    endpoints.tokenStore(tokenStore());
}
 
Example 12
Source File: OAuth2Config.java    From auth-server with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer configurer) throws Exception {
  configurer.authenticationManager(authenticationManager);
  configurer.userDetailsService(userService);
  configurer.tokenStore(tokenStore);
}
 
Example 13
Source File: OAuth2AuthorizationServer.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
        throws Exception {
    endpoints.tokenStore(tokenStore());
}
 
Example 14
Source File: AuthorizationServerConfiguration.java    From demo-spring-boot-security-oauth2 with MIT License 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
	endpoints.authenticationManager(this.authenticationManager);
	endpoints.accessTokenConverter(accessTokenConverter());
	endpoints.tokenStore(tokenStore());
}
 
Example 15
Source File: AuthorizationServerConfig.java    From cloud-project with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints.authenticationManager(this.authenticationManager);
    endpoints.accessTokenConverter(accessTokenConverter());
    endpoints.tokenStore(tokenStore());
}