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 the getLicenseError(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:
  • Constructor Details

    • LicenseFilter

      public LicenseFilter()
  • Method Details

    • 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 an OslcError. This filter will automatically serialize such error in the HTTP response.

      Specified by:
      doFilter in class HttpFilter
      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 received Accept header.
      Parameters:
      request - the received request
      response - the response to send
      chain - the filter chain to proceed
      error - the license error received when checking license
      Throws:
      IOException - exception can be thrown when writing response
      ServletException - exception can be thrown when processing filter
      Since:
      2.0.0