use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SmsRouteTreeTest method shouldUseProvidedAuthModuleForMatchingPath.
@Test
public void shouldUseProvidedAuthModuleForMatchingPath() throws Exception {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
Context context = mock(Context.class);
ReadRequest request = Requests.newReadRequest("/not-authorized/service");
Promise<AuthorizationResult, ResourceException> failResult = newResultPromise(accessDenied("no"));
given(authModule.authorizeRead(any(Context.class), any(ReadRequest.class))).willReturn(failResult);
//When
routeTree.handles("NOT_AUTHORIZED").addRoute(RoutingMode.STARTS_WITH, "/service", requestHandler);
Promise<ResourceResponse, ResourceException> result = routeTree.handleRead(context, request);
//Then
assertThat(result).failedWithException();
verify(authModule).authorizeRead(any(Context.class), any(ReadRequest.class));
verifyNoMoreInteractions(requestHandler, defaultAuthModule);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class TokenOwnerAuthzModuleTest method setupUser.
private Context setupUser(String finalId) throws SSOException {
Principal mockPrincipal = mock(Principal.class);
SSOTokenContext tc = mock(SSOTokenContext.class);
Context mockContext = mock(Context.class);
given(mockContext.asContext(SSOTokenContext.class)).willReturn(tc);
SSOToken mockToken = mock(SSOToken.class);
given(tc.getCallerSSOToken()).willReturn(mockToken);
given(mockToken.getProperty(eq(Constants.UNIVERSAL_IDENTIFIER))).willReturn("uid" + finalId);
given(mockTokenManager.createSSOToken(eq("token"))).willReturn(mockToken);
given(mockToken.getPrincipal()).willReturn(mockPrincipal);
given(mockPrincipal.getName()).willReturn(finalId);
return mockContext;
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyRequestFactoryTest method shouldRejectUnsupportedAction.
@Test(expectedExceptions = EntitlementException.class)
public void shouldRejectUnsupportedAction() throws EntitlementException {
// Given...
Context context = buildContextStructure("/abc");
factory.buildRequest(PolicyAction.UNKNOWN, context, actionRequest);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldHandleEntitlementExceptions.
@Test
public void shouldHandleEntitlementExceptions() throws EntitlementException {
// Given...
given(request.getAction()).willReturn("evaluate");
Context context = buildContextStructure("/abc");
EntitlementException eE = new EntitlementException(EntitlementException.INVALID_VALUE);
given(requestFactory.buildRequest(PolicyAction.EVALUATE, context, request)).willThrow(eE);
given(request.getRequestType()).willReturn(RequestType.ACTION);
// When...
Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
verify(requestFactory).buildRequest(PolicyAction.EVALUATE, context, request);
verify(request).getRequestType();
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
verifyNoMoreInteractions(request, requestFactory, policyRequest, factory, evaluator, parser);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldMakeBatchEvaluation.
@Test
public void shouldMakeBatchEvaluation() throws EntitlementException {
// Given...
given(request.getAction()).willReturn("evaluate");
Context context = buildContextStructure("/abc");
given(requestFactory.buildRequest(PolicyAction.EVALUATE, context, request)).willReturn(policyRequest);
given(policyRequest.getRestSubject()).willReturn(restSubject);
given(policyRequest.getApplication()).willReturn("some-application");
given(factory.getEvaluator(restSubject, "some-application")).willReturn(evaluator);
given(policyRequest.getApplication()).willReturn("some-application");
given(policyRequest.getRealm()).willReturn("/abc");
List<Entitlement> decisions = Arrays.asList(new Entitlement());
given(evaluator.routePolicyRequest(policyRequest)).willReturn(decisions);
JsonValue jsonDecision = JsonValue.json(array());
given(parser.printEntitlements(decisions)).willReturn(jsonDecision);
// When...
Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
verify(requestFactory).buildRequest(PolicyAction.EVALUATE, context, request);
verify(policyRequest).getRestSubject();
verify(policyRequest, times(2)).getApplication();
verify(policyRequest).getRealm();
verify(factory).getEvaluator(restSubject, "some-application");
verify(evaluator).routePolicyRequest(policyRequest);
verify(parser).printEntitlements(decisions);
assertThat(promise).succeeded().withContent().isEqualTo(jsonDecision);
verifyNoMoreInteractions(request, requestFactory, policyRequest, factory, evaluator, parser);
}
Aggregations