use of org.forgerock.openam.core.rest.sms.SmsRouteTree in project OpenAM by OpenRock.
the class SmsRequestHandler method addService.
/**
* Adds routes for the specified service to the provided router. Realm schema routes are added if the
* {@link #schemaType} is either {@link SchemaType#GLOBAL} (for default values) or
* {@link SchemaType#ORGANIZATION}. Global schema routes are only added for {@link SchemaType#GLOBAL}.
*
* @param sm The ServiceManager instance to use.
* @param serviceName The name of the service being added.
* @param serviceVersion The version of the service being added.
* @return The routes that were configured.
* @throws SMSException From downstream service manager layer.
* @throws SSOException From downstream service manager layer.
*/
private Map<SmsRouteTree, Set<RouteMatcher<Request>>> addService(ServiceManager sm, String serviceName, String serviceVersion) throws SMSException, SSOException {
if (excludedServices.contains(serviceName)) {
debug.message("Excluding service from REST SMS: {}", serviceName);
return null;
}
ServiceSchemaManager ssm = sm.getSchemaManager(serviceName, serviceVersion);
String resourceName = EMPTY_PATH.equals(ssm.getResourceName()) ? "" : ssm.getResourceName();
Map<SmsRouteTree, Set<RouteMatcher<Request>>> routes = new HashMap<>();
ServiceSchema organizationSchema = ssm.getOrganizationSchema();
ServiceSchema dynamicSchema = ssm.getDynamicSchema();
if (schemaType == SchemaType.GLOBAL) {
ServiceSchema globalSchema = ssm.getGlobalSchema();
if (hasGlobalSchema(globalSchema)) {
debug.message("Adding global schema REST SMS endpoints for service: {}", serviceName);
addGlobalPaths(resourceName, new ArrayList<ServiceSchema>(), globalSchema, organizationSchema, dynamicSchema, routes, DEFAULT_IGNORED_ROUTES, null);
} else if (organizationSchema != null) {
debug.message("Adding global schema REST SMS endpoints for service: {}", serviceName);
addGlobalPaths(resourceName, new ArrayList<ServiceSchema>(), organizationSchema, organizationSchema, dynamicSchema, routes, DEFAULT_IGNORED_ROUTES, null);
}
} else {
if (organizationSchema != null) {
debug.message("Adding realm schema REST SMS endpoints for service: {}", serviceName);
addPaths(resourceName, new ArrayList<ServiceSchema>(), organizationSchema, dynamicSchema, routes, DEFAULT_IGNORED_ROUTES, null);
} else if (dynamicSchema != null) {
debug.message("Adding realm schema REST SMS endpoints for service: {}", serviceName);
addPaths(resourceName, new ArrayList<ServiceSchema>(), dynamicSchema, dynamicSchema, routes, DEFAULT_IGNORED_ROUTES, null);
}
}
return routes;
}
use of org.forgerock.openam.core.rest.sms.SmsRouteTree in project OpenAM by OpenRock.
the class SmsRequestHandler method createServices.
/**
* Creates a {@link Router} for all the registered services, and then assigns that router to the instance so that
* it will be used for all future requests.
* @throws SMSException From downstream service manager layer.
* @throws SSOException From downstream service manager layer.
*/
private synchronized void createServices() throws SSOException, SMSException {
Map<String, Map<SmsRouteTree, Set<RouteMatcher<Request>>>> serviceRoutes = new HashMap<>();
ServiceManager sm = getServiceManager();
Set<String> serviceNames = sm.getServiceNames();
for (String serviceName : serviceNames) {
Map<SmsRouteTree, Set<RouteMatcher<Request>>> routes = addService(sm, serviceName, DEFAULT_VERSION);
if (routes != null) {
serviceRoutes.put(serviceName, routes);
}
}
if (schemaType == SchemaType.GLOBAL) {
addServersRoutes(sm, serviceRoutes);
}
this.serviceRoutes = serviceRoutes;
}
use of org.forgerock.openam.core.rest.sms.SmsRouteTree in project OpenAM by OpenRock.
the class SmsRequestHandler method addServersRoutes.
private void addServersRoutes(ServiceSchemaManager ssm, Set<RouteMatcher<Request>> serviceRoutes, String parentName, String schemaName) throws SSOException, SMSException {
ServiceSchema parentSchema = ssm.getGlobalSchema().getSubSchema(parentName);
ServiceSchema schema = parentSchema.getSubSchema(schemaName);
HashMap<SmsRouteTree, Set<RouteMatcher<Request>>> routes = new HashMap<>();
addPaths("", new ArrayList<>(Collections.singletonList(parentSchema)), schema, null, routes, Collections.<Pattern>emptyList(), routeTree);
serviceRoutes.addAll(routes.get(routeTree));
}
use of org.forgerock.openam.core.rest.sms.SmsRouteTree in project OpenAM by OpenRock.
the class SmsRequestHandler method addRoute.
private Map<SmsRouteTree, Set<RouteMatcher<Request>>> addRoute(ServiceSchema schema, RoutingMode mode, String path, RequestHandler handler, List<Pattern> ignoredRoutes, SmsRouteTree routeTree) {
for (Pattern ignored : ignoredRoutes) {
if (ignored.matcher(path).matches()) {
return emptyMap();
}
}
SmsRouteTree tree = routeTree == null ? this.routeTree.handles(schema.getServiceName()) : routeTree;
RouteMatcher<Request> route = tree.addRoute(mode, path, handler);
return Maps.newHashMap(Collections.singletonMap(tree, asSet(route)));
}
use of org.forgerock.openam.core.rest.sms.SmsRouteTree in project OpenAM by OpenRock.
the class SmsRouteTreeTest method shouldHandleAddingRoutes.
@Test(dataProvider = "handleRoutes")
public void shouldHandleAddingRoutes(String serviceName, String resourcePath) {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
Context context = mock(Context.class);
ReadRequest request = Requests.newReadRequest(resourcePath + "/handler");
Promise<AuthorizationResult, ResourceException> successResult = newResultPromise(accessPermitted());
given(defaultAuthModule.authorizeRead(any(Context.class), any(ReadRequest.class))).willReturn(successResult);
//When
SmsRouteTree handlerTree = routeTree.handles(serviceName);
handlerTree.addRoute(RoutingMode.STARTS_WITH, "/handler", requestHandler);
routeTree.handleRead(context, request);
//Then
verify(requestHandler).handleRead(any(Context.class), any(ReadRequest.class));
}
Aggregations