JndiManager.java (apache-log4j-2.12.3-src) | : | JndiManager.java (apache-log4j-2.12.4-src) | ||
---|---|---|---|---|
skipping to change at line 45 | skipping to change at line 45 | |||
* Manages a JNDI {@link javax.naming.Context}. | * Manages a JNDI {@link javax.naming.Context}. | |||
* | * | |||
* @since 2.1 | * @since 2.1 | |||
*/ | */ | |||
public class JndiManager extends AbstractManager { | public class JndiManager extends AbstractManager { | |||
private static final JndiManagerFactory FACTORY = new JndiManagerFactory(); | private static final JndiManagerFactory FACTORY = new JndiManagerFactory(); | |||
private static final String PREFIX = "log4j2.enableJndi"; | private static final String PREFIX = "log4j2.enableJndi"; | |||
private static final String JAVA_SCHEME = "java"; | private static final String JAVA_SCHEME = "java"; | |||
private final Context context; | private static final boolean JNDI_CONTEXT_SELECTOR_ENABLED = isJndiEnabled(" | |||
ContextSelector"); | ||||
private static final boolean JNDI_JDBC_ENABLED = isJndiEnabled("Jdbc"); | ||||
private static final boolean JNDI_JMS_ENABLED = isJndiEnabled("Jms"); | ||||
private static final boolean JNDI_LOOKUP_ENABLED = isJndiEnabled("Lookup"); | ||||
private final InitialContext context; | ||||
private static boolean isJndiEnabled(final String subKey) { | private static boolean isJndiEnabled(final String subKey) { | |||
return PropertiesUtil.getProperties().getBooleanProperty(PREFIX + subKey , false); | return PropertiesUtil.getProperties().getBooleanProperty(PREFIX + subKey , false); | |||
} | } | |||
public static boolean isJndiEnabled() { | public static boolean isJndiEnabled() { | |||
return isJndiContextSelectorEnabled() || isJndiJmsEnabled() || isJndiLoo kupEnabled(); | return isJndiContextSelectorEnabled() || isJndiJdbcEnabled() || isJndiJm sEnabled() || isJndiLookupEnabled(); | |||
} | } | |||
public static boolean isJndiContextSelectorEnabled() { | public static boolean isJndiContextSelectorEnabled() { | |||
return isJndiEnabled("ContextSelector"); | return JNDI_CONTEXT_SELECTOR_ENABLED; | |||
} | ||||
public static boolean isJndiJdbcEnabled() { | ||||
return JNDI_JDBC_ENABLED; | ||||
} | } | |||
public static boolean isJndiJmsEnabled() { | public static boolean isJndiJmsEnabled() { | |||
return isJndiEnabled("Jms"); | return JNDI_JMS_ENABLED; | |||
} | } | |||
public static boolean isJndiLookupEnabled() { | public static boolean isJndiLookupEnabled() { | |||
return isJndiEnabled("Lookup"); | return JNDI_LOOKUP_ENABLED; | |||
} | } | |||
private JndiManager(final String name, final Context context) { | private JndiManager(final String name, final InitialContext context) { | |||
super(null, name); | super(null, name); | |||
this.context = context; | this.context = context; | |||
} | } | |||
/** | /** | |||
* Gets the default JndiManager using the default {@link javax.naming.Initia lContext}. | * Gets the default JndiManager using the default {@link javax.naming.Initia lContext}. | |||
* | * | |||
* @return the default JndiManager | * @return the default JndiManager | |||
*/ | */ | |||
public static JndiManager getDefaultManager() { | public static JndiManager getDefaultManager() { | |||
skipping to change at line 207 | skipping to change at line 216 | |||
if (context == null) { | if (context == null) { | |||
return null; | return null; | |||
} | } | |||
try { | try { | |||
URI uri = new URI(name); | URI uri = new URI(name); | |||
if (uri.getScheme() == null || uri.getScheme().equals(JAVA_SCHEME)) { | if (uri.getScheme() == null || uri.getScheme().equals(JAVA_SCHEME)) { | |||
return (T) this.context.lookup(name); | return (T) this.context.lookup(name); | |||
} | } | |||
LOGGER.warn("Unsupported JNDI URI - {}", name); | LOGGER.warn("Unsupported JNDI URI - {}", name); | |||
} catch (URISyntaxException ex) { | } catch (URISyntaxException ex) { | |||
LOGGER.warn("Invalid JNDI URI - {}", name); | LOGGER.warn("Invalid JNDI URI - {}", name); | |||
} | } | |||
return null; | return null; | |||
} | } | |||
private static class JndiManagerFactory implements ManagerFactory<JndiManage r, Properties> { | private static class JndiManagerFactory implements ManagerFactory<JndiManage r, Properties> { | |||
@Override | @Override | |||
public JndiManager createManager(final String name, final Properties dat a) { | public JndiManager createManager(final String name, final Properties dat a) { | |||
if (!isJndiEnabled()) { | if (!isJndiEnabled()) { | |||
throw new IllegalStateException(String.format("JNDI must be enab led by setting one of the %s* properties to true", PREFIX)); | throw new IllegalStateException(String.format("JNDI must be enab led by setting one of the %s* properties to true", PREFIX)); | |||
End of changes. 7 change blocks. | ||||
7 lines changed or deleted | 17 lines changed or added |