Search in sources :

Example 1 with UmaAuditLogger

use of org.forgerock.openam.uma.audit.UmaAuditLogger in project OpenAM by OpenRock.

the class AuthorizationRequestEndpointTest method setup.

@BeforeMethod
@SuppressWarnings("unchecked")
public void setup() throws ServerException, InvalidGrantException, NotFoundException, EntitlementException, JSONException {
    requestFactory = mock(OAuth2RequestFactory.class);
    OAuth2Request oAuth2Request = mock(OAuth2Request.class);
    given(requestFactory.create(any(Request.class))).willReturn(oAuth2Request);
    given(oAuth2Request.getParameter("realm")).willReturn("REALM");
    accessToken = mock(AccessToken.class);
    oauth2TokenStore = mock(TokenStore.class);
    given(oauth2TokenStore.readAccessToken(Matchers.<OAuth2Request>anyObject(), anyString())).willReturn(accessToken);
    given(accessToken.getClientId()).willReturn(RS_CLIENT_ID);
    given(accessToken.getResourceOwnerId()).willReturn(REQUESTING_PARTY_ID);
    umaAuditLogger = mock(UmaAuditLogger.class);
    umaTokenStore = mock(UmaTokenStore.class);
    rpt = mock(RequestingPartyToken.class);
    given(rpt.getId()).willReturn("1");
    permissionTicket = mock(PermissionTicket.class);
    given(permissionTicket.getExpiryTime()).willReturn(System.currentTimeMillis() + 10000);
    given(permissionTicket.getResourceSetId()).willReturn(RS_ID);
    given(permissionTicket.getResourceServerClientId()).willReturn(RS_CLIENT_ID);
    given(permissionTicket.getRealm()).willReturn("REALM");
    given(umaTokenStore.readPermissionTicket(anyString())).willReturn(permissionTicket);
    given(umaTokenStore.createRPT(Matchers.<PermissionTicket>anyObject())).willReturn(rpt);
    resourceSetStore = mock(ResourceSetStore.class);
    ResourceSetDescription resourceSet = new ResourceSetDescription();
    resourceSet.setId(RS_DESCRIPTION_ID);
    resourceSet.setResourceOwnerId(RESOURCE_OWNER_ID);
    given(resourceSetStore.query(QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, RS_ID))).willReturn(Collections.singleton(resourceSet));
    umaProviderSettings = mock(UmaProviderSettings.class);
    policyEvaluator = mock(Evaluator.class);
    given(umaProviderSettings.getPolicyEvaluator(any(Subject.class), eq(RS_CLIENT_ID.toLowerCase()))).willReturn(policyEvaluator);
    given(umaProviderSettings.getUmaTokenStore()).willReturn(umaTokenStore);
    umaProviderSettingsFactory = mock(UmaProviderSettingsFactory.class);
    given(umaProviderSettingsFactory.get(Matchers.<Request>anyObject())).willReturn(umaProviderSettings);
    given(umaProviderSettings.getUmaTokenStore()).willReturn(umaTokenStore);
    OAuth2ProviderSettingsFactory oauth2ProviderSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
    OAuth2ProviderSettings oauth2ProviderSettings = mock(OAuth2ProviderSettings.class);
    given(oauth2ProviderSettingsFactory.get(any(OAuth2Request.class))).willReturn(oauth2ProviderSettings);
    given(oauth2ProviderSettings.getResourceSetStore()).willReturn(resourceSetStore);
    OAuth2UrisFactory<RealmInfo> oauth2UrisFactory = mock(OAuth2UrisFactory.class);
    OAuth2Uris oauth2Uris = mock(OAuth2Uris.class);
    given(oauth2UrisFactory.get(any(OAuth2Request.class))).willReturn(oauth2Uris);
    given(oauth2Uris.getIssuer()).willReturn("ISSUER");
    pendingRequestsService = mock(PendingRequestsService.class);
    Map<String, ClaimGatherer> claimGatherers = new HashMap<>();
    idTokenClaimGatherer = mock(IdTokenClaimGatherer.class);
    claimGatherers.put(IdTokenClaimGatherer.FORMAT, idTokenClaimGatherer);
    ExtensionFilterManager extensionFilterManager = mock(ExtensionFilterManager.class);
    requestAuthorizationFilter = mock(RequestAuthorizationFilter.class);
    given(extensionFilterManager.getFilters(RequestAuthorizationFilter.class)).willReturn(Collections.singletonList(requestAuthorizationFilter));
    UmaExceptionHandler exceptionHandler = mock(UmaExceptionHandler.class);
    endpoint = spy(new AuthorizationRequestEndpoint2(umaProviderSettingsFactory, oauth2TokenStore, requestFactory, oauth2ProviderSettingsFactory, oauth2UrisFactory, umaAuditLogger, pendingRequestsService, claimGatherers, extensionFilterManager, exceptionHandler, jacksonRepresentationFactory));
    request = mock(Request.class);
    given(endpoint.getRequest()).willReturn(request);
    response = mock(Response.class);
    endpoint.setResponse(response);
    requestBody = mock(JSONObject.class);
    given(requestBody.toString()).willReturn("{\"ticket\": \"016f84e8-f9b9-11e0-bd6f-0021cc6004de\"}");
    entity = mock(JsonRepresentation.class);
    given(entity.getJsonObject()).willReturn(requestBody);
}
Also used : OAuth2Uris(org.forgerock.oauth2.core.OAuth2Uris) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) RealmInfo(org.forgerock.openam.core.RealmInfo) OAuth2RequestFactory(org.forgerock.oauth2.core.OAuth2RequestFactory) OAuth2ProviderSettingsFactory(org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory) AccessToken(org.forgerock.oauth2.core.AccessToken) ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) UmaAuditLogger(org.forgerock.openam.uma.audit.UmaAuditLogger) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) RequestAuthorizationFilter(org.forgerock.openam.uma.extensions.RequestAuthorizationFilter) Evaluator(com.sun.identity.entitlement.Evaluator) Subject(javax.security.auth.Subject) Response(org.restlet.Response) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) JSONObject(org.json.JSONObject) TokenStore(org.forgerock.oauth2.core.TokenStore) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) ExtensionFilterManager(org.forgerock.openam.oauth2.extensions.ExtensionFilterManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with UmaAuditLogger

use of org.forgerock.openam.uma.audit.UmaAuditLogger in project OpenAM by OpenRock.

the class UmaPolicyServiceImplDelegationTest method setup.

@SuppressWarnings("unchecked")
@BeforeMethod
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    //Stub getting ResourceSetStore
    ResourceSetStoreFactory resourceSetStoreFactory = mock(ResourceSetStoreFactory.class);
    given(resourceSetStoreFactory.create(anyString())).willReturn(resourceSetStore);
    //Stub getting UmaAuditLogger
    Config<UmaAuditLogger> lazyAuditLogger = mock(Config.class);
    given(lazyAuditLogger.get()).willReturn(auditLogger);
    //Stub getting Evaluator
    UmaPolicyEvaluatorFactory policyEvaluatorFactory = mock(UmaPolicyEvaluatorFactory.class);
    given(policyEvaluatorFactory.getEvaluator(any(Subject.class), anyString())).willReturn(policyEvaluator);
    Debug debug = mock(Debug.class);
    UmaSettingsFactory umaSettingsFactory = mock(UmaSettingsFactory.class);
    given(umaSettingsFactory.create(anyString())).willReturn(umaSettings);
    ExtensionFilterManager extensionFilterManager = mock(ExtensionFilterManager.class);
    policyService = new UmaPolicyServiceImpl(policyResourceDelegate, resourceSetStoreFactory, lazyAuditLogger, contextHelper, policyEvaluatorFactory, coreServicesWrapper, debug, umaSettingsFactory, extensionFilterManager);
    given(contextHelper.getRealm(Matchers.<Context>anyObject())).willReturn("REALM");
}
Also used : UmaSettingsFactory(org.forgerock.openam.uma.UmaSettingsFactory) UmaAuditLogger(org.forgerock.openam.uma.audit.UmaAuditLogger) ResourceSetStoreFactory(org.forgerock.openam.oauth2.resources.ResourceSetStoreFactory) Subject(javax.security.auth.Subject) Debug(com.sun.identity.shared.debug.Debug) ExtensionFilterManager(org.forgerock.openam.oauth2.extensions.ExtensionFilterManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with UmaAuditLogger

use of org.forgerock.openam.uma.audit.UmaAuditLogger in project OpenAM by OpenRock.

the class UmaPolicyServiceImplTest method setup.

@BeforeMethod
public void setup() throws Exception {
    policyResourceDelegate = mock(PolicyResourceDelegate.class);
    final ResourceSetStoreFactory resourceSetStoreFactory = mock(ResourceSetStoreFactory.class);
    Config<UmaAuditLogger> lazyAuditLogger = mock(Config.class);
    auditLogger = mock(UmaAuditLogger.class);
    contextHelper = mock(ContextHelper.class);
    UmaPolicyEvaluatorFactory policyEvaluatorFactory = mock(UmaPolicyEvaluatorFactory.class);
    policyEvaluator = mock(Evaluator.class);
    given(policyEvaluatorFactory.getEvaluator(any(Subject.class), anyString())).willReturn(policyEvaluator);
    coreServicesWrapper = mock(CoreServicesWrapper.class);
    Debug debug = mock(Debug.class);
    UmaSettingsFactory umaSettingsFactory = mock(UmaSettingsFactory.class);
    UmaSettings umaSettings = mock(UmaSettings.class);
    given(umaSettingsFactory.create(anyString())).willReturn(umaSettings);
    ExtensionFilterManager extensionFilterManager = mock(ExtensionFilterManager.class);
    resourceDelegationFilter = mock(ResourceDelegationFilter.class);
    given(extensionFilterManager.getFilters(ResourceDelegationFilter.class)).willReturn(Collections.singleton(resourceDelegationFilter));
    policyService = new UmaPolicyServiceImpl(policyResourceDelegate, resourceSetStoreFactory, lazyAuditLogger, contextHelper, policyEvaluatorFactory, coreServicesWrapper, debug, umaSettingsFactory, extensionFilterManager);
    given(contextHelper.getRealm(Matchers.<Context>anyObject())).willReturn("REALM");
    given(contextHelper.getUserId(Matchers.<Context>anyObject())).willReturn(RESOURCE_OWNER_ID);
    given(contextHelper.getUserUid(Matchers.<Context>anyObject())).willReturn("RESOURCE_OWNER_UID");
    resourceSetStore = mock(ResourceSetStore.class);
    resourceSet = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", RESOURCE_OWNER_ID, Collections.<String, Object>emptyMap());
    resourceSet.setDescription(json(object(field("name", "NAME"), field("scopes", array("SCOPE_A", "SCOPE_B", "SCOPE_C")))));
    given(resourceSetStoreFactory.create(anyString())).willReturn(resourceSetStore);
    given(resourceSetStore.read("RESOURCE_SET_ID", RESOURCE_OWNER_ID)).willReturn(resourceSet);
    given(resourceSetStore.read(eq("RESOURCE_SET_ID"), any(ResourceSetAcceptAllFilter.class))).willReturn(resourceSet);
    given(resourceSetStore.query(QueryFilter.and(QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, "RESOURCE_SET_ID")))).willReturn(Collections.singleton(resourceSet));
    doThrow(org.forgerock.oauth2.core.exceptions.NotFoundException.class).when(resourceSetStore).read("OTHER_ID", RESOURCE_OWNER_ID);
    doThrow(org.forgerock.oauth2.core.exceptions.ServerException.class).when(resourceSetStore).read("FAILING_ID", RESOURCE_OWNER_ID);
    doThrow(org.forgerock.oauth2.core.exceptions.ServerException.class).when(resourceSetStore).query(QueryFilter.and(QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, "FAILING_ID")));
    given(lazyAuditLogger.get()).willReturn(auditLogger);
    AMIdentity identity = mock(AMIdentity.class);
    given(identity.getUniversalId()).willReturn("uid=RESOURCE_OWNER_ID,ou=REALM,dc=forgerock,dc=org");
    given(coreServicesWrapper.getIdentity(RESOURCE_OWNER_ID, "REALM")).willReturn(identity);
}
Also used : CoreServicesWrapper(org.forgerock.openam.core.CoreServicesWrapper) ContextHelper(org.forgerock.openam.rest.resource.ContextHelper) UmaSettingsFactory(org.forgerock.openam.uma.UmaSettingsFactory) UmaAuditLogger(org.forgerock.openam.uma.audit.UmaAuditLogger) ResourceDelegationFilter(org.forgerock.openam.uma.extensions.ResourceDelegationFilter) Matchers.anyString(org.mockito.Matchers.anyString) Evaluator(com.sun.identity.entitlement.Evaluator) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Subject(javax.security.auth.Subject) ResourceSetAcceptAllFilter(org.forgerock.openam.uma.ResourceSetAcceptAllFilter) UmaSettings(org.forgerock.openam.uma.UmaSettings) ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) AMIdentity(com.sun.identity.idm.AMIdentity) ResourceSetStoreFactory(org.forgerock.openam.oauth2.resources.ResourceSetStoreFactory) Debug(com.sun.identity.shared.debug.Debug) ExtensionFilterManager(org.forgerock.openam.oauth2.extensions.ExtensionFilterManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Subject (javax.security.auth.Subject)3 ExtensionFilterManager (org.forgerock.openam.oauth2.extensions.ExtensionFilterManager)3 UmaAuditLogger (org.forgerock.openam.uma.audit.UmaAuditLogger)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Evaluator (com.sun.identity.entitlement.Evaluator)2 Debug (com.sun.identity.shared.debug.Debug)2 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)2 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)2 ResourceSetStoreFactory (org.forgerock.openam.oauth2.resources.ResourceSetStoreFactory)2 UmaSettingsFactory (org.forgerock.openam.uma.UmaSettingsFactory)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AMIdentity (com.sun.identity.idm.AMIdentity)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AccessToken (org.forgerock.oauth2.core.AccessToken)1 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)1 OAuth2ProviderSettingsFactory (org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory)1 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)1 OAuth2RequestFactory (org.forgerock.oauth2.core.OAuth2RequestFactory)1 OAuth2Uris (org.forgerock.oauth2.core.OAuth2Uris)1