org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest Java Examples

The following examples show how to use org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest. 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: OAuth2RestOperationsConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 6 votes vote down vote up
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
	DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(new DefaultAccessTokenRequest());
	Authentication principal = SecurityContextHolder.getContext().getAuthentication();
	if (principal instanceof OAuth2Authentication) {
		OAuth2Authentication authentication = (OAuth2Authentication) principal;
		Object details = authentication.getDetails();
		if (details instanceof OAuth2AuthenticationDetails) {
			OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
			String token = oauthsDetails.getTokenValue();
			context.setAccessToken(new DefaultOAuth2AccessToken(token));
		}
	}
	return context;
}
 
Example #2
Source File: UaaConnectionHelper.java    From uaa-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Get the OAuth access token (and refresh it if necessary)
 * 
 * @return
 */
private OAuth2AccessToken getAccessToken() {
	if (token == null) {
		token = CHAIN.obtainAccessToken(creds, new DefaultAccessTokenRequest());
	}
	else if (token.isExpired()) {
		refreshAccessToken();
	}

	return token;
}
 
Example #3
Source File: MockOAuth2ClientContext.java    From spring-cloud-security with Apache License 2.0 5 votes vote down vote up
@Override
public AccessTokenRequest getAccessTokenRequest() {
	DefaultAccessTokenRequest tokenRequest = new DefaultAccessTokenRequest(
			new HashMap<String, String[]>());
	tokenRequest.setExistingToken(new DefaultOAuth2AccessToken(value));
	return tokenRequest;
}
 
Example #4
Source File: OAuth2RestOperationsConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 4 votes vote down vote up
@Bean
public DefaultOAuth2ClientContext oauth2ClientContext() {
	return new DefaultOAuth2ClientContext(new DefaultAccessTokenRequest());
}
 
Example #5
Source File: OAuthClient.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
private AccessTokenRequest createAccessTokenRequest(String username, String password) {
    return new DefaultAccessTokenRequest();
}
 
Example #6
Source File: AuthorizationCodeGrantTests.java    From spring-boot-demo with MIT License 4 votes vote down vote up
@Test
void testAttemptedTokenAcquisitionWithNoRedirect() {
    AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider();
    assertThrows(UserRedirectRequiredException.class,
        () -> provider.obtainAccessToken(resource, new DefaultAccessTokenRequest()));
}
 
Example #7
Source File: UaaConnectionHelper.java    From uaa-java-client with Apache License 2.0 4 votes vote down vote up
/**
 * refresh the access token
 */
private void refreshAccessToken() {
	Assert.notNull(token);

	token = CHAIN.refreshAccessToken(creds, token.getRefreshToken(), new DefaultAccessTokenRequest());
}