Class LicenseFilter
- java.lang.Object
-
- com.sodius.oslc.server.services.HttpFilter
-
- com.sodius.oslc.server.security.services.LicenseFilter
-
- All Implemented Interfaces:
Filter
public class LicenseFilter extends HttpFilter
Allows to check license when accessing end-points.When the license is not verified, the filter strategy depends on the
Accept
header received:- For a known OSLC media type (
application/rdf+xml
,application/xml
,text/xml
,application/json
,text/turtle
), the filter chain is aborted and the response contains an OSLC Error entity. - For a
text/html
or a wildcard media type, the filter chain is processed and an error message is added as an attribute of the request. This enables the servlet to provide an HTML page which displays a license error message at its convenience, using thegetLicenseError(HttpServletRequest)
method. - For any other media types, the filter chain is aborted and the response contains an error message with a
text/plain
content type.
- Since:
- 2.0.0
- See Also:
getLicenseError(HttpServletRequest)
-
-
Constructor Summary
Constructors Constructor Description LicenseFilter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
Processes this filter and either executes or blocks the chain.static Optional<String>
getLicenseError(HttpServletRequest request)
Allows to request attribute containing a license error message, if any.protected void
handleLicenseException(HttpServletRequest request, HttpServletResponse response, FilterChain chain, OslcError error)
Handles the behavior of the filter when the license is not verified, depending on the receivedAccept
header.-
Methods inherited from class com.sodius.oslc.server.services.HttpFilter
destroy, doFilter, handleOslcError, init
-
-
-
-
Method Detail
-
doFilter
protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException
Description copied from class:HttpFilter
Processes this filter and either executes or blocks the chain.Subclasses may throw a
OslcWebApplicationException
to report anOslcError
. This filter will automatically serialize such error in the HTTP response.- Specified by:
doFilter
in classHttpFilter
- Parameters:
request
- the request.response
- the response.chain
- the filter chain to process.- Throws:
IOException
- if an I/O error occurs.ServletException
- if the filter execution fails.
-
getLicenseError
public static Optional<String> getLicenseError(HttpServletRequest request)
Allows to request attribute containing a license error message, if any. This shall be used by a servlet producing HTML content to include the license error as part of the page, at its convenience.- Parameters:
request
- the received request- Returns:
- an optional string if an error message is present, optional empty otherwise.
-
handleLicenseException
protected void handleLicenseException(HttpServletRequest request, HttpServletResponse response, FilterChain chain, OslcError error) throws IOException, ServletException
Handles the behavior of the filter when the license is not verified, depending on the receivedAccept
header.- Parameters:
request
- the received requestresponse
- the response to sendchain
- the filter chain to proceederror
- the license error received when checking license- Throws:
IOException
- exception can be thrown when writing responseServletException
- exception can be thrown when processing filter- Since:
- 2.0.0
-
-