Class CmsProtectedStaticFileHandler
- All Implemented Interfaces:
I_CmsConfigurationParameterHandler
,I_CmsNeedsAdminCmsObject
,I_CmsResourceInit
,I_CmsCustomLinkRenderer
Resources are accessed by appending their VFS root path to the /staticresource handler path. When resources are requested this way, they are still loaded with the normal OpenCms loader mechanism. This works for the intended use case (binary files, images) but may not work for other types.
The resources accessible through this handler can be restricted by setting regex configuration parameters for path and type which the requested resources have to match.
This can be used in combination with the CmsJsonResourceHandler class. When configured correctly (using the linkrewrite.id parameter on this handler, and a matching linkrewrite.refid on the CmsJsonResourceHandler), links to resources this handler is responsible for will be rewritten to point to the URL for the resource using this handler.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Configuration parameter that determines which authorization method to use.static final String
Parameter for defining the id under which the link renderer should be registered.static final String
static final String
Configuration parameter for the path filter regex.static final String
Configuration parameter for the type filter regex.static final String
URL prefix.Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD
Fields inherited from interface org.opencms.main.I_CmsResourceInit
ATTR_ALTERNATIVE_CMS_OBJECT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addConfigurationParameter
(String paramName, String paramValue) Adds a configuration parameter to this parameter configurable class instance.Gets the configuration data.getLink
(CmsObject cms, CmsResource resource) Returns the link for the given link resource.Returns the link for the given link object.void
Initializes a configuration after all parameters have been added.initResource
(CmsResource origRes, CmsObject cms, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) Possibility to modify or change the CmsFile with the CmsObject.static String
mergeLinkPrefix
(String prefix, String path, String query) Merges a link prefix with additional link components.void
setAdminCmsObject
(CmsObject adminCms) Sets the admin CmsObject.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opencms.main.I_CmsResourceInit
initParameters
-
Field Details
-
PARAM_LINKREWRITE_ID
Parameter for defining the id under which the link renderer should be registered.- See Also:
-
PARAM_AUTHORIZATION
Configuration parameter that determines which authorization method to use.- See Also:
-
PARAM_PATHFILTER
Configuration parameter for the path filter regex.- See Also:
-
PARAM_TYPEFILTER
Configuration parameter for the type filter regex.- See Also:
-
PREFIX
URL prefix.- See Also:
-
PARAM_LINKREWRITE_PREFIX
- See Also:
-
-
Constructor Details
-
CmsProtectedStaticFileHandler
public CmsProtectedStaticFileHandler()
-
-
Method Details
-
mergeLinkPrefix
Merges a link prefix with additional link components.- Parameters:
prefix
- the prefixpath
- the pathquery
- the query- Returns:
- the combined link
-
addConfigurationParameter
Description copied from interface:I_CmsConfigurationParameterHandler
Adds a configuration parameter to this parameter configurable class instance.- Specified by:
addConfigurationParameter
in interfaceI_CmsConfigurationParameterHandler
- Parameters:
paramName
- the name of the parameterparamValue
- the value for the parameter- See Also:
-
getConfiguration
Description copied from interface:I_CmsResourceInit
Gets the configuration data.- Specified by:
getConfiguration
in interfaceI_CmsConfigurationParameterHandler
- Specified by:
getConfiguration
in interfaceI_CmsResourceInit
- Returns:
- the configuration data
- See Also:
-
getLink
Description copied from interface:I_CmsCustomLinkRenderer
Returns the link for the given link object.If null is returned, this means the normal link handling behavior should be used instead.
- Specified by:
getLink
in interfaceI_CmsCustomLinkRenderer
- Parameters:
cms
- the CMS contextlink
- the link object- Returns:
- the link for the link object
- See Also:
-
getLink
Description copied from interface:I_CmsCustomLinkRenderer
Returns the link for the given link resource.If null is returned, this means the normal link handling behavior should be used instead.
- Specified by:
getLink
in interfaceI_CmsCustomLinkRenderer
- Parameters:
cms
- the CMS contextresource
- the resource linked to- Returns:
- the link for the link object
- See Also:
-
initConfiguration
Description copied from interface:I_CmsConfigurationParameterHandler
Initializes a configuration after all parameters have been added.- Specified by:
initConfiguration
in interfaceI_CmsConfigurationParameterHandler
- See Also:
-
initResource
public CmsResource initResource(CmsResource origRes, CmsObject cms, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws CmsResourceInitException Description copied from interface:I_CmsResourceInit
Possibility to modify or change the CmsFile with the CmsObject.Caution: reading parameters from the request, destroys special characters in all parameters, because the encoding for the request was not set yet.
- Specified by:
initResource
in interfaceI_CmsResourceInit
- Parameters:
origRes
- the requested filecms
- the current CmsObjectreq
- the current requestres
- the current response- Returns:
- a resource in the OpenCms VFS
- Throws:
CmsResourceInitException
- if other implementations of the interface should not be executed- See Also:
-
setAdminCmsObject
Description copied from interface:I_CmsNeedsAdminCmsObject
Sets the admin CmsObject.- Specified by:
setAdminCmsObject
in interfaceI_CmsNeedsAdminCmsObject
- Parameters:
adminCms
- a CmsObject with admin privileges- See Also:
-