Search in sources :

Example 11 with ClientCredentialsResourceDetails

use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails in project tutorials by eugenp.

the class CustomConfigAuthorizationServerIntegrationTest method givenOAuth2Context_whenAccessTokenIsRequestedByClientWithWriteScope_ThenAccessTokenIsNotNull.

@Test
public void givenOAuth2Context_whenAccessTokenIsRequestedByClientWithWriteScope_ThenAccessTokenIsNotNull() {
    ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("baeldung-admin", singletonList("write"));
    OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails);
    OAuth2AccessToken accessToken = restTemplate.getAccessToken();
    assertNotNull(accessToken);
}
Also used : OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) ClientCredentialsResourceDetails(org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 12 with ClientCredentialsResourceDetails

use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails in project tutorials by eugenp.

the class CustomConfigAuthorizationServerIntegrationTest method givenOAuth2Context_whenAccessTokenIsRequested_ThenAccessTokenValueIsNotNull.

@Test
public void givenOAuth2Context_whenAccessTokenIsRequested_ThenAccessTokenValueIsNotNull() {
    ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("baeldung", singletonList("read"));
    OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails);
    OAuth2AccessToken accessToken = restTemplate.getAccessToken();
    assertNotNull(accessToken);
}
Also used : OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) ClientCredentialsResourceDetails(org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 13 with ClientCredentialsResourceDetails

use of org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails in project tutorials by eugenp.

the class OAuth2IntegrationTestSupport method getOAuth2RestTemplate.

protected OAuth2RestTemplate getOAuth2RestTemplate(final ClientCredentialsResourceDetails resourceDetails) {
    DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext);
    restTemplate.setMessageConverters(singletonList(new MappingJackson2HttpMessageConverter()));
    return restTemplate;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) DefaultOAuth2ClientContext(org.springframework.security.oauth2.client.DefaultOAuth2ClientContext) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate)

Aggregations

ClientCredentialsResourceDetails (org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails)12 OAuth2RestTemplate (org.springframework.security.oauth2.client.OAuth2RestTemplate)9 Test (org.junit.Test)7 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Bean (org.springframework.context.annotation.Bean)3 DefaultOAuth2ClientContext (org.springframework.security.oauth2.client.DefaultOAuth2ClientContext)2 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)2 Api (com.faforever.server.config.ServerProperties.Api)1 Date (java.util.Date)1 PostConstruct (javax.annotation.PostConstruct)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 DefaultOAuth2RequestAuthenticator (org.springframework.security.oauth2.client.DefaultOAuth2RequestAuthenticator)1 DefaultAccessTokenRequest (org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest)1 ClientCredentialsAccessTokenProvider (org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider)1 DefaultExpiringOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken)1 DefaultOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken)1