Class LoginHandler

java.lang.Object
org.codelibs.fess.api.v2.handlers.LoginHandler

public class LoginHandler extends Object
Handles POST /api/v2/auth/login.

Authentication entry point for the static theme SPA. Performs a tiered set of cheap-first gates: IP rate-limit, body parsing, presence checks, per-user rate-limit, then finally credential verification via FessLoginAssist. On success the response carries the freshly issued CSRF token and an echo of return_to (only when it is a relative path — protocol-relative URLs are rejected to prevent open-redirect).

Constructor-injected LoginRateLimiter keeps the handler easy to test: production wires the DI-managed singleton via ComponentUtil.getLoginRateLimiter(), tests pass a fresh instance.

MJ-30 i18n contract: error.message values in this handler are developer-facing English strings. Clients MUST use error.code (the V2ErrorCode token) for user-facing i18n. This is intentional — the v2 wire spec explicitly separates machine-readable codes from human messages.

  • Constructor Details

    • LoginHandler

      public LoginHandler()
      Default constructor used by the DI container. The handler resolves the shared LoginRateLimiter lazily via limiter() so DI bootstrap order is not constrained. The handler holds no per-request state and is safe to share across concurrent requests.
    • LoginHandler

      public LoginHandler(LoginRateLimiter limiter)
      Test-friendly constructor allowing the caller to inject a specific LoginRateLimiter instance (e.g. with a controllable clock). Passing null causes the handler to resolve the DI-managed singleton via ComponentUtil.getLoginRateLimiter() on first use.
      Parameters:
      limiter - the rate limiter to use, or null to resolve via DI
  • Method Details

    • handle

      public void handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException
      Processes one POST /api/v2/auth/login request.

      Applies a tiered set of cheap-first gates (IP rate-limit, body parse, presence checks, per-user rate-limit) before invoking FessLoginAssist for credential verification. On success the response carries the freshly issued CSRF token and an echo of the safe return_to value; failures map to v2 error codes (V2ErrorCode.RATE_LIMITED, V2ErrorCode.INVALID_REQUEST, V2ErrorCode.AUTH_REQUIRED, V2ErrorCode.INTERNAL_ERROR).

      Parameters:
      req - the incoming HTTP request
      res - the HTTP response to write to
      Throws:
      IOException - if writing the envelope or reading the body fails