use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RestRouterIT method shouldBeAbleToReachInternalViaInternalRouter.
@Test
public void shouldBeAbleToReachInternalViaInternalRouter() throws Exception {
// Given
Promise<ResourceResponse, ResourceException> promise = newResultPromise(newResourceResponse("1", "1", json(object())));
given(internalResource.readInstance(any(Context.class), eq("123"), any(ReadRequest.class))).willReturn(promise);
Router internalRouter = InjectorHolder.getInstance(Key.get(Router.class, Names.named("InternalCrestRouter")));
Context context = mockRequiredContexts();
ReadRequest request = Requests.newReadRequest("internal/123");
// When
internalRouter.handleRead(context, request);
// Then
verify(internalResource).readInstance(any(Context.class), eq("123"), any(ReadRequest.class));
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RestRouterIT method shouldReadCrestEndpointOnRealmHandlerWithSubRealm.
@Test
public void shouldReadCrestEndpointOnRealmHandlerWithSubRealm() throws Exception {
//Given
Context context = mockRequiredContexts();
Request request = newRequest("GET", "/json/subrealm/users/demo");
auditingOff();
mockRealm("/subrealm");
//When
handler.handle(context, request);
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(usersResource).readInstance(contextCaptor.capture(), eq("demo"), any(ReadRequest.class));
assertThat(contextCaptor.getValue().asContext(RealmContext.class).getResolvedRealm()).isEqualTo("/subrealm");
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RestRouterIT method shouldReadChfEndpointOnRealmHandlerWithSubRealm.
@Test
public void shouldReadChfEndpointOnRealmHandlerWithSubRealm() throws Exception {
//Given
Context context = mockContext();
Request request = newRequest("GET", "/json/subrealm/authenticate");
mockRealm("/subrealm");
//When
handler.handle(context, request);
//Then
verify(authenticateResource).get();
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestActionNoMappingFails.
@Test
public void crestActionNoMappingFails() throws SSOException, DelegationException {
// When...
final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
final Router router = new Router();
router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
final Context context = new RealmContext(subjectContext);
final ActionRequest request = Requests.newActionRequest("/policies", "unknownAction");
Promise<ActionResponse, ResourceException> promise = router.handleAction(context, request);
// Then...
assertThat(promise).failedWithException().isInstanceOf(ForbiddenException.class);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RestRouterIT method setupMocks.
@BeforeMethod
public void setupMocks() {
MockitoAnnotations.initMocks(this);
configResource = mock(SingletonResourceProvider.class);
usersResource = mock(CollectionResourceProvider.class);
internalResource = mock(CollectionResourceProvider.class);
dashboardResource = spy(new DashboardResource());
authenticateResource = spy(new AuthenticateResource());
httpAccessAuditFilter = spy(new AbstractHttpAccessAuditFilter(AUTHENTICATION, mock(AuditEventPublisher.class), mock(AuditEventFactory.class)) {
@Override
protected String getRealm(Context context) {
return null;
}
});
auditEventPublisher = mock(AuditEventPublisher.class);
auditServiceProvider = mock(AuditServiceProvider.class);
versionBehaviourManager = mock(ResourceApiVersionBehaviourManager.class);
ssoTokenManager = mock(SSOTokenManager.class);
authUtilsWrapper = mock(AuthUtilsWrapper.class);
coreWrapper = mock(CoreWrapper.class);
SSOToken adminToken = mock(SSOToken.class);
given(coreWrapper.getAdminToken()).willReturn(adminToken);
given(coreWrapper.isValidFQDN(anyString())).willReturn(true);
realmValidator = mock(RestRealmValidator.class);
}
Aggregations