Class OAuthFilter

java.lang.Object
com.sodius.oslc.server.services.HttpFilter
com.sodius.oslc.server.oauth.services.OAuthFilter
All Implemented Interfaces:
Filter

public class OAuthFilter extends HttpFilter
A filter that uses OAuthServer to ensure requests requiring restricted access are authenticated. Possible authentications are:
  • OAuth - check for valid Access token or perform the OAuth dance
  • Basic - check for valid user credentials
  • Session - if no Authorization header on the request, use the OAuthIdentity from the HTTP session, if any
An OSLC provider application can register extensions of the com.sodius.oslc.server.accessControl extension point to indicate servlet paths that require authentication of those which can be freely accessed.

If the OSLC provider application does not run in an OSGi container, the access control should be done by overriding the isProtected(HttpServletRequest request) method.

Since:
1.3.0
See Also:
  • Constructor Details

    • OAuthFilter

      public OAuthFilter()
  • Method Details

    • isProtected

      protected boolean isProtected(HttpServletRequest request)
      Determines whether a request URI requires user authentication.

      This is a default implementation that requires an OSGi container, and is based on the com.sodius.oslc.server.accessControl extension point.

      Parameters:
      request - the HTTP servlet request
      Returns:
      true if the request requires an authentication, false otherwise
      Since:
      1.8.0
    • doFilter

      protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException
      If the servlet being accessed requires user authentication, this filter performs the authentication challenge.

      An OSLC provider application can register extensions of the com.sodius.oslc.server.accessControl extension point to indicate servlet paths that require authentication of those which can be freely accessed.

      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.
    • getLoggedInUser

      protected Optional<OAuthIdentity> getLoggedInUser(HttpServletRequest request)
      Gets the identity of the user currently logged in the application, null if none is found.
      Parameters:
      request - the HTTP request
      Returns:
      the logged-in user identity
      Since:
      2.1.0