use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PendingRequestsServiceTest method shouldSendEmailOnPendingRequestApproval.
@Test
public void shouldSendEmailOnPendingRequestApproval() throws Exception {
//Given
Context context = mock(Context.class);
createPendingRequest(PENDING_REQUEST_ID, RESOURCE_SET_ID, RESOURCE_SET_NAME, RESOURCE_OWNER_ID, REALM, REQUESTING_PARTY_ID, Collections.singleton(SCOPE));
given(settings.isEmailRequestingPartyOnPendingRequestApprovalEnabled()).willReturn(true);
mockPendingRequestApprovalEmailTemplate(REQUESTING_PARTY_ID, REALM);
mockSuccessfulPolicyCreationForPendingRequest();
JsonValue content = json(object());
//When
service.approvePendingRequest(context, PENDING_REQUEST_ID, content, REALM);
//Then
verify(policyService).createPolicy(eq(context), any(JsonValue.class));
verify(emailService).email(REALM, REQUESTING_PARTY_ID, "APPROVAL_SUBJECT", "APPROVAL_BODY " + RESOURCE_OWNER_ID + " " + RESOURCE_SET_NAME + " " + SCOPE);
verify(store).delete(PENDING_REQUEST_ID);
verify(auditLogger).log(RESOURCE_SET_ID, RESOURCE_SET_NAME, resourceOwnerIdentity, UmaAuditType.REQUEST_APPROVED, REQUESTING_PARTY_ID);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PendingRequestsServiceTest method shouldApprovePendingRequestUsingScopesFromRequestContent.
@Test
public void shouldApprovePendingRequestUsingScopesFromRequestContent() throws Exception {
//Given
Context context = mock(Context.class);
createPendingRequest(PENDING_REQUEST_ID, RESOURCE_SET_ID, RESOURCE_SET_NAME, RESOURCE_OWNER_ID, REALM, REQUESTING_PARTY_ID, Collections.singleton(SCOPE));
mockSuccessfulPolicyCreationForPendingRequest();
JsonValue content = json(object(field("scopes", array("SCOPE_A", "SCOPE_B"))));
//When
service.approvePendingRequest(context, PENDING_REQUEST_ID, content, REALM);
//Then
ArgumentCaptor<JsonValue> policyCaptor = ArgumentCaptor.forClass(JsonValue.class);
verify(policyService).createPolicy(eq(context), policyCaptor.capture());
JsonValue policy = policyCaptor.getValue();
assertThat(policy).stringAt("policyId").isEqualTo(RESOURCE_SET_ID);
assertThat(policy).hasArray("permissions").hasSize(1);
assertThat(policy).stringAt("permissions/0/subject").isEqualTo(REQUESTING_PARTY_ID);
assertThat(policy).hasArray("permissions/0/scopes").containsOnly("SCOPE_A", "SCOPE_B");
verify(store).delete(PENDING_REQUEST_ID);
verify(auditLogger).log(RESOURCE_SET_ID, RESOURCE_SET_NAME, resourceOwnerIdentity, UmaAuditType.REQUEST_APPROVED, REQUESTING_PARTY_ID);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class AuditTestUtils method mockAuditContext.
public static Context mockAuditContext() throws Exception {
final Context httpContext = new HttpContext(jsonFromFile("/org/forgerock/openam/rest/fluent/httpContext.json"), AbstractAuditFilterTest.class.getClassLoader());
final Subject callerSubject = new Subject();
final Context securityContext = new SecurityContext(httpContext, null, null);
final Context subjectContext = new SSOTokenContext(mock(Debug.class), null, securityContext) {
@Override
public Subject getCallerSubject() {
return callerSubject;
}
@Override
public SSOToken getCallerSSOToken() {
SSOToken token = mock(SSOToken.class);
try {
given(token.getProperty(Constants.AM_CTX_ID)).willReturn("TRACKING_ID");
given(token.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("USER_ID");
} catch (SSOException e) {
// won't happen - it's a mock
}
return token;
}
};
final Context clientContext = ClientContext.newInternalClientContext(subjectContext);
return new RequestAuditContext(new AuditInfoContext(clientContext, AuditConstants.Component.AUDIT));
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class ApplicationTypesResourceTest method shouldReadInstanceCorrectly.
@Test
public void shouldReadInstanceCorrectly() throws IllegalAccessException, InstantiationException, ExecutionException, InterruptedException {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject subject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
ReadRequest request = mock(ReadRequest.class);
ApplicationType mockApplicationType = new ApplicationType("test", null, null, null, null);
given(mockApplicationTypeManager.getApplicationType(subject, "test")).willReturn(mockApplicationType);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
//then
assertTrue(result.get().getId().equals("test"));
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyResourceDelegateTest method shouldHandleFailureToDeleteFailedCreationOfPolicies.
@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToDeleteFailedCreationOfPolicies() throws ResourceException {
//Given
//Given
Context context = mock(Context.class);
Set<JsonValue> policies = new HashSet<JsonValue>();
JsonValue policyOne = json(object(field("name", "POLICY_ONE")));
JsonValue policyTwo = json(object(field("name", "POLICY_TWO")));
policies.add(policyOne);
policies.add(policyTwo);
ResourceResponse createdPolicyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
ResourceException createException = mock(ResourceException.class);
ResourceException deleteException = mock(ResourceException.class);
Promise<ResourceResponse, ResourceException> createPolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
Promise<ResourceResponse, ResourceException> createPolicyTwoPromise = Promises.newExceptionPromise(createException);
Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newExceptionPromise(deleteException);
given(policyResource.handleCreate(eq(context), Matchers.<CreateRequest>anyObject())).willReturn(createPolicyOnePromise).willReturn(createPolicyTwoPromise);
given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())).willReturn(deletePolicyOnePromise);
//When
try {
delegate.createPolicies(context, policies).getOrThrowUninterruptibly();
} catch (ResourceException e) {
//Then
ArgumentCaptor<DeleteRequest> requestCaptor = ArgumentCaptor.forClass(DeleteRequest.class);
verify(policyResource).handleDelete(eq(context), requestCaptor.capture());
assertThat(requestCaptor.getValue().getResourcePathObject().leaf()).isEqualTo("ID_1");
assertThat(e).isEqualTo(deleteException);
throw e;
}
}
Aggregations