HADOOP-16299. [JDK 11] Build fails without specifying -Djavac.version=11
Signed-off-by: Takanobu Asanuma <tasanuma@apache.org>
This commit is contained in:
parent
0c5fa2e7d9
commit
f257497b0f
@ -46,7 +46,6 @@
|
||||
import javax.naming.spi.InitialContextFactory;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.sun.jndi.ldap.LdapCtxFactory;
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.conf.Configurable;
|
||||
@ -270,8 +269,9 @@ public class LdapGroupsMapping
|
||||
|
||||
public static final String LDAP_CTX_FACTORY_CLASS_KEY =
|
||||
LDAP_CONFIG_PREFIX + ".ctx.factory.class";
|
||||
public static final Class<? extends LdapCtxFactory>
|
||||
LDAP_CTX_FACTORY_CLASS_DEFAULT = LdapCtxFactory.class;
|
||||
|
||||
public static final String LDAP_CTX_FACTORY_CLASS_DEFAULT =
|
||||
"com.sun.jndi.ldap.LdapCtxFactory";
|
||||
|
||||
private static final Logger LOG =
|
||||
LoggerFactory.getLogger(LdapGroupsMapping.class);
|
||||
@ -314,7 +314,7 @@ public class LdapGroupsMapping
|
||||
private boolean useOneQuery;
|
||||
private int numAttempts;
|
||||
private int numAttemptsBeforeFailover;
|
||||
private Class<? extends InitialContextFactory> ldapCxtFactoryClass;
|
||||
private String ldapCtxFactoryClassName;
|
||||
|
||||
/**
|
||||
* Returns list of groups for a user.
|
||||
@ -633,7 +633,7 @@ private DirContext getDirContext() throws NamingException {
|
||||
if (ctx == null) {
|
||||
// Set up the initial environment for LDAP connectivity
|
||||
Hashtable<String, String> env = new Hashtable<>();
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, ldapCxtFactoryClass.getName());
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, ldapCtxFactoryClassName);
|
||||
env.put(Context.PROVIDER_URL, currentLdapUrl);
|
||||
env.put(Context.SECURITY_AUTHENTICATION, "simple");
|
||||
|
||||
@ -755,8 +755,18 @@ public synchronized void setConf(Configuration conf) {
|
||||
}
|
||||
SEARCH_CONTROLS.setReturningAttributes(returningAttributes);
|
||||
|
||||
ldapCxtFactoryClass = conf.getClass(LDAP_CTX_FACTORY_CLASS_KEY,
|
||||
LDAP_CTX_FACTORY_CLASS_DEFAULT, InitialContextFactory.class);
|
||||
// LDAP_CTX_FACTORY_CLASS_DEFAULT is not open to unnamed modules
|
||||
// in Java 11+, so the default value is set to null to avoid
|
||||
// creating the instance for now.
|
||||
Class<? extends InitialContextFactory> ldapCtxFactoryClass =
|
||||
conf.getClass(LDAP_CTX_FACTORY_CLASS_KEY, null,
|
||||
InitialContextFactory.class);
|
||||
if (ldapCtxFactoryClass != null) {
|
||||
ldapCtxFactoryClassName = ldapCtxFactoryClass.getName();
|
||||
} else {
|
||||
// The default value is set afterwards.
|
||||
ldapCtxFactoryClassName = LDAP_CTX_FACTORY_CLASS_DEFAULT;
|
||||
}
|
||||
|
||||
this.numAttempts = conf.getInt(LDAP_NUM_ATTEMPTS_KEY,
|
||||
LDAP_NUM_ATTEMPTS_DEFAULT);
|
||||
|
@ -22,7 +22,6 @@
|
||||
import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_CTX_FACTORY_CLASS_KEY;
|
||||
import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_URL_KEY;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -36,6 +35,7 @@
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
import javax.naming.ldap.InitialLdapContext;
|
||||
import javax.naming.spi.InitialContextFactory;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
@ -235,13 +235,10 @@ public Context getInitialContext(Hashtable<?, ?> env)
|
||||
assertEquals(expectedBindPassword, actualBindPassword);
|
||||
}
|
||||
if (contextToReturn == null) {
|
||||
InitialContextFactory defaultFactory = null;
|
||||
try {
|
||||
defaultFactory = LDAP_CTX_FACTORY_CLASS_DEFAULT.newInstance();
|
||||
} catch (ReflectiveOperationException e) {
|
||||
fail("Could not initialize the default factory");
|
||||
}
|
||||
return defaultFactory.getInitialContext(env);
|
||||
Hashtable<Object, Object> newEnv = new Hashtable<>(env);
|
||||
newEnv.put(Context.INITIAL_CONTEXT_FACTORY,
|
||||
LDAP_CTX_FACTORY_CLASS_DEFAULT);
|
||||
contextToReturn = new InitialLdapContext(newEnv, null);
|
||||
}
|
||||
return contextToReturn;
|
||||
}
|
||||
|
@ -2070,21 +2070,9 @@
|
||||
<additionalOptions>
|
||||
<!-- TODO: remove -html4 option to generate html5 docs when we stop supporting JDK8 -->
|
||||
<additionalOption>-html4</additionalOption>
|
||||
<additionalOption>--add-exports</additionalOption>
|
||||
<additionalOption>java.naming/com.sun.jndi.ldap=ALL-UNNAMED</additionalOption>
|
||||
</additionalOptions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<compilerArgs combine.children="append">
|
||||
<arg>--add-exports</arg>
|
||||
<arg>java.naming/com.sun.jndi.ldap=ALL-UNNAMED</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
Loading…
Reference in New Issue
Block a user