Skip to content

Commit 986a716

Browse files
committed
Port log4j-jndi changes from 2.x (#2163)
1 parent 6d1d346 commit 986a716

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/JndiManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private JndiManager(final String name, final Context context) {
6767
}
6868

6969
/**
70-
* Gets the default JndiManager using the default {@link javax.naming.InitialContext}.
70+
* Gets the default JndiManager using the default {@link InitialContext}.
7171
*
7272
* @return the default JndiManager
7373
*/
@@ -76,7 +76,7 @@ public static JndiManager getDefaultManager() {
7676
}
7777

7878
/**
79-
* Gets a named JndiManager using the default {@link javax.naming.InitialContext}.
79+
* Gets a named JndiManager using the default {@link InitialContext}.
8080
*
8181
* @param name the name of the JndiManager instance to create or use if available
8282
* @return a default JndiManager
@@ -217,7 +217,7 @@ public <T> T lookup(final String name) throws NamingException {
217217
}
218218
LOGGER.warn("Unsupported JNDI URI - {}", name);
219219
} catch (URISyntaxException ex) {
220-
LOGGER.warn("Invalid JNDI URI - {}", name);
220+
LOGGER.warn("Invalid JNDI URI - {}", name);
221221
}
222222
return null;
223223
}

log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/internal/JndiCloser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import javax.naming.Context;
2020
import javax.naming.NamingException;
21+
import org.apache.logging.log4j.core.util.Closer;
2122

2223
/**
2324
* Helper class for closing JNDI resources.

log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/lookup/JndiLookup.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ public JndiLookup() {
5858

5959
/**
6060
* Looks up the value of the JNDI resource.
61+
*
6162
* @param event The current LogEvent (is ignored by this StrLookup).
62-
* @param key the JNDI resource name to be looked up, may be null
63+
* @param key the JNDI resource name to be looked up, may be null
6364
* @return The String value of the JNDI resource.
6465
*/
6566
@Override
@@ -77,9 +78,9 @@ public String lookup(final LogEvent event, final String key) {
7778
}
7879

7980
/**
80-
* Convert the given JNDI name to the actual JNDI name to use.
81-
* Default implementation applies the "java:comp/env/" prefix
82-
* unless other scheme like "java:" is given.
81+
* Convert the given JNDI name to the actual JNDI name to use. Default implementation applies the "java:comp/env/"
82+
* prefix unless other scheme like "java:" is given.
83+
*
8384
* @param jndiName The name of the resource.
8485
* @return The fully qualified name to look up.
8586
*/

log4j-jndi/src/main/java/org/apache/logging/log4j/jndi/selector/JndiContextSelector.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import javax.naming.NamingException;
2828
import org.apache.logging.log4j.core.LoggerContext;
2929
import org.apache.logging.log4j.core.impl.ContextAnchor;
30-
import org.apache.logging.log4j.core.selector.ContextSelector;
3130
import org.apache.logging.log4j.core.selector.NamedContextSelector;
3231
import org.apache.logging.log4j.core.util.Constants;
3332
import org.apache.logging.log4j.jndi.JndiManager;
@@ -43,6 +42,7 @@
4342
* context to look up the value of the entry. The logging context of the web-application will depend on the value the
4443
* env-entry. The JNDI context which is looked up by this class is <code>java:comp/env/log4j/context-name</code>.
4544
*
45+
* <p>For security reasons, JNDI must be enabled by setting system property <code>log4j2.enableJndiContextSelector=true</code>.</p>
4646
* <p>
4747
* Here is an example of an <code>env-entry</code>:
4848
* </p>
@@ -96,8 +96,8 @@ public class JndiContextSelector implements NamedContextSelector {
9696
private static final StatusLogger LOGGER = StatusLogger.getLogger();
9797

9898
public JndiContextSelector() {
99-
if (!JndiManager.isJndiEnabled()) {
100-
throw new IllegalStateException("JNDI must be enabled by setting log4j2.enableJndi=true");
99+
if (!JndiManager.isJndiContextSelectorEnabled()) {
100+
throw new IllegalStateException("JNDI must be enabled by setting log4j2.enableJndiContextSelector=true");
101101
}
102102
}
103103

@@ -112,7 +112,7 @@ public void shutdown(
112112
}
113113
}
114114
if (ctx != null) {
115-
ctx.stop(ContextSelector.DEFAULT_STOP_TIMEOUT, TimeUnit.MILLISECONDS);
115+
ctx.stop(DEFAULT_STOP_TIMEOUT, TimeUnit.MILLISECONDS);
116116
}
117117
}
118118

@@ -148,7 +148,7 @@ public LoggerContext getContext(
148148
return loggingContextName == null ? CONTEXT : locateContext(loggingContextName, null, configLocation);
149149
}
150150

151-
private String getContextName() {
151+
private static String getContextName() {
152152
String loggingContextName = null;
153153

154154
try (final JndiManager jndiManager = JndiManager.getDefaultManager()) {

0 commit comments

Comments
 (0)