Skip to content

LdapHealthIndicator reports UNKNOWN instead of UP when LDAP server doesn't expose a protocol version - #51441

Merged
philwebb merged 2 commits into
spring-projects:4.1.xfrom
2heunxun:fix/ldap-health-indicator-unknown-status
Aug 25, 2026
Merged

philwebb merged 2 commits into
spring-projects:4.1.xfrom
2heunxun:fix/ldap-health-indicator-unknown-status

Conversation

@2heunxun

Copy link
Copy Markdown
Contributor

What happened?

LdapHealthIndicator.doHealthCheck() reads the LDAP server's protocol version from a JNDI environment attribute and only reports the health status as UP if that version is present:

String version = this.ldapOperations.executeReadOnly(versionContextExecutor);
if (version != null) {
    builder.up().withDetail("version", version);
}

However, executeReadOnly() returning without throwing already means the LDAP connection succeeded.

java.naming.ldap.version is a JNDI environment attribute that a client requests explicitly. It is not something the server always echoes back, and Spring LDAP's default LdapContextSource configuration does not set it.

As a result, in a common setup, version can be null even though the LDAP connection is perfectly healthy.

When this happens, builder.up() is never called. Since Health.Builder defaults to Status.UNKNOWN, the indicator incorrectly reports UNKNOWN for a working LDAP connection instead of UP.

What should happen?

A successful LDAP round trip should report UP, regardless of whether the optional version detail is available.

How to reproduce?

Added LdapHealthIndicatorTests#ldapIsUpWhenVersionIsUnavailable.

The test stubs executeReadOnly() to return null, representing a successful connection where the LDAP version is unavailable, and asserts that:

  • The health status is UP.
  • No version detail is included.

On the current code, this test fails because the status is UNKNOWN instead of UP.

What does this PR change?

doHealthCheck() now calls builder.up() unconditionally after a successful executeReadOnly() call.

The version detail is only added when the version is available:

String version = this.ldapOperations.executeReadOnly(versionContextExecutor);
builder.up();

if (version != null) {
    builder.withDetail("version", version);
}

No public API changes are introduced.

Impact / risk

  • Connection succeeds + version available: Unchanged. Reports UP with the version detail.
  • Connection succeeds + version unavailable: Now correctly reports UP instead of UNKNOWN. This is the fix.
  • Connection fails: Unchanged. Reports DOWN through AbstractHealthIndicator's exception handling.

Tests

  • Added the regression test ldapIsUpWhenVersionIsUnavailable.
  • Existing LdapHealthIndicatorTests continue to pass.
  • checkstyleMain passes.
  • checkstyleTest passes.
  • format passes.
  • :module:spring-boot-ldap:test passes.

ps. Sorry for the noise. I originally opened this against the wrong base branch (4.1.x) and closed it (#51440). This PR targets main as intended.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Aug 25, 2026
@wilkinsona

Copy link
Copy Markdown
Member

This is a regression in 4.1 due to the changes in d26b689.

@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Aug 25, 2026
@wilkinsona wilkinsona added this to the 4.1.x milestone Aug 25, 2026
@philwebb philwebb self-assigned this Aug 25, 2026
2heunxun and others added 2 commits August 25, 2026 11:43
Fix regression caused by commit d26b689 which caused
`doHealthCheck()` to only call `builder.up()` when the LDAP
server's protocol version (`java.naming.ldap.version`) could be
read from the JNDI environment.

See spring-projectsgh-51441

Signed-off-by: 2heunxun <seapeon@naver.com>
@philwebb
philwebb force-pushed the fix/ldap-health-indicator-unknown-status branch from f3062af to 014bbcc Compare August 25, 2026 18:47
@philwebb
philwebb changed the base branch from main to 4.1.x August 25, 2026 18:48
@philwebb
philwebb merged commit fcd2c9a into spring-projects:4.1.x Aug 25, 2026
3 of 4 checks passed
@philwebb philwebb modified the milestones: 4.1.x, 4.1.2 Aug 25, 2026
@philwebb

Copy link
Copy Markdown
Member

Thanks very much @2heunxun

@2heunxun

Copy link
Copy Markdown
Contributor Author

@philwebb My pleasure! Thanks for merging it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: regression A regression from a previous release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants