Class RestJSentinelVersionFilter

java.lang.Object
com.svenruppert.jsentinel.rest.RestJSentinelVersionFilter

@ExperimentalJSentinelApi public final class RestJSentinelVersionFilter extends Object
REST adapter for JSentinelVersionEnforcer.

Wire this filter before RestAuthorizationFilter in the application's request pipeline. allow(RestRequest, RestResponse, String) returns true when the request passes the drift check — the caller proceeds with authorization. It returns false when the session has drifted; in that case the filter has already written the 401 response with a WWW-Authenticate: SessionStale header (RFC 7235) and the SessionStale audit event has been published. Callers must not invoke the handler in that case.

If the RestSubjectResolver does not surface a RestJSentinelVersionContext (the default), the filter returns true unconditionally — applications that don't yet track per-session versions opt in by overriding resolveJSentinelVersionContext.

  • Field Details

    • SESSION_STALE_CHALLENGE

      public static final String SESSION_STALE_CHALLENGE
      Header value advertised when the session has drifted (RFC 7235 style).
      See Also:
  • Constructor Details

    • RestJSentinelVersionFilter

      public RestJSentinelVersionFilter(RestSubjectResolver resolver, com.svenruppert.jsentinel.session.JSentinelVersionEnforcer enforcer)
      Parameters:
      resolver - subject / version-context resolver; non-null
      enforcer - adapter-neutral enforcer; non-null
  • Method Details

    • allow

      public boolean allow(RestRequest request, RestResponse response, String route)
      Runs the drift check.
      Parameters:
      request - current request; non-null
      response - response to populate on drift; non-null
      route - route / path used in the audit event; may be null — the filter passes through to enforce
      Returns:
      true when the request passes (caller proceeds); false when the session has drifted (caller must skip the handler — the response is already written)
    • allow

      public boolean allow(RestRequest request, RestResponse response)
      Convenience overload that derives route from request.path().
      Parameters:
      request - current request; non-null
      response - response to populate on drift; non-null
      Returns:
      same semantics as allow(RestRequest, RestResponse, String)