Class CmsProtectedStaticFileHandler
- java.lang.Object
-
- org.opencms.main.CmsProtectedStaticFileHandler
-
- All Implemented Interfaces:
I_CmsConfigurationParameterHandler
,I_CmsNeedsAdminCmsObject
,I_CmsResourceInit
,I_CmsCustomLinkRenderer
public class CmsProtectedStaticFileHandler extends java.lang.Object implements I_CmsResourceInit, I_CmsConfigurationParameterHandler, I_CmsNeedsAdminCmsObject, I_CmsCustomLinkRenderer
Resource init handler that provides an alternative way of serving static files like images or binary files, using the API authorization mechanism instead of the normal authorization handler.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
Fields Modifier and Type Field Description static java.lang.String
PARAM_AUTHORIZATION
Configuration parameter that determines which authorization method to use.static java.lang.String
PARAM_LINKREWRITE_ID
Parameter for defining the id under which the link renderer should be registered.static java.lang.String
PARAM_LINKREWRITE_PREFIX
static java.lang.String
PARAM_PATHFILTER
Configuration parameter for the path filter regex.static java.lang.String
PARAM_TYPEFILTER
Configuration parameter for the type filter regex.static java.lang.String
PREFIX
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
Constructors Constructor Description CmsProtectedStaticFileHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConfigurationParameter(java.lang.String paramName, java.lang.String paramValue)
Adds a configuration parameter to this parameter configurable class instance.CmsParameterConfiguration
getConfiguration()
Gets the configuration data.java.lang.String
getLink(CmsObject cms, CmsResource resource)
Returns the link for the given link resource.java.lang.String
getLink(CmsObject cms, CmsLink link)
Returns the link for the given link object.void
initConfiguration()
Initializes a configuration after all parameters have been added.CmsResource
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 java.lang.String
mergeLinkPrefix(java.lang.String prefix, java.lang.String path, java.lang.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 Detail
-
PARAM_LINKREWRITE_ID
public static final java.lang.String PARAM_LINKREWRITE_ID
Parameter for defining the id under which the link renderer should be registered.- See Also:
- Constant Field Values
-
PARAM_AUTHORIZATION
public static final java.lang.String PARAM_AUTHORIZATION
Configuration parameter that determines which authorization method to use.- See Also:
- Constant Field Values
-
PARAM_PATHFILTER
public static final java.lang.String PARAM_PATHFILTER
Configuration parameter for the path filter regex.- See Also:
- Constant Field Values
-
PARAM_TYPEFILTER
public static final java.lang.String PARAM_TYPEFILTER
Configuration parameter for the type filter regex.- See Also:
- Constant Field Values
-
PREFIX
public static final java.lang.String PREFIX
URL prefix.- See Also:
- Constant Field Values
-
PARAM_LINKREWRITE_PREFIX
public static final java.lang.String PARAM_LINKREWRITE_PREFIX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsProtectedStaticFileHandler
public CmsProtectedStaticFileHandler()
-
-
Method Detail
-
mergeLinkPrefix
public static java.lang.String mergeLinkPrefix(java.lang.String prefix, java.lang.String path, java.lang.String query)
Merges a link prefix with additional link components.- Parameters:
prefix
- the prefixpath
- the pathquery
- the query- Returns:
- the combined link
-
addConfigurationParameter
public void addConfigurationParameter(java.lang.String paramName, java.lang.String paramValue)
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:
I_CmsConfigurationParameterHandler.addConfigurationParameter(java.lang.String, java.lang.String)
-
getConfiguration
public CmsParameterConfiguration 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:
I_CmsConfigurationParameterHandler.getConfiguration()
-
getLink
public java.lang.String getLink(CmsObject cms, CmsLink link)
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:
I_CmsCustomLinkRenderer.getLink(org.opencms.file.CmsObject, org.opencms.relations.CmsLink)
-
getLink
public java.lang.String getLink(CmsObject cms, CmsResource resource)
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:
I_CmsCustomLinkRenderer.getLink(org.opencms.file.CmsObject, org.opencms.file.CmsResource)
-
initConfiguration
public void initConfiguration()
Description copied from interface:I_CmsConfigurationParameterHandler
Initializes a configuration after all parameters have been added.- Specified by:
initConfiguration
in interfaceI_CmsConfigurationParameterHandler
- See Also:
I_CmsConfigurationParameterHandler.initConfiguration()
-
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:
I_CmsResourceInit.initResource(org.opencms.file.CmsResource, org.opencms.file.CmsObject, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
-
setAdminCmsObject
public void setAdminCmsObject(CmsObject adminCms)
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:
I_CmsNeedsAdminCmsObject.setAdminCmsObject(org.opencms.file.CmsObject)
-
-