Search in sources :

Example 1 with DebugRestTemplateInterceptor

use of gov.ca.cwds.config.logging.DebugRestTemplateInterceptor in project perry by ca-cwds.

the class NoStateUserInfoRestTemplateCustomizerTest method testCustomize.

@Test
public void testCustomize() throws Exception {
    NoStateUserInfoRestTemplateCustomizer noStateUserInfoRestTemplateCustomizer = new NoStateUserInfoRestTemplateCustomizer();
    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(new AuthorizationCodeResourceDetails());
    noStateUserInfoRestTemplateCustomizer.customize(oAuth2RestTemplate);
    AccessTokenProviderChain accessTokenProvider = getFieldValue(oAuth2RestTemplate, "accessTokenProvider", AccessTokenProviderChain.class);
    assert accessTokenProvider != null;
    List list = getFieldValue(accessTokenProvider, "chain", List.class);
    assert list.size() == 4;
    assert list.stream().anyMatch(o -> o instanceof ImplicitAccessTokenProvider);
    assert list.stream().anyMatch(o -> o instanceof ResourceOwnerPasswordAccessTokenProvider);
    assert list.stream().anyMatch(o -> o instanceof ClientCredentialsAccessTokenProvider);
    assert list.stream().anyMatch(o -> o instanceof NoStateAuthorizationCodeTokenProvider);
    NoStateAuthorizationCodeTokenProvider noStateAuthorizationCodeTokenProvider = (NoStateAuthorizationCodeTokenProvider) list.stream().filter(o -> o instanceof NoStateAuthorizationCodeTokenProvider).findFirst().get();
    assert !getFieldValue(noStateAuthorizationCodeTokenProvider, "stateMandatory", Boolean.class);
    List interceptors = getFieldValue(noStateAuthorizationCodeTokenProvider, "interceptors", List.class);
    assert interceptors.size() == 1;
    assert interceptors.stream().anyMatch(o -> o instanceof DebugRestTemplateInterceptor);
}
Also used : AccessTokenProvider(org.springframework.security.oauth2.client.token.AccessTokenProvider) ClientCredentialsAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider) List(java.util.List) ImplicitAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider) DebugRestTemplateInterceptor(gov.ca.cwds.config.logging.DebugRestTemplateInterceptor) ResourceOwnerPasswordAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider) Test(org.junit.Test) AuthorizationCodeResourceDetails(org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails) Field(java.lang.reflect.Field) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) AccessTokenProviderChain(org.springframework.security.oauth2.client.token.AccessTokenProviderChain) ImplicitAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider) AccessTokenProviderChain(org.springframework.security.oauth2.client.token.AccessTokenProviderChain) AuthorizationCodeResourceDetails(org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails) List(java.util.List) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) ClientCredentialsAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider) ResourceOwnerPasswordAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider) DebugRestTemplateInterceptor(gov.ca.cwds.config.logging.DebugRestTemplateInterceptor) Test(org.junit.Test)

Example 2 with DebugRestTemplateInterceptor

use of gov.ca.cwds.config.logging.DebugRestTemplateInterceptor in project perry by ca-cwds.

the class NoStateUserInfoRestTemplateCustomizer method customize.

@Override
public void customize(OAuth2RestTemplate template) {
    AuthorizationCodeAccessTokenProvider noStateAuthorizationCodeTokenProvider = new NoStateAuthorizationCodeTokenProvider();
    noStateAuthorizationCodeTokenProvider.setInterceptors(Arrays.asList(new DebugRestTemplateInterceptor()));
    noStateAuthorizationCodeTokenProvider.setStateMandatory(false);
    template.setAccessTokenProvider(new AccessTokenProviderChain(Arrays.<AccessTokenProvider>asList(noStateAuthorizationCodeTokenProvider, new ImplicitAccessTokenProvider(), new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider())));
}
Also used : AuthorizationCodeAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider) ImplicitAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider) AccessTokenProviderChain(org.springframework.security.oauth2.client.token.AccessTokenProviderChain) ClientCredentialsAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider) AccessTokenProvider(org.springframework.security.oauth2.client.token.AccessTokenProvider) ClientCredentialsAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider) ImplicitAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider) AuthorizationCodeAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider) ResourceOwnerPasswordAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider) DebugRestTemplateInterceptor(gov.ca.cwds.config.logging.DebugRestTemplateInterceptor) ResourceOwnerPasswordAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider)

Aggregations

DebugRestTemplateInterceptor (gov.ca.cwds.config.logging.DebugRestTemplateInterceptor)2 AccessTokenProvider (org.springframework.security.oauth2.client.token.AccessTokenProvider)2 AccessTokenProviderChain (org.springframework.security.oauth2.client.token.AccessTokenProviderChain)2 ClientCredentialsAccessTokenProvider (org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider)2 ImplicitAccessTokenProvider (org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider)2 ResourceOwnerPasswordAccessTokenProvider (org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider)2 Field (java.lang.reflect.Field)1 List (java.util.List)1 Test (org.junit.Test)1 OAuth2RestTemplate (org.springframework.security.oauth2.client.OAuth2RestTemplate)1 AuthorizationCodeAccessTokenProvider (org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider)1 AuthorizationCodeResourceDetails (org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails)1