This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/main by this push:
     new 986a7168ef Port `log4j-jndi` changes from `2.x` (#2163)
986a7168ef is described below

commit 986a7168ef36cb27297c4e7f767bdcdb89af92d0
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Wed Jan 10 15:31:53 2024 +0100

    Port `log4j-jndi` changes from `2.x` (#2163)
---
 .../main/java/org/apache/logging/log4j/jndi/JndiManager.java   |  6 +++---
 .../org/apache/logging/log4j/jndi/internal/JndiCloser.java     |  1 +
 .../java/org/apache/logging/log4j/jndi/lookup/JndiLookup.java  |  9 +++++----
 .../logging/log4j/jndi/selector/JndiContextSelector.java       | 10 +++++-----
 4 files changed, 14 insertions(+), 12 deletions(-)

diff --git 
a/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/JndiManager.java 
b/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/JndiManager.java
index 83248679f9..1f340524ac 100644
--- a/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/JndiManager.java
+++ b/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/JndiManager.java
@@ -67,7 +67,7 @@ public class JndiManager extends AbstractManager {
     }
 
     /**
-     * Gets the default JndiManager using the default {@link 
javax.naming.InitialContext}.
+     * Gets the default JndiManager using the default {@link InitialContext}.
      *
      * @return the default JndiManager
      */
@@ -76,7 +76,7 @@ public class JndiManager extends AbstractManager {
     }
 
     /**
-     * Gets a named JndiManager using the default {@link 
javax.naming.InitialContext}.
+     * Gets a named JndiManager using the default {@link InitialContext}.
      *
      * @param name the name of the JndiManager instance to create or use if 
available
      * @return a default JndiManager
@@ -217,7 +217,7 @@ public class JndiManager extends AbstractManager {
             }
             LOGGER.warn("Unsupported JNDI URI - {}", name);
         } catch (URISyntaxException ex) {
-            LOGGER.warn("Invalid  JNDI URI - {}", name);
+            LOGGER.warn("Invalid JNDI URI - {}", name);
         }
         return null;
     }
diff --git 
a/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/internal/JndiCloser.java
 
b/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/internal/JndiCloser.java
index 6a1dc48992..3b2c557242 100644
--- 
a/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/internal/JndiCloser.java
+++ 
b/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/internal/JndiCloser.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.jndi.internal;
 
 import javax.naming.Context;
 import javax.naming.NamingException;
+import org.apache.logging.log4j.core.util.Closer;
 
 /**
  * Helper class for closing JNDI resources.
diff --git 
a/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/lookup/JndiLookup.java 
b/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/lookup/JndiLookup.java
index 3673059895..80249d7087 100644
--- 
a/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/lookup/JndiLookup.java
+++ 
b/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/lookup/JndiLookup.java
@@ -58,8 +58,9 @@ public class JndiLookup extends AbstractLookup {
 
     /**
      * Looks up the value of the JNDI resource.
+     *
      * @param event The current LogEvent (is ignored by this StrLookup).
-     * @param key  the JNDI resource name to be looked up, may be null
+     * @param key the JNDI resource name to be looked up, may be null
      * @return The String value of the JNDI resource.
      */
     @Override
@@ -77,9 +78,9 @@ public class JndiLookup extends AbstractLookup {
     }
 
     /**
-     * Convert the given JNDI name to the actual JNDI name to use.
-     * Default implementation applies the "java:comp/env/" prefix
-     * unless other scheme like "java:" is given.
+     * Convert the given JNDI name to the actual JNDI name to use. Default 
implementation applies the "java:comp/env/"
+     * prefix unless other scheme like "java:" is given.
+     *
      * @param jndiName The name of the resource.
      * @return The fully qualified name to look up.
      */
diff --git 
a/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/selector/JndiContextSelector.java
 
b/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/selector/JndiContextSelector.java
index c7c86dcca9..b23ed36c22 100644
--- 
a/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/selector/JndiContextSelector.java
+++ 
b/log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/selector/JndiContextSelector.java
@@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
 import javax.naming.NamingException;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.impl.ContextAnchor;
-import org.apache.logging.log4j.core.selector.ContextSelector;
 import org.apache.logging.log4j.core.selector.NamedContextSelector;
 import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.jndi.JndiManager;
@@ -43,6 +42,7 @@ import org.apache.logging.log4j.status.StatusLogger;
  * context to look up the value of the entry. The logging context of the 
web-application will depend on the value the
  * env-entry. The JNDI context which is looked up by this class is 
<code>java:comp/env/log4j/context-name</code>.
  *
+ * <p>For security reasons, JNDI must be enabled by setting system property 
<code>log4j2.enableJndiContextSelector=true</code>.</p>
  * <p>
  * Here is an example of an <code>env-entry</code>:
  * </p>
@@ -96,8 +96,8 @@ public class JndiContextSelector implements 
NamedContextSelector {
     private static final StatusLogger LOGGER = StatusLogger.getLogger();
 
     public JndiContextSelector() {
-        if (!JndiManager.isJndiEnabled()) {
-            throw new IllegalStateException("JNDI must be enabled by setting 
log4j2.enableJndi=true");
+        if (!JndiManager.isJndiContextSelectorEnabled()) {
+            throw new IllegalStateException("JNDI must be enabled by setting 
log4j2.enableJndiContextSelector=true");
         }
     }
 
@@ -112,7 +112,7 @@ public class JndiContextSelector implements 
NamedContextSelector {
             }
         }
         if (ctx != null) {
-            ctx.stop(ContextSelector.DEFAULT_STOP_TIMEOUT, 
TimeUnit.MILLISECONDS);
+            ctx.stop(DEFAULT_STOP_TIMEOUT, TimeUnit.MILLISECONDS);
         }
     }
 
@@ -148,7 +148,7 @@ public class JndiContextSelector implements 
NamedContextSelector {
         return loggingContextName == null ? CONTEXT : 
locateContext(loggingContextName, null, configLocation);
     }
 
-    private String getContextName() {
+    private static String getContextName() {
         String loggingContextName = null;
 
         try (final JndiManager jndiManager = JndiManager.getDefaultManager()) {

Reply via email to