Repository navigation
fix(mcp): stop logging rejected MCP logins as exceptions - #33604
Conversation
A rejected credential is the expected outcome of /mcp/login, not a fault,
but the servlet logged two of them with a full stack trace:
- checkIfLoginBlocked's AuthenticationException was logged as
LOG.warn("Login blocked for user", e) — a stack dump for the lockout
policy working as designed.
- An unknown account never reaches the AuthenticationException catch at
all. Both authenticators report it as CustomExceptionMessage
(BasicAuthenticator.lookUserInProvider, LdapAuthenticator.lookUserInProvider),
so it fell through to the generic handler: ERROR + stack trace, and
HTTP 500 instead of the login form.
Log both as events, and give the unknown-account case the same inline
"Invalid username or password" form the wrong-password case already gets.
LDAP reuses CustomExceptionMessage for an unreachable directory, so the
new catch rethrows anything that isn't INVALID_USER_OR_PASSWORD and that
still reaches the generic handler.
WebServiceException.errorType had no accessor and is the only reliable
discriminator here — LDAP reports an unknown user as 500 and a connection
failure as 503, so the status can't be used. Added the getter.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Code Review ✅ Approved🟡 Medium risk Stops logging rejected MCP logins as exceptions by catching OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
| // Both authenticators report an unknown account as CustomExceptionMessage, and LDAP uses | ||
| // the same type for a directory that is unreachable. Only INVALID_USER_OR_PASSWORD is a | ||
| // rejected credential; anything else is a real fault the outer handler must still log. | ||
| if (!INVALID_USER_OR_PASSWORD.equals(e.getErrorType())) { |
There was a problem hiding this comment.
LDAP Misconfiguration Is Masked
When an LDAP entry lacks the configured username or email attribute, LdapAuthenticator reports the configuration fault with the INVALID_USER_OR_PASSWORD error type. This check then treats it as rejected credentials and renders the login form instead of reaching the generic error handler. As a result, operators receive no server error or diagnostic error log for the LDAP configuration failure. Please distinguish this case using more than errorType, or assign configuration failures a separate error type.
Knowledge Base Used: Client, SDK, and MCP integrations
| } catch (AuthenticationException e) { | ||
| LOG.warn("Login blocked for user", e); | ||
| // Lockout is the policy doing its job, not a fault - record the event, not a stack trace. | ||
| LOG.warn("Login blocked after repeated failed attempts"); |
There was a problem hiding this comment.
adding a username in there would be good
|
✅ Playwright Results — workflow succeededValidated commit ✅ 4486 passed · ❌ 0 failed · 🟡 10 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 51m 22s ⏱️ Max setup 4m 49s · max shard execution 22m 6s · max shard-job elapsed before upload 25m 29s · reporting 19s 🌐 220.97 requests/attempt · 2.23 app boots/UI scenario · 40.95% common-shard skew Optimization targets still in progress:
🟡 10 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
🚦 Removed from the merge queue —
|



Describe your changes:
No linked issue — this came from a production stack trace rather than a filed report. The closest
issue, #32652, covers the same endpoint but was already closed by #32720; the unknown-account 500
below is a distinct bug that fix did not reach.
A rejected credential is the expected outcome of
POST /mcp/login, not a fault, but the servletlogged two of them with a full stack trace:
Lockout.
checkIfLoginBlocked'sAuthenticationExceptionwas logged asLOG.warn("Login blocked for user", e)— a stack dump every time the lockout policy did exactlywhat it was configured to do.
Unknown account. This one never reaches the
AuthenticationExceptioncatch at all. Bothauthenticators report a non-existent account as
CustomExceptionMessage(
BasicAuthenticator.lookUserInProvider:553,LdapAuthenticator.lookUserInProvider:318), not asAuthenticationException, so it fell through to the generic handler:LOG.error(..., e)with astack trace, and HTTP 500 instead of the login form. A typo'd username produced a server
error page.
Both are now logged as events, and the unknown-account case gets the same inline
"Invalid username or password" form the wrong-password case already got.
The reported trace itself (wrong password for an existing user) was already fixed on
mainby#32720, which corrected the servlet's import from
service.exception.AuthenticationExceptiontoservice.security.AuthenticationException. This PR closes the two remaining paths in the samemethod.
Type of change:
High-level design:
Small fix, but one decision is worth recording: how to tell a rejected credential apart from a real
fault, given both arrive as
CustomExceptionMessage.LDAP reuses that same type for an unreachable directory (
LDAP_CONNECTION_ERROR), which must keepreaching the generic handler and being logged in full. Status code can't discriminate — LDAP reports
an unknown user as 500 and a connection failure as 503, while Basic reports an unknown user
as 400. The only stable discriminator is
errorType(INVALID_USER_OR_PASSWORD), whichWebServiceExceptionheld in a private field with no accessor. So:WebServiceException— addedgetErrorType(). Purely additive; the nestedErrorMessagealreadyexposed the same value.
BasicAuthLoginServlet— the newcatch (CustomExceptionMessage)rethrows anything that isn'tINVALID_USER_OR_PASSWORD, so infrastructure failures are unaffected.Alternative rejected: matching on the exception message text. Brittle, and there are two different
strings (
INVALID_USERNAME_PASSWORD,INVALID_EMAIL_PASSWORD) for the same condition.No migration, schema, or API-contract impact. Behaviour change is confined to
/mcp/login: anunknown account now returns 200 + login form instead of 500.
Tests:
Use cases covered
password"; no 500, no stack trace in the log.
Unit tests
openmetadata-mcp/src/test/java/org/openmetadata/mcp/server/auth/handlers/BasicAuthLoginServletTest.javadoPost_unknownAccount_rendersLoginFormWithInvalidCredentialsMessage(new)doPost_ldapDirectoryUnavailable_fallsThroughToGenericFailure(new — guards against the catchover-reaching and swallowing real faults)
doPost_unknownAccount_...fails on the unpatched servlet (hits the 500path,
BasicAuthLoginServletTest:221) and passes with the fix.Coverage (JaCoCo,
static-code-analysisprofile): every line added by this PR is covered,including both branches of the new
INVALID_USER_OR_PASSWORDcheck (2/2) and the rethrow. Classline coverage is 47.9% (68/142) — the uncovered remainder is the pre-existing
doGet,auth-code-issue and redirect happy path, which this PR does not touch. The two missed lines inside
the changed region (250–251) are the pre-existing inner
catch (Exception recordEx)block.Full
openmetadata-mcpmodule run: 674 tests, 0 failures, 10 errors — all 10 areIdTokenValidatorTest, an okhttp/mockwebserver classpath mismatch(
NoSuchMethodError: okhttp3.internal.concurrent.TaskRunner.<init>). Confirmed pre-existing:identical 10 errors on a clean
origin/maincheckout.Backend integration tests
/mcp/loginis a browser-facing servlet in theMCP OAuth flow, covered by the unit tests above.
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
Not performed — no local stack was started for this change. Verification was automated: the red/green
check above proves the unknown-account path changed from 500 to the inline form, and the
LDAP-unavailable test proves the new catch doesn't swallow real faults.
UI screen recording / screenshots:
Not applicable — no UI changes.
Checklist:
Fixes <issue-number>: <short explanation>— N/A, no linked issue (see above).Fixes #<issue-number>above — N/A, see above.Known adjacent issue, deliberately left out of scope
For a wrong password the failed attempt is counted twice —
BasicAuthenticator.validatePasswordrecords it before throwing, and the servlet's catch records it again — which effectively halves
maxLoginFailAttemptson this endpoint. Pre-existing, unrelated to the logging fix, and changing italters lockout semantics, so it's better as its own PR.
🤖 Generated with Claude Code
The PR is not yet safe to merge because an LDAP identity-attribute configuration failure is incorrectly converted into an invalid-credentials response.
Findings
Summary
This PR changes MCP browser-login error handling so expected credential rejections no longer produce exception stack traces and unknown accounts return the inline login form rather than HTTP 500.
WebServiceException.errorType.INVALID_USER_OR_PASSWORDexceptions as rejected credentials.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[POST /mcp/login] --> B[Resolve account and validate password] B -->|AuthenticationException| C[Render invalid-credentials form] B -->|CustomExceptionMessage| D{errorType is INVALID_USER_OR_PASSWORD?} D -->|No| E[Generic error handler and HTTP 500] D -->|Yes: unknown account or bad LDAP credentials| C D -->|Yes: LDAP attribute misconfiguration| F[Incorrectly render invalid-credentials form]Reviews (1) · Last reviewed commit: "fix(mcp): stop logging rejected MCP logi..."