use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromCRUDPAQRequestWithSubrealm.
@Test(dataProvider = "CRUDPAQ")
public void filterShouldConsumeRealmFromCRUDPAQRequestWithSubrealm(Request request, String postURIString) throws Exception {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
String path = SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT;
Context context = mockContext(path);
request.setUri(createRequestURI(HOSTNAME, path, postURIString));
mockDnsAlias(HOSTNAME, "/");
mockRealmAlias("/" + SUB_REALM, "/" + SUB_REALM);
//When
Handler httpHandler = getHttpHandler(requestHandler);
httpHandler.handle(context, request).getOrThrowUninterruptibly();
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
ArgumentCaptor<org.forgerock.json.resource.Request> requestCaptor = ArgumentCaptor.forClass(org.forgerock.json.resource.Request.class);
collectCRUDPAQArguments(requestHandler, contextCaptor, requestCaptor);
verifyRealmContext(contextCaptor.getValue(), "", "/" + SUB_REALM, null);
verifyUriRouterContext(contextCaptor.getValue(), SUB_REALM);
verifyResolvedResourcePath(requestCaptor.getValue(), ENDPOINT_PATH_ELEMENT);
}
use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.
the class SelfServiceRequestHandler method getService.
private RequestHandler getService(Context context) throws NotSupportedException {
String realm = RealmContext.getRealm(context);
RequestHandler service = serviceCache.get(realm);
if (service == null) {
synchronized (serviceCache) {
service = serviceCache.get(realm);
if (service == null) {
service = createNewService(context, realm);
serviceCache.put(realm, service);
}
}
}
return service;
}
use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.
the class STSPublishServiceHttpRouteProvider method getHandler.
private Handler getHandler() {
final RequestHandler restPublishRequestHandler = new RestSTSPublishServiceRequestHandler(STSPublishInjectorHolder.getInstance(Key.get(RestSTSInstancePublisher.class)), STSPublishInjectorHolder.getInstance(Key.get(RestRealmValidator.class)), STSPublishInjectorHolder.getInstance(Key.get(new TypeLiteral<InstanceConfigMarshaller<RestSTSInstanceConfig>>() {
})), STSPublishInjectorHolder.getInstance(Key.get(Logger.class)));
rootRouter.route("rest").auditAs(STS).authorizeWith(STSPublishServiceAuthzModule.class).toRequestHandler(STARTS_WITH, restPublishRequestHandler);
final RequestHandler soapPublishRequestHandler = new SoapSTSPublishServiceRequestHandler(STSPublishInjectorHolder.getInstance(Key.get(SoapSTSInstancePublisher.class)), STSPublishInjectorHolder.getInstance(Key.get(RestRealmValidator.class)), STSPublishInjectorHolder.getInstance(Key.get(new TypeLiteral<InstanceConfigMarshaller<SoapSTSInstanceConfig>>() {
})), STSPublishInjectorHolder.getInstance(Key.get(Logger.class)));
rootRouter.route("soap").auditAs(STS).authorizeWith(STSPublishServiceAuthzModule.class).toRequestHandler(STARTS_WITH, soapPublishRequestHandler);
return Handlers.chainOf(newHttpHandler(rootRouter.getRouter()), authenticationFilter);
}
use of org.forgerock.json.resource.RequestHandler 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.json.resource.RequestHandler in project OpenAM by OpenRock.
the class SmsRequestHandler method addPaths.
/**
* Recursively adds routes for the schema paths found in the schema instance.
*
* @param parentPath The parent route path to add new routes beneath.
* @param schemaPath The path for schema that is built up as we navigate through the Schema and SubSchema
* declarations for the service.
* @param schema The Schema or SubSchema instance for this iteration of the method.
* @param dynamicSchema The dynamic Schema instance, or {@code null} if no dynamic schema is defined.
* @param serviceRoutes Routes added for the service are added for later removal if needed.
* @param ignoredRoutes Any routes to be ignored.
* @param routeTree The tree to add routes to. If null, the root tree will be used to find the appropriate node.
* @throws SMSException From downstream service manager layer.
*/
private void addPaths(String parentPath, List<ServiceSchema> schemaPath, ServiceSchema schema, ServiceSchema dynamicSchema, Map<SmsRouteTree, Set<RouteMatcher<Request>>> serviceRoutes, List<Pattern> ignoredRoutes, SmsRouteTree routeTree) throws SMSException {
String schemaName = schema.getResourceName();
String path = getPath(parentPath, schemaName, schemaPath, schema);
if (!schema.getAttributeSchemas().isEmpty() || schema.supportsMultipleConfigurations()) {
if (schema.supportsMultipleConfigurations() && !excludeCollection(schema.getServiceName())) {
RequestHandler handler = Resources.newCollection(collectionProviderFactory.create(new SmsJsonConverter(schema), schema, schemaType, new ArrayList<ServiceSchema>(schemaPath), parentPath, true));
debug.message("Adding collection path {}", path);
serviceRoutes.putAll(addRoute(schema, STARTS_WITH, path, handler, ignoredRoutes, routeTree));
parentPath = path + "/{" + schemaName + "}";
} else if (!excludeSingleton(schema.getServiceName())) {
RequestHandler handler = singletonProviderFactory.create(new SmsJsonConverter(schema), schema, dynamicSchema, schemaType, new ArrayList<ServiceSchema>(schemaPath), parentPath, true);
debug.message("Adding singleton path {}", path);
serviceRoutes.putAll(addRoute(schema, EQUALS, path, handler, ignoredRoutes, routeTree));
parentPath = path;
}
}
addPaths(parentPath, schemaPath, schema, serviceRoutes, ignoredRoutes, routeTree);
}
Aggregations