org.springframework.security.oauth2.provider.code.AuthorizationCodeServices Java Examples

The following examples show how to use org.springframework.security.oauth2.provider.code.AuthorizationCodeServices. 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: ApiBootAuthorizationServerConfiguration.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Return all granters within oauth2
 * Contains custom
 *
 * @return TokenGranter
 */
private List<TokenGranter> getDefaultTokenGranters() {
    ClientDetailsService clientDetails = clientDetailsService;
    AuthorizationServerTokenServices tokenServices = tokenServices();
    AuthorizationCodeServices authorizationCodeServices = authorizationCodeServices();
    OAuth2RequestFactory requestFactory = requestFactory();

    List<TokenGranter> tokenGranters = new ArrayList<TokenGranter>();
    // code
    tokenGranters.add(new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientDetails,
            requestFactory));

    // refresh token
    tokenGranters.add(new RefreshTokenGranter(tokenServices, clientDetails, requestFactory));

    // implicit
    ImplicitTokenGranter implicit = new ImplicitTokenGranter(tokenServices, clientDetails, requestFactory);
    tokenGranters.add(implicit);

    // client
    tokenGranters.add(new ClientCredentialsTokenGranter(tokenServices, clientDetails, requestFactory));

    // password
    if (authenticationManager != null) {
        tokenGranters.add(new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices,
                clientDetails, requestFactory));
    }

    // have custom token granter
    if (!ObjectUtils.isEmpty(apiBootOauthTokenGranters)) {
        apiBootOauthTokenGranters.stream().forEach(apiBootOauthTokenGranter -> tokenGranters.add(new DefaultApiBootOauthTokenGranter(tokenServices, clientDetailsService, requestFactory, apiBootOauthTokenGranter)));
    }

    return tokenGranters;
}
 
Example #2
Source File: OAuth2Configuration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Bean
public TokenGranter tokenGranter() {

    DefaultOAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService());

    AuthorizationCodeServices codeServices = authorizationCodeServices();

    AuthorizationServerTokenServices tokenServices = tokenServices();
    List<TokenGranter> tokenGranters = Arrays.asList(
            new CustomAuthCodeTokenGranter(tokenServices, codeServices, clientDetailsService(), requestFactory),
            new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService(), requestFactory),
            new ImplicitTokenGranter(tokenServices, clientDetailsService(), requestFactory));

    return new CompositeTokenGranter(tokenGranters);
}
 
Example #3
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 #4
Source File: OAuth2SecurityConfiguration.java    From spring-cloud-shop with MIT License 5 votes vote down vote up
private List<TokenGranter> getTokenGranters(AuthorizationCodeServices authorizationCodeServices,
                                            AuthorizationServerTokenServices tokenServices,
                                            ClientDetailsService clientDetailsService,
                                            OAuth2RequestFactory requestFactory) {
    return Stream.of(
            new ClientCredentialsTokenGranter(tokenServices, clientDetailsService, requestFactory),
            new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService, requestFactory),
            new PhonePasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService, requestFactory),
            new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientDetailsService, requestFactory),
            new SmsTokenGranter(userServiceImpl, tokenServices, clientDetailsService, requestFactory))
            .collect(Collectors.toList());
}
 
Example #5
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 #6
Source File: OAuth2Configuration.java    From oauth2lab with MIT License 5 votes vote down vote up
@Bean
public TokenGranter tokenGranter() {

    DefaultOAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService());

    AuthorizationCodeServices codeServices = authorizationCodeServices();

    AuthorizationServerTokenServices tokenServices = tokenServices();
    List<TokenGranter> tokenGranters = Arrays.asList(
            new AuthorizationCodeTokenGranter(tokenServices, codeServices, clientDetailsService(), requestFactory),
            new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService(), requestFactory),
            new ImplicitTokenGranter(tokenServices, clientDetailsService(), requestFactory));

    return new CompositeTokenGranter(tokenGranters);
}
 
Example #7
Source File: ApiBootAuthorizationServerConfiguration.java    From api-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Return all granters within oauth2
 * Contains custom
 *
 * @return TokenGranter
 */
private List<TokenGranter> getDefaultTokenGranters() {
    ClientDetailsService clientDetails = clientDetailsService;
    AuthorizationServerTokenServices tokenServices = tokenServices();
    AuthorizationCodeServices authorizationCodeServices = authorizationCodeServices();
    OAuth2RequestFactory requestFactory = requestFactory();

    List<TokenGranter> tokenGranters = new ArrayList<TokenGranter>();
    // code
    tokenGranters.add(new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientDetails,
            requestFactory));

    // refresh token
    tokenGranters.add(new RefreshTokenGranter(tokenServices, clientDetails, requestFactory));

    // implicit
    ImplicitTokenGranter implicit = new ImplicitTokenGranter(tokenServices, clientDetails, requestFactory);
    tokenGranters.add(implicit);

    // client
    tokenGranters.add(new ClientCredentialsTokenGranter(tokenServices, clientDetails, requestFactory));

    // password
    if (authenticationManager != null) {
        tokenGranters.add(new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices,
                clientDetails, requestFactory));
    }

    // have custom token granter
    if (!ObjectUtils.isEmpty(apiBootOauthTokenGranters)) {
        apiBootOauthTokenGranters.stream().forEach(apiBootOauthTokenGranter -> tokenGranters.add(new DefaultApiBootOauthTokenGranter(tokenServices, clientDetailsService, requestFactory, apiBootOauthTokenGranter)));
    }

    return tokenGranters;
}
 
Example #8
Source File: LessStrictRedirectUriAuthorizationCodeTokenGranter.java    From osiam with MIT License 5 votes vote down vote up
public LessStrictRedirectUriAuthorizationCodeTokenGranter(
        AuthorizationServerTokenServices tokenServices,
        AuthorizationCodeServices authorizationCodeServices,
        ClientDetailsService clientDetailsService,
        OAuth2RequestFactory requestFactory
) {
    super(tokenServices, clientDetailsService, requestFactory, GRANT_TYPE);
    this.authorizationCodeServices = authorizationCodeServices;
}
 
Example #9
Source File: AuthorizationServerConfig.java    From moserp with Apache License 2.0 4 votes vote down vote up
@Bean
protected AuthorizationCodeServices authorizationCodeServices() {
    return new InMemoryAuthorizationCodeServices();
}
 
Example #10
Source File: OAuth2AuthorizationServerConfig.java    From osiam with MIT License 4 votes vote down vote up
@Bean
public AuthorizationCodeServices authorizationCodeServices() {
    return new InMemoryAuthorizationCodeServices();
}
 
Example #11
Source File: Oauth2AuthorizationServerApplication.java    From spring-oauth2-jwt-jdbc with MIT License 4 votes vote down vote up
@Bean
protected AuthorizationCodeServices authorizationCodeServices() {
    return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #12
Source File: OAuthConfiguration.java    From spring-boot-microservices with Apache License 2.0 4 votes vote down vote up
@Bean
protected AuthorizationCodeServices authorizationCodeServices() {
	return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #13
Source File: AuthorizationServerConfig.java    From SpringCloud with Apache License 2.0 4 votes vote down vote up
/**
 * 授权码模式持久化授权码code
 *
 * @return JdbcAuthorizationCodeServices
 */
@Bean
protected AuthorizationCodeServices authorizationCodeServices() {
    // 授权码存储等处理方式类,使用jdbc,操作oauth_code表
    return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #14
Source File: OAuth2ServerConfiguration.java    From spring-oauth-server with GNU General Public License v2.0 4 votes vote down vote up
@Bean
public AuthorizationCodeServices authorizationCodeServices(DataSource dataSource) {
    return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #15
Source File: ApiBootAuthorizationServerConfiguration.java    From beihu-boot with Apache License 2.0 4 votes vote down vote up
private AuthorizationCodeServices authorizationCodeServices() {
    return new InMemoryAuthorizationCodeServices();
}
 
Example #16
Source File: OAuth2Configuration.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
@Bean
public AuthorizationCodeServices authorizationCodeServices() {
    return new InMemoryAuthorizationCodeServices();
}
 
Example #17
Source File: OAuthConfiguration.java    From spring-oauth-example with MIT License 4 votes vote down vote up
@Bean
public AuthorizationCodeServices authorizationCodeServices() {
    return new JdbcAuthorizationCodeServices(oauthDataSource());
}
 
Example #18
Source File: CustomAuthCodeTokenGranter.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
protected CustomAuthCodeTokenGranter(AuthorizationServerTokenServices tokenServices, AuthorizationCodeServices authorizationCodeServices,
                                        ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory, String grantType) {
    super(tokenServices, clientDetailsService, requestFactory, grantType);
    this.authorizationCodeServices = authorizationCodeServices;
}
 
Example #19
Source File: CustomAuthCodeTokenGranter.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
public CustomAuthCodeTokenGranter(AuthorizationServerTokenServices tokenServices,
                                     AuthorizationCodeServices authorizationCodeServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory) {
    this(tokenServices, authorizationCodeServices, clientDetailsService, requestFactory, GRANT_TYPE);
}
 
Example #20
Source File: AuthenticationServerConfig.java    From JetfireCloud with Apache License 2.0 4 votes vote down vote up
/**
 * 授权码模式持久名授权码
 *
 * @return
 */
@Bean
protected AuthorizationCodeServices authorizationCodeServices() {
    //授权码存储等处理方式类,使用jdbc,操作oauth_code表
    return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #21
Source File: AuthApplication.java    From spring-cloud-shop with MIT License 4 votes vote down vote up
@Bean
public AuthorizationCodeServices jdbcAuthorizationCodeServices(DataSource dataSource) {
    return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #22
Source File: OAuth2Configuration.java    From oauth2lab with MIT License 4 votes vote down vote up
@Bean
public AuthorizationCodeServices authorizationCodeServices() {
    return new InMemoryAuthorizationCodeServices();
}
 
Example #23
Source File: AuthorizationServerConfig.java    From pacbot with Apache License 2.0 4 votes vote down vote up
@Bean
public AuthorizationCodeServices authorizationCodeServices() {
    return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #24
Source File: ApiBootAuthorizationServerConfiguration.java    From api-boot with Apache License 2.0 4 votes vote down vote up
private AuthorizationCodeServices authorizationCodeServices() {
    return new InMemoryAuthorizationCodeServices();
}
 
Example #25
Source File: AuthorizationServerConfiguration.java    From cola with MIT License 4 votes vote down vote up
@Bean
public AuthorizationCodeServices authorizationCodeServices() {
	return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #26
Source File: AuthorizationServerConfiguration.java    From open-cloud with MIT License 2 votes vote down vote up
/**
 * 授权码
 *
 * @return
 */
@Bean
public AuthorizationCodeServices authorizationCodeServices() {
    return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #27
Source File: AuthorizationServerConfiguration.java    From open-cloud with MIT License 2 votes vote down vote up
/**
 * 授权码存放
 *
 * @return
 */
@Bean
public AuthorizationCodeServices authorizationCodeServices() {
    return new JdbcAuthorizationCodeServices(dataSource);
}
 
Example #28
Source File: AuthorizationConfig.java    From springcloud-oauth2 with MIT License votes vote down vote up
/**
     * 配置授权码模式授权码服务,不配置默认为内存模式
     * @return
     */
    @Primary
    @Bean
    public AuthorizationCodeServices authorizationCodeServices() {
        return new RedisAuthorizationCodeServices(redisConnectionFactory);
    }