Java Code Examples for org.springframework.security.oauth2.provider.client.ClientCredentialsTokenGranter

The following examples show how to use org.springframework.security.oauth2.provider.client.ClientCredentialsTokenGranter. These examples are extracted from open source projects. 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 Project: osiam   Source File: OAuth2AuthorizationServerConfig.java    License: MIT License 6 votes vote down vote up
@Bean
public TokenGranter tokenGranter() throws Exception {
    return new CompositeTokenGranter(Arrays.asList(new TokenGranter[]{
            new ClientCredentialsTokenGranter(
                    tokenServices(), osiamClientDetailsService, oAuth2RequestFactory()
            ),
            new OsiamResourceOwnerPasswordTokenGranter(
                    authenticationManager, tokenServices(), osiamClientDetailsService, oAuth2RequestFactory()
            ),
            new RefreshTokenGranter(
                    tokenServices(), osiamClientDetailsService, oAuth2RequestFactory()
            ),
            new LessStrictRedirectUriAuthorizationCodeTokenGranter(
                    tokenServices(), authorizationCodeServices(), osiamClientDetailsService, oAuth2RequestFactory()
            )
    }));
}
 
Example 2
protected TokenGranter getTokenGranter(String grantType) {

        if ("authorization_code".equals(grantType)) {
            return new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientDetailsService, this.oAuth2RequestFactory);
        } else if ("password".equals(grantType)) {
            return new ResourceOwnerPasswordTokenGranter(getAuthenticationManager(), tokenServices, clientDetailsService, this.oAuth2RequestFactory);
        } else if ("refresh_token".equals(grantType)) {
            return new RefreshTokenGranter(tokenServices, clientDetailsService, this.oAuth2RequestFactory);
        } else if ("client_credentials".equals(grantType)) {
            return new ClientCredentialsTokenGranter(tokenServices, clientDetailsService, this.oAuth2RequestFactory);
        } else if ("implicit".equals(grantType)) {
            return new ImplicitTokenGranter(tokenServices, clientDetailsService, this.oAuth2RequestFactory);
        } else {
            throw new UnsupportedGrantTypeException("Unsupport grant_type: " + grantType);
        }
    }
 
Example 3
/**
 * 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 4
/**
 * 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 5
Source Project: spring-cloud-shop   Source File: OAuth2SecurityConfiguration.java    License: 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());
}