Removed Hadoop common dependency and changed switch to String based Kerberos/Simple.

This commit is contained in:
Rohit Choudhary 2016-07-12 15:48:47 +05:30
parent 60e6d21b5b
commit 9143b47751
2 changed files with 16 additions and 34 deletions

View file

@ -62,12 +62,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
<build>

View file

@ -19,16 +19,12 @@ package org.apache.zeppelin.shell.security;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.zeppelin.interpreter.InterpreterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.SIMPLE;
/***
* Shell security helper
@ -38,34 +34,26 @@ public class ShellSecurityImpl {
private static Logger LOGGER = LoggerFactory.getLogger(ShellSecurityImpl.class);
public static void createSecureCinfiguration(Properties properties, String shell) {
UserGroupInformation.AuthenticationMethod authType;
try {
authType = UserGroupInformation
.AuthenticationMethod.valueOf(properties.getProperty("zeppelin.shell.auth.type")
.trim().toUpperCase());
} catch (Exception e) {
LOGGER.error(String.format("Invalid auth.type detected with value %s, defaulting " +
"auth.type to SIMPLE", properties.getProperty("zeppelin.shell.auth.type").trim()));
authType = SIMPLE;
}
String authType = properties.getProperty("zeppelin.shell.auth.type")
.trim().toUpperCase();
switch (authType) {
case KERBEROS:
CommandLine cmdLine = CommandLine.parse(shell);
cmdLine.addArgument("-c", false);
String kinitCommand = String.format("kinit -k -t %s %s",
properties.getProperty("zeppelin.shell.keytab.location"),
properties.getProperty("zeppelin.shell.principal"));
cmdLine.addArgument(kinitCommand, false);
DefaultExecutor executor = new DefaultExecutor();
case "KERBEROS":
CommandLine cmdLine = CommandLine.parse(shell);
cmdLine.addArgument("-c", false);
String kinitCommand = String.format("kinit -k -t %s %s",
properties.getProperty("zeppelin.shell.keytab.location"),
properties.getProperty("zeppelin.shell.principal"));
cmdLine.addArgument(kinitCommand, false);
DefaultExecutor executor = new DefaultExecutor();
try {
int exitVal = executor.execute(cmdLine);
} catch (Exception e) {
LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e);
throw new InterpreterException(e);
}
try {
int exitVal = executor.execute(cmdLine);
} catch (Exception e) {
LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e);
throw new InterpreterException(e);
}
}
}
}