RestEndpoints.java revision da3717708a8396fc1c8e5bcca7c79205d52d9871
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2014 ForgeRock AS.
*/
/**
* Singleton class which contains both the routers for CREST resources and Restlet service endpoints.
*
* @since 12.0.0
*/
public class RestEndpoints {
private final RestRealmValidator realmValidator;
private final VersionSelector versionSelector;
private final CoreWrapper coreWrapper;
private final CrestRouter resourceRouter;
private final ServiceRouter jsonServiceRouter;
private final ServiceRouter xacmlServiceRouter;
private final Router oauth2ServiceRouter;
/**
* Constructs a new RestEndpoints instance.
*
* @param realmValidator An instance of the RestRealmValidator.
* @param versionSelector An instance of the VersionSelector.
*/
public RestEndpoints(RestRealmValidator realmValidator, VersionSelector versionSelector, CoreWrapper coreWrapper) {
this(realmValidator, versionSelector, coreWrapper, OrganizationConfigManager.getInvalidRealmNames());
}
RestEndpoints(RestRealmValidator realmValidator, VersionSelector versionSelector, CoreWrapper coreWrapper,
this.realmValidator = realmValidator;
this.versionSelector = versionSelector;
this.coreWrapper = coreWrapper;
this.oauth2ServiceRouter = createOAuth2Router();
}
/**
* Gets the CREST resource router.
* @return The router.
*/
public CrestRouter getResourceRouter() {
return resourceRouter;
}
/**
* Gets the JSON restlet service router.
* @return The router.
*/
public ServiceRouter getJSONServiceRouter() {
return jsonServiceRouter;
}
/**
* Gets the XACML restlet service router.
* @return The router.
*/
public ServiceRouter getXACMLServiceRouter() {
return xacmlServiceRouter;
}
/**
* Gets the OAuth2 restlet service router.
* @return The router.
*/
public Router getOAuth2ServiceRouter() {
return oauth2ServiceRouter;
}
/**
* Constructs a new {@link org.forgerock.openam.rest.resource.CrestRealmRouter} with routes to each of the CREST
* resource endpoints.
*
* @return A {@code RealmRouter}.
*/
// Ensure all routes are added to the realm name blacklist
FluentRouter rootRealmRouter = new RealmBlackListingFluentRouter(rootRealmRouterDelegate, invalidRealmNames);
//not protected
//protected
return rootRealmRouterDelegate;
}
/**
* Constructs a new {@link ServiceRouter} with routes to each of the Restlet service endpoints.
*
* @return A {@code ServiceRouter}.
*/
return router;
}
/**
* Constructs a new {@link ServiceRouter} with routes to each of the Restlet service endpoints.
*
* @return A {@code ServiceRouter}.
*/
return router;
}
private Router createOAuth2Router() {
// Standard OAuth2 endpoints
// OpenID Connect endpoints
// OpenID Connect Discovery
return router;
}
/**
* Decorator realm router that ensures that any REST endpoint route names are automatically added to the
* realm name black-list to prevent clashes.
*/
private static class RealmBlackListingFluentRealmRouter implements FluentRealmRouter {
private final FluentRealmRouter delegate;
RealmBlackListingFluentRealmRouter(final FluentRealmRouter delegate, final Set<String> invalidRealmNames) {
this.invalidRealmNames = invalidRealmNames;
}
}
return this;
}
return this;
}
}
/**
* Decorator router that ensures that any REST endpoint route names are automatically added to the
* realm name black-list to prevent clashes.
*/
private static class RealmBlackListingFluentRouter extends FluentRouter {
private final FluentRouter delegate;
public RealmBlackListingFluentRouter(final FluentRouter delegate, final Set<String> invalidRealmNames) {
this.invalidRealmNames = invalidRealmNames;
}
}
public FluentRealmRouter dynamically() {
}
}
/**
* Returns the first path segment from a uri template. For example {@code /foo/bar} becomes {@code foo}.
*
* @param path the full uri template path.
* @return the first non-empty path segment.
* @throws IllegalArgumentException if the path contains no non-empty segments.
*/
return part;
}
}
}
}