Search in sources :

Example 6 with OAuth2UrisFactory

use of org.forgerock.oauth2.core.OAuth2UrisFactory in project OpenAM by OpenRock.

the class DeviceCodeGrantTypeHandlerTest method setup.

@BeforeMethod
public void setup() throws Exception {
    initMocks(this);
    OAuth2ProviderSettingsFactory providerSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
    when(providerSettingsFactory.get(request)).thenReturn(providerSettings);
    when(providerSettings.getDeviceCodePollInterval()).thenReturn(5);
    when(providerSettings.validateRequestedClaims(anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    OAuth2UrisFactory oAuth2UrisFactory = mock(OAuth2UrisFactory.class);
    when(oAuth2UrisFactory.get(request)).thenReturn(oAuth2Uris);
    ClientAuthenticator clientAuthenticator = mock(ClientAuthenticator.class);
    ClientRegistration clientRegistration = mock(ClientRegistration.class);
    when(clientAuthenticator.authenticate(eq(request), anyString())).thenReturn(clientRegistration);
    accessTokenGenerator = new GrantTypeAccessTokenGenerator(tokenStore);
    when(tokenStore.createAccessToken(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anySetOf(String.class), any(RefreshToken.class), anyString(), anyString(), any(OAuth2Request.class))).thenReturn(accessToken);
    when(tokenStore.createRefreshToken(anyString(), anyString(), anyString(), anyString(), anySetOf(String.class), any(OAuth2Request.class), anyString())).thenReturn(refreshToken);
    ClientAuthenticationFailureFactory failureFactory = mock(ClientAuthenticationFailureFactory.class);
    InvalidClientException expectedResult = mock(InvalidClientException.class);
    when(expectedResult.getError()).thenReturn("invalid_client");
    when(failureFactory.getException()).thenReturn(expectedResult);
    when(failureFactory.getException(anyString())).thenReturn(expectedResult);
    when(failureFactory.getException(any(OAuth2Request.class), anyString())).thenReturn(expectedResult);
    grantTypeHandler = new DeviceCodeGrantTypeHandler(providerSettingsFactory, clientAuthenticator, tokenStore, clientRegistrationStore, failureFactory, oAuth2UrisFactory, accessTokenGenerator);
}
Also used : ClientAuthenticationFailureFactory(org.forgerock.oauth2.core.exceptions.ClientAuthenticationFailureFactory) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InvalidClientException(org.forgerock.oauth2.core.exceptions.InvalidClientException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with OAuth2UrisFactory

use of org.forgerock.oauth2.core.OAuth2UrisFactory in project OpenAM by OpenRock.

the class OpenAMResourceSetStoreTest method setup.

@BeforeMethod
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    dataStore = mock(TokenDataStore.class);
    OAuth2ProviderSettingsFactory providerSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
    OAuth2UrisFactory<RealmInfo> oAuth2UrisFactory = mock(OAuth2UrisFactory.class);
    OAuth2Uris oAuth2Uris = mock(OAuth2Uris.class);
    TokenIdGenerator idGenerator = mock(TokenIdGenerator.class);
    store = new OpenAMResourceSetStore("REALM", providerSettingsFactory, oAuth2UrisFactory, idGenerator, dataStore);
    given(oAuth2UrisFactory.get(Matchers.<OAuth2Request>anyObject())).willReturn(oAuth2Uris);
    given(oAuth2Uris.getResourceSetRegistrationPolicyEndpoint(anyString())).willReturn("POLICY_URI");
}
Also used : TokenDataStore(org.forgerock.openam.sm.datalayer.store.TokenDataStore) RealmInfo(org.forgerock.openam.core.RealmInfo) TokenIdGenerator(org.forgerock.openam.cts.api.tokens.TokenIdGenerator) OAuth2ProviderSettingsFactory(org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory) OAuth2Uris(org.forgerock.oauth2.core.OAuth2Uris) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

OAuth2ProviderSettingsFactory (org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory)5 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 ClientAuthenticationFailureFactory (org.forgerock.oauth2.core.exceptions.ClientAuthenticationFailureFactory)3 RealmInfo (org.forgerock.openam.core.RealmInfo)3 Request (org.restlet.Request)3 SecureRandom (java.security.SecureRandom)2 AccessToken (org.forgerock.oauth2.core.AccessToken)2 ClientRegistrationStore (org.forgerock.oauth2.core.ClientRegistrationStore)2 OAuth2Uris (org.forgerock.oauth2.core.OAuth2Uris)2 OAuth2UrisFactory (org.forgerock.oauth2.core.OAuth2UrisFactory)2 TokenStore (org.forgerock.oauth2.core.TokenStore)2 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)2 RestletOAuth2Request (org.forgerock.oauth2.restlet.RestletOAuth2Request)2 OpenIdConnectClientRegistrationStore (org.forgerock.openidconnect.OpenIdConnectClientRegistrationStore)2 BDDMockito.anyString (org.mockito.BDDMockito.anyString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TypeLiteral (com.google.inject.TypeLiteral)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1