mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Polish LdapHealthIndicator
See gh-51441
This commit is contained in:
+3
-18
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.boot.ldap.health;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.boot.health.contributor.AbstractHealthIndicator;
|
||||
@@ -37,7 +34,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class LdapHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private static final ContextExecutor<@Nullable String> versionContextExecutor = new VersionContextExecutor();
|
||||
private static final ContextExecutor<@Nullable String> versionContextExecutor = (
|
||||
dirContext) -> (String) dirContext.getEnvironment().get("java.naming.ldap.version");
|
||||
|
||||
private final LdapOperations ldapOperations;
|
||||
|
||||
@@ -49,24 +47,11 @@ public class LdapHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
String version = this.ldapOperations.executeReadOnly(versionContextExecutor);
|
||||
builder.up();
|
||||
String version = this.ldapOperations.executeReadOnly(versionContextExecutor);
|
||||
if (version != null) {
|
||||
builder.withDetail("version", version);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class VersionContextExecutor implements ContextExecutor<@Nullable String> {
|
||||
|
||||
@Override
|
||||
public @Nullable String executeWithContext(DirContext ctx) throws NamingException {
|
||||
Object version = ctx.getEnvironment().get("java.naming.ldap.version");
|
||||
if (version != null) {
|
||||
return (String) version;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user