From 821a2308608c26b8865c25ad1eff978313e1dd7f Mon Sep 17 00:00:00 2001 From: Possommi Date: Thu, 24 Oct 2024 08:55:50 +0200 Subject: [PATCH] UBO-363 Fixed NullPointerException in MCRUserMatcherLDAP (#426) * UBO-363 Fixed NullPointerException in MCRUserMatcherLDAP * UBO-363 Improved logging of exceptions --- .../main/java/org/mycore/ubo/ldap/LDAPAuthenticator.java | 6 +++--- .../java/org/mycore/ubo/matcher/MCRUserMatcherLDAP.java | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ubo-common/src/main/java/org/mycore/ubo/ldap/LDAPAuthenticator.java b/ubo-common/src/main/java/org/mycore/ubo/ldap/LDAPAuthenticator.java index efe82d570..8d2f11c75 100644 --- a/ubo-common/src/main/java/org/mycore/ubo/ldap/LDAPAuthenticator.java +++ b/ubo-common/src/main/java/org/mycore/ubo/ldap/LDAPAuthenticator.java @@ -118,11 +118,11 @@ private LdapContext getLDAPContext(String uid, String credentials, String dn) th return new InitialLdapContext(env, null); } catch (AuthenticationException ex) { if (ex.getMessage().contains(PATTERN_INVALID_CREDENTIALS)) { - LOGGER.info("Could not authenticate LDAP user " + uid + ": " + ex.getMessage()); - return null; + LOGGER.error("Could not authenticate LDAP user {}:{}", uid, ex.getMessage()); } else { - throw ex; + LOGGER.error("Error while creating {}", LdapContext.class.getSimpleName(), ex); } + return null; } } } diff --git a/ubo-common/src/main/java/org/mycore/ubo/matcher/MCRUserMatcherLDAP.java b/ubo-common/src/main/java/org/mycore/ubo/matcher/MCRUserMatcherLDAP.java index 7da028559..81ab23af9 100644 --- a/ubo-common/src/main/java/org/mycore/ubo/matcher/MCRUserMatcherLDAP.java +++ b/ubo-common/src/main/java/org/mycore/ubo/matcher/MCRUserMatcherLDAP.java @@ -477,15 +477,18 @@ public List getLDAPUsersByGivenLDAPAttributes(Multimap ldapAttribute String ldapSearchFilter = createLDAPSearchFilter(ldapAttributes, searchTemplate); try { ctx = new LDAPAuthenticator().authenticate(); + if (ctx == null) { + return new ArrayList<>(); + } ldapUsers = new LDAPSearcher().searchWithGlobalDN(ctx, ldapSearchFilter); } catch (NamingException ex) { - LOGGER.error("Exception occurred: " + ex); + LOGGER.error("Exception occurred during getting LDAP users", ex); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException ex) { - LOGGER.warn("could not close context " + ex); + LOGGER.warn("Could not close LDAP context", ex); } } }