Search in sources :

Example 1 with UmaSettings

use of org.forgerock.openam.uma.UmaSettings 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

Evaluator (com.sun.identity.entitlement.Evaluator)1 AMIdentity (com.sun.identity.idm.AMIdentity)1 Debug (com.sun.identity.shared.debug.Debug)1 Subject (javax.security.auth.Subject)1 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)1 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)1 CoreServicesWrapper (org.forgerock.openam.core.CoreServicesWrapper)1 ExtensionFilterManager (org.forgerock.openam.oauth2.extensions.ExtensionFilterManager)1 ResourceSetStoreFactory (org.forgerock.openam.oauth2.resources.ResourceSetStoreFactory)1 ContextHelper (org.forgerock.openam.rest.resource.ContextHelper)1 ResourceSetAcceptAllFilter (org.forgerock.openam.uma.ResourceSetAcceptAllFilter)1 UmaSettings (org.forgerock.openam.uma.UmaSettings)1 UmaSettingsFactory (org.forgerock.openam.uma.UmaSettingsFactory)1 UmaAuditLogger (org.forgerock.openam.uma.audit.UmaAuditLogger)1 ResourceDelegationFilter (org.forgerock.openam.uma.extensions.ResourceDelegationFilter)1 Matchers.anyString (org.mockito.Matchers.anyString)1 BeforeMethod (org.testng.annotations.BeforeMethod)1