Search in sources :

Example 1 with ClientRegistrationStore

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

the class OpenAMTokenStoreTest method realmAgnosticTokenStoreShouldIgnoreRealmMismatch.

@Test
public void realmAgnosticTokenStoreShouldIgnoreRealmMismatch() throws Exception {
    //Given
    OpenAMTokenStore realmAgnosticTokenStore = new OAuth2GuiceModule.RealmAgnosticTokenStore(tokenStore, providerSettingsFactory, oAuth2UrisFactory, clientRegistrationStore, realmNormaliser, ssoTokenManager, cookieExtractor, auditLogger, debug, new SecureRandom(), failureFactory);
    JsonValue token = json(object(field("tokenName", Collections.singleton("access_token")), field("realm", Collections.singleton("/otherrealm"))));
    given(tokenStore.read("TOKEN_ID")).willReturn(token);
    ConcurrentHashMap<String, Object> attributes = new ConcurrentHashMap<String, Object>();
    given(request.getAttributes()).willReturn(attributes);
    attributes.put("realm", "/testrealm");
    OAuth2Request request = oAuth2RequestFactory.create(this.request);
    //When
    AccessToken accessToken = realmAgnosticTokenStore.readAccessToken(request, "TOKEN_ID");
    //Then
    assertThat(accessToken).isNotNull();
    assertThat(request.getToken(AccessToken.class)).isSameAs(accessToken);
}
Also used : RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) AccessToken(org.forgerock.oauth2.core.AccessToken) JsonValue(org.forgerock.json.JsonValue) SecureRandom(java.security.SecureRandom) BDDMockito.anyString(org.mockito.BDDMockito.anyString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 2 with ClientRegistrationStore

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

the class OpenIdConnectAuthorizeRequestValidatorTest method setUp.

@BeforeMethod
public void setUp() throws InvalidClientException, NotFoundException {
    ClientRegistrationStore clientRegistrationStore = mock(ClientRegistrationStore.class);
    clientRegistration = mock(ClientRegistration.class);
    given(clientRegistrationStore.get(anyString(), Matchers.<OAuth2Request>anyObject())).willReturn(clientRegistration);
    requestValidator = new OpenIdConnectAuthorizeRequestValidator(clientRegistrationStore);
}
Also used : ClientRegistration(org.forgerock.oauth2.core.ClientRegistration) ClientRegistrationStore(org.forgerock.oauth2.core.ClientRegistrationStore) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with ClientRegistrationStore

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

the class OpenAMScopeValidatorTest method setup.

@BeforeMethod
public void setup() throws Exception {
    client = mock(ClientRegistration.class);
    request = mock(OAuth2Request.class);
    providerSettings = mock(OAuth2ProviderSettings.class);
    clientRegistrationStore = mock(OpenIdConnectClientRegistrationStore.class);
    OAuth2ProviderSettingsFactory factory = mock(OAuth2ProviderSettingsFactory.class);
    when(factory.get(request)).thenReturn(providerSettings);
    ScriptEvaluator scriptEvaluator = mock(ScriptEvaluator.class);
    IdentityManager identityManager = mock(IdentityManager.class);
    identity = mock(AMIdentity.class);
    when(identityManager.getResourceOwnerIdentity(anyString(), anyString())).thenReturn(identity);
    validator = new OpenAMScopeValidator(identityManager, null, factory, null, scriptEvaluator, clientRegistrationStore, null);
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) ScriptEvaluator(org.forgerock.openam.scripting.ScriptEvaluator) ClientRegistration(org.forgerock.oauth2.core.ClientRegistration) OAuth2ProviderSettingsFactory(org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory) AMIdentity(com.sun.identity.idm.AMIdentity) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) OpenIdConnectClientRegistrationStore(org.forgerock.openidconnect.OpenIdConnectClientRegistrationStore) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with ClientRegistrationStore

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

the class OpenAMTokenStoreTest method setUp.

@BeforeMethod
public void setUp() {
    tokenStore = mock(OAuthTokenStore.class);
    providerSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
    oAuth2UrisFactory = mock(OAuth2UrisFactory.class);
    clientRegistrationStore = mock(OpenIdConnectClientRegistrationStore.class);
    realmNormaliser = mock(RealmNormaliser.class);
    ssoTokenManager = mock(SSOTokenManager.class);
    request = mock(Request.class);
    cookieExtractor = mock(CookieExtractor.class);
    auditLogger = mock(OAuth2AuditLogger.class);
    debug = mock(Debug.class);
    failureFactory = mock(ClientAuthenticationFailureFactory.class);
    oAuth2RequestFactory = new RestletOAuth2RequestFactory(new JacksonRepresentationFactory(new ObjectMapper()));
    ClientAuthenticationFailureFactory failureFactory = mock(ClientAuthenticationFailureFactory.class);
    InvalidClientException expectedResult = mock(InvalidClientException.class);
    when(expectedResult.getError()).thenReturn(new String("invalid_client"));
    when(failureFactory.getException()).thenReturn(expectedResult);
    when(failureFactory.getException(anyString())).thenReturn(expectedResult);
    when(failureFactory.getException(any(OAuth2Request.class), anyString())).thenReturn(expectedResult);
    openAMtokenStore = new OpenAMTokenStore(tokenStore, providerSettingsFactory, oAuth2UrisFactory, clientRegistrationStore, realmNormaliser, ssoTokenManager, cookieExtractor, auditLogger, debug, new SecureRandom(), failureFactory);
}
Also used : OAuth2UrisFactory(org.forgerock.oauth2.core.OAuth2UrisFactory) SSOTokenManager(com.iplanet.sso.SSOTokenManager) JacksonRepresentationFactory(org.forgerock.openam.rest.representations.JacksonRepresentationFactory) RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) SecureRandom(java.security.SecureRandom) BDDMockito.anyString(org.mockito.BDDMockito.anyString) OpenIdConnectClientRegistrationStore(org.forgerock.openidconnect.OpenIdConnectClientRegistrationStore) ClientAuthenticationFailureFactory(org.forgerock.oauth2.core.exceptions.ClientAuthenticationFailureFactory) RealmNormaliser(org.forgerock.openam.utils.RealmNormaliser) RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2ProviderSettingsFactory(org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory) InvalidClientException(org.forgerock.oauth2.core.exceptions.InvalidClientException) RestletOAuth2RequestFactory(org.forgerock.oauth2.restlet.RestletOAuth2RequestFactory) Debug(com.sun.identity.shared.debug.Debug) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with ClientRegistrationStore

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

the class IdTokenClaimGathererTest method mockClientRegistrationStore.

private ClientRegistrationStore mockClientRegistrationStore() throws InvalidClientException, NotFoundException {
    ClientRegistrationStore clientRegistrationStore = mock(ClientRegistrationStore.class);
    given(clientRegistrationStore.get("CLIENT_ID", oAuth2Request)).willReturn(clientRegistration);
    given(clientRegistration.getClientSecret()).willReturn("CLIENT_SECRET");
    return clientRegistrationStore;
}
Also used : ClientRegistrationStore(org.forgerock.oauth2.core.ClientRegistrationStore)

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