org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider Java Examples

The following examples show how to use org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider. 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: MyOAuth2RestTemplate.java    From springboot-security-wechat with Apache License 2.0 6 votes vote down vote up
public MyOAuth2RestTemplate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext context) {
    super(resource, context);
    this.accessTokenProvider = new MyAccessTokenProviderChain(Arrays.asList(new AccessTokenProvider[]{new MyAuthorizationCodeAccessTokenProvider(),
            new ImplicitAccessTokenProvider(),
            new ResourceOwnerPasswordAccessTokenProvider(),
            new ClientCredentialsAccessTokenProvider()}));
    this.retryBadAccessTokens = true;
    this.authenticator = new DefaultOAuth2RequestAuthenticator();
    if(resource == null) {
        throw new IllegalArgumentException("An OAuth2 resource must be supplied.");
    } else {
        this.resource = resource;
        this.context = context;
        this.setErrorHandler(new OAuth2ErrorHandler(resource));
    }
}
 
Example #2
Source File: SsoAuthClient.java    From cola with MIT License 5 votes vote down vote up
/**
 * 登录
 *
 * @param username
 * @param password
 * @return
 */
public OAuth2AccessToken login(String username, String password) {
	ResourceOwnerPasswordResourceDetails details = new ResourceOwnerPasswordResourceDetails();
	details.setUsername(username);
	details.setPassword(password);
	details.setAccessTokenUri(this.properties.getAccessTokenUri());
	details.setClientId(this.properties.getClientId());
	details.setClientSecret(this.properties.getClientSecret());
	OAuth2RestTemplate auth2RestTemplate = new OAuth2RestTemplate(details);
	auth2RestTemplate.setAccessTokenProvider(new ResourceOwnerPasswordAccessTokenProvider());
	return auth2RestTemplate.getAccessToken();
}
 
Example #3
Source File: OAuthClient.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
protected OAuth2AccessToken createToken() {
    OAuth2ProtectedResourceDetails resource = getResourceDetails(credentials.getEmail(), credentials.getPassword(),
                                                                 credentials.getClientId(), credentials.getClientSecret());
    AccessTokenRequest request = createAccessTokenRequest(credentials.getEmail(), credentials.getPassword());

    ResourceOwnerPasswordAccessTokenProvider provider = createResourceOwnerPasswordAccessTokenProvider();
    try {
        return provider.obtainAccessToken(resource, request);
    } catch (OAuth2AccessDeniedException oauthEx) {
        HttpStatus status = HttpStatus.valueOf(oauthEx.getHttpErrorCode());
        throw new CloudOperationException(status, oauthEx.getMessage(), oauthEx.getSummary());
    }
}
 
Example #4
Source File: OAuthClient.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
protected OAuth2AccessToken refreshToken() {
    OAuth2ProtectedResourceDetails resource = getResourceDetails(credentials.getEmail(), credentials.getPassword(),
                                                                 credentials.getClientId(), credentials.getClientSecret());
    AccessTokenRequest request = createAccessTokenRequest(credentials.getEmail(), credentials.getPassword());

    ResourceOwnerPasswordAccessTokenProvider provider = createResourceOwnerPasswordAccessTokenProvider();

    return provider.refreshAccessToken(resource, token.getRefreshToken(), request);
}
 
Example #5
Source File: OAuthClient.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
protected ResourceOwnerPasswordAccessTokenProvider createResourceOwnerPasswordAccessTokenProvider() {
    ResourceOwnerPasswordAccessTokenProvider resourceOwnerPasswordAccessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider();
    resourceOwnerPasswordAccessTokenProvider.setRequestFactory(restTemplate.getRequestFactory()); // copy the http proxy along
    return resourceOwnerPasswordAccessTokenProvider;
}
 
Example #6
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
@Bean
public OAuth2RestTemplate oauth2RestTemplate() {

    OAuth2ProtectedResourceDetails resourceDetails = passwordResourceDetails();

    OAuth2RestTemplate template = new OAuth2RestTemplate(resourceDetails,
            oauth2ClientContext);

    AccessTokenProviderChain provider = new AccessTokenProviderChain(
            Arrays.asList(new ResourceOwnerPasswordAccessTokenProvider()));

    provider.setClientTokenServices(clientTokenServices);
    template.setAccessTokenProvider(provider);

    return template;
}
 
Example #7
Source File: ManualOAuthAuthenticationProvider.java    From spring-cloud-dashboard with Apache License 2.0 4 votes vote down vote up
public AccessTokenProvider userAccessTokenProvider() {
	ResourceOwnerPasswordAccessTokenProvider accessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider();
	return accessTokenProvider;
}