Search in sources :

Example 6 with ClientRegistrationStore

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

the class IdTokenClaimGathererTest method setup.

@BeforeMethod
public void setup() throws Exception {
    initMocks(this);
    OAuth2ProviderSettingsFactory oAuth2ProviderSettingsFactory = mockOAuth2ProviderSettings();
    OAuth2UrisFactory<RealmInfo> oauth2UrisFactory = mockOAuth2Uris();
    ClientRegistrationStore clientRegistrationStore = mockClientRegistrationStore();
    claimGatherer = spy(new IdTokenClaimGatherer(oAuth2ProviderSettingsFactory, oauth2UrisFactory, clientRegistrationStore, jwtReconstruction, signingManager));
    given(jwtReconstruction.reconstructJwt(anyString(), eq(SignedJwt.class))).willReturn(idToken);
    given(idToken.getHeader()).willReturn(jwsHeader);
    given(idToken.getClaimsSet()).willReturn(claimsSet);
}
Also used : RealmInfo(org.forgerock.openam.core.RealmInfo) OAuth2ProviderSettingsFactory(org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory) ClientRegistrationStore(org.forgerock.oauth2.core.ClientRegistrationStore) SignedJwt(org.forgerock.json.jose.jws.SignedJwt) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ClientRegistrationStore

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

the class AuthorizationServiceImplTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    requestValidator = mock(AuthorizeRequestValidator.class);
    List<AuthorizeRequestValidator> requestValidators = new ArrayList<AuthorizeRequestValidator>();
    requestValidators.add(requestValidator);
    resourceOwnerSessionValidator = mock(ResourceOwnerSessionValidator.class);
    OAuth2ProviderSettingsFactory providerSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
    resourceOwnerConsentVerifier = mock(ResourceOwnerConsentVerifier.class);
    clientRegistrationStore = mock(ClientRegistrationStore.class);
    tokenIssuer = mock(AuthorizationTokenIssuer.class);
    ClientAuthenticationFailureFactory failureFactory = mock(ClientAuthenticationFailureFactory.class);
    authorizationService = new AuthorizationServiceImpl(requestValidators, resourceOwnerSessionValidator, providerSettingsFactory, resourceOwnerConsentVerifier, clientRegistrationStore, tokenIssuer, failureFactory);
    providerSettings = mock(OAuth2ProviderSettings.class);
    given(providerSettingsFactory.get(Matchers.<OAuth2Request>anyObject())).willReturn(providerSettings);
}
Also used : ArrayList(java.util.ArrayList) ClientAuthenticationFailureFactory(org.forgerock.oauth2.core.exceptions.ClientAuthenticationFailureFactory) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with ClientRegistrationStore

use of org.forgerock.oauth2.core.ClientRegistrationStore 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 9 with ClientRegistrationStore

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

the class EndSessionTest method setup.

@BeforeMethod
public void setup() throws InvalidClientException, SignatureException, NotFoundException {
    idToken = "eyAidHlwIjogIkpXVCIsICJhbGciOiAiSFMyNTYiIH0.eyAidG9rZW5OYW1lIjogImlkX3Rva2VuIiwgImF6cCI6ICJOZXdPcG" + "VuSWRDbGllbnQiLCAic3ViIjogIlRlc3RVc2VyIiwgImF0X2hhc2giOiAibHhSNE1BcGV1aXl0dWxiVFI4OV9wQSIsICJpc3MiOi" + "AiaHR0cDovL29wZW5hbS5leGFtcGxlLmNvbTo4MDgwL29wZW5hbS9vYXV0aDIiLCAib3JnLmZvcmdlcm9jay5vcGVuaWRjb25uZW" + "N0Lm9wcyI6ICI2OTYzOTc4MC04NjkzLTQ1ODktOTk1Ni05ZThkM2UxZWI2YjQiLCAiaWF0IjogMTQzNjM1MjM4MiwgImF1dGhfdG" + "ltZSI6IDE0MzYzNTIzODIsICJleHAiOiAxNDM2MzUyOTgyLCAidG9rZW5UeXBlIjogIkpXVFRva2VuIiwgIm5vbmNlIjogIjEyMz" + "Q1IiwgInJlYWxtIjogIi8iLCAiYXVkIjogWyAiTmV3T3BlbklkQ2xpZW50IiBdLCAiY19oYXNoIjogIkY3RENrMkE5cDVmeUN0VF" + "hpYmF5V2ciIH0.0uIyHGAsr04gu9H4cJ57UPYVJmSJwjCakozPATlCcuE";
    oAuth2Request = mock(OAuth2Request.class);
    when(oAuth2Request.getParameter(OAuth2Constants.Params.END_SESSION_ID_TOKEN_HINT)).thenReturn(idToken);
    OAuth2RequestFactory<?, Request> requestFactory = mock(OAuth2RequestFactory.class);
    ExceptionHandler exceptionHandler = mock(ExceptionHandler.class);
    ClientRegistrationStore clientRegistrationStore = mock(ClientRegistrationStore.class);
    openIDConnectEndSession = mock(OpenIDConnectEndSession.class);
    endSession = new EndSession(requestFactory, openIDConnectEndSession, exceptionHandler, clientRegistrationStore);
    Request request = mock(Request.class);
    Response response = mock(Response.class);
    when(response.getEntity()).thenReturn(mock(Representation.class));
    endSession.setRequest(request);
    endSession.setResponse(response);
    when(requestFactory.create(any(Request.class))).thenReturn(oAuth2Request);
    client = mock(ClientRegistration.class);
    when(clientRegistrationStore.get(anyString(), any(OAuth2Request.class))).thenReturn(client);
}
Also used : ExceptionHandler(org.forgerock.oauth2.restlet.ExceptionHandler) Response(org.restlet.Response) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) ClientRegistration(org.forgerock.oauth2.core.ClientRegistration) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OpenIDConnectEndSession(org.forgerock.openidconnect.OpenIDConnectEndSession) OpenIDConnectEndSession(org.forgerock.openidconnect.OpenIDConnectEndSession) Representation(org.restlet.representation.Representation) ClientRegistrationStore(org.forgerock.oauth2.core.ClientRegistrationStore) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

BeforeMethod (org.testng.annotations.BeforeMethod)7 ClientRegistrationStore (org.forgerock.oauth2.core.ClientRegistrationStore)4 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)4 ClientRegistration (org.forgerock.oauth2.core.ClientRegistration)3 OAuth2ProviderSettingsFactory (org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory)3 ClientAuthenticationFailureFactory (org.forgerock.oauth2.core.exceptions.ClientAuthenticationFailureFactory)3 SecureRandom (java.security.SecureRandom)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 Request (org.restlet.Request)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1 AMIdentity (com.sun.identity.idm.AMIdentity)1 Debug (com.sun.identity.shared.debug.Debug)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 JsonValue (org.forgerock.json.JsonValue)1 SignedJwt (org.forgerock.json.jose.jws.SignedJwt)1