Web Application Endpoint

Platform allows you to disable endpoints within web apps. This functionality may be useful especially for REST-oriented applications.

The example below shows how to disable endpoints in a web app.

The example web app offers the following endpoints:

/platform
/platform/init
/platform/update
/platform/system
/console/impex/export
/console/impex/import

Assume that you want to set up Platform to permanently disable the /hac/platform/init and /hac/platform/update endpoints. You can do it through a configuration that uses appropriate properties.

The configuration property responsible for disabling endpoints uses the following naming convention: endpoint.extensionName.endpointPath.disabled=true|false, where:

  • endpoint is a constant part and must be always included

  • extensionName is the name of the extension that provides the web app; in the example, it is the hac extension

  • endpointPath is a dotted version of the endpoint path, for example, foo.bar.baz is the dotted version of the /foo/bar/baz path.

  • disabled is a constant part and must be always included

Here is the property configured to disable the /hac/platform/init and /hac/platform/update endpoints:

endpoint.hac.platform.init.disabled=true
endpoint.hac.platform.update.disabled=true

ResourcesGuardService

ResourcesGuardService enables you to check whether an endpoint in a web app is configured to be disabled or enabled. It also enables you to manage configuration propagation for endpoint paths and subpaths. You can inject it through Spring by using the ResourcesGuardService ID.

Checking Whether Endpoints Are Disabled

ResourcesGuardService provides two public methods that enable you to check whether endpoints are disabled or enabled:

  • boolean isResourceDisabled(String extensionName, String resourcePath)

  • boolean isResourceEnabled(String extensionName, String resourcePath)

This example shows how to use them:

// assuming resourceGuardService was injected by Spring
boolean platformInitDisabled = resourcesGuardService.isResourceDisabled("hac", "/platform/init");
boolean platformUpdateDisabled = resourcesGuardService.isResourceDisabled("hac", "/platform/update");
 
// assertions
assertThat(platformInitDisabled).isTrue();
assertThat(platformUpdateDisabled).isTrue();

Propagating Configuration for Paths and Subpaths

By default, each configuration respects the parent-child hierarchy of paths and subpaths. It means that a configuration set for a given path propagates into all subpaths of that path.

For example, the /platform path has these three subpaths: /platform/init, /platform/update, and /platform/system. Disabling only the /platform path makes all the three subpaths disabled too - by default and without any further configuration:

endpoint.hac.platform.disabled=true

To prevent your configuration from propagating from a path into its subpaths, explicitly configure those subpaths. Also, configure ResourcesGuardService by setting the endpoints.guardservice.respect.parents property value to false.

For example, here are some available endpoints:

/platform
/platform/init
/platform/update
/platform/system

And here is some configuration:

endpoints.guardservice.respect.parents=false
endpoint.hac.platform.disabled=true
endpoint.hac.platform.update.disabled=false

As a result:

  • /platform/init and /platform/system endpoints inherit the configuration settings from their top-level parent, /platform; these endpoints are disabled because their paths aren't explicitly configured otherwise

  • you prevent the /platform configuration settings from propagating into the /platform/update subpath; the /platform/update endpoint is not disabled

ResourcesGuardFilter

You need a tool to use all the presented configurations and settings to actually make a particular endpoint disabled. Platform provides a new Filter class called ResourcesGuardFilter. You can inject it into the standard SAP Commerce filter chain. Configure it on the web app level as in this example:

<bean id="myWebAppResourcesGuardFilter" class="de.hybris.platform.servicelayer.web.ResourcesGuardFilter">
    <property name="resourcesGuardService" ref="resourcesGuardService"/>
    <property name="extensionName" value="myWebApp" />
</bean>
 
<bean id="myWebAppFilterChain" class="de.hybris.platform.servicelayer.web.BackOfficeFilterChain">
    <constructor-arg>
        <list>
            <ref bean="myWebAppResourcesGuardFilter"/>
            <!-- Possible other filters here... -->
        </list>
    </constructor-arg>
</bean>

By default, this filter sends the HTTP 404 code whenever it finds that a particular request URI matches a configured endpoint and that endpoint is disabled. It may also send a redirect to a particular page or endpoint if you configure it to do so, for example:

<bean id="myWebAppResourcesGuardFilter" class="de.hybris.platform.servicelayer.web.ResourcesGuardFilter">
    <property name="resourcesGuardService" ref="resourcesGuardService"/>
    <property name="extensionName" value="myWebApp" />
    <property name="reditectTo" value="/404.jsp" />
</bean>

Hiding Tabs in SAP Commerce Administration Console

If you disable endpoints that are URLs to Administration Console tabs, the tabs become invisible.

Considerations

The provided tools read a configuration and help you determine whether some endpoints in your web app are configured to be disabled. Your web app, however, may have, for example, navigation links to those endpoints on some jsp pages. You need to implement your own logic to use ResourcesGuardService if you don't want the end user to see such links.