@zjffdu review comments

This commit is contained in:
Prabhjyot Singh 2017-07-05 13:54:32 +05:30
parent 7f8b8672b6
commit 7fe883c3e9
4 changed files with 27 additions and 69 deletions

View file

@ -151,13 +151,10 @@ public class JDBCInterpreter extends KerberosInterpreter {
@Override
protected boolean runKerberosLogin() {
try {
UserGroupInformation.AuthenticationMethod authType = JDBCSecurityImpl.getAuthtype(property);
if (authType.equals(KERBEROS)) {
if (UserGroupInformation.isLoginKeytabBased()) {
UserGroupInformation.getLoginUser().reloginFromKeytab();
} else if (UserGroupInformation.isLoginTicketBased()) {
UserGroupInformation.getLoginUser().reloginFromTicketCache();
}
if (UserGroupInformation.isLoginKeytabBased()) {
UserGroupInformation.getLoginUser().reloginFromKeytab();
} else if (UserGroupInformation.isLoginTicketBased()) {
UserGroupInformation.getLoginUser().reloginFromTicketCache();
}
} catch (Exception e) {
logger.error("Unable to run kinit for zeppelin", e);

View file

@ -31,13 +31,13 @@ import org.apache.commons.exec.ExecuteWatchdog;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.lang3.StringUtils;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.KerberosInterpreter;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.scheduler.SchedulerFactory;
import org.apache.zeppelin.shell.security.ShellSecurityImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -160,7 +160,7 @@ public class ShellInterpreter extends KerberosInterpreter {
@Override
protected boolean runKerberosLogin() {
try {
ShellSecurityImpl.createSecureConfiguration(getProperty(), shell);
createSecureConfiguration();
} catch (Exception e) {
LOGGER.error("Unable to run kinit for zeppelin", e);
return false;
@ -168,6 +168,23 @@ public class ShellInterpreter extends KerberosInterpreter {
return true;
}
public void createSecureConfiguration() {
Properties properties = getProperty();
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 {
executor.execute(cmdLine);
} catch (Exception e) {
LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e);
throw new InterpreterException(e);
}
}
@Override
protected boolean isKerboseEnabled() {
if (!StringUtils.isAnyEmpty(getProperty("zeppelin.shell.auth.type")) && getProperty(

View file

@ -1,59 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.zeppelin.shell.security;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.zeppelin.interpreter.InterpreterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
/***
* Shell security helper
*/
public class ShellSecurityImpl {
private static Logger LOGGER = LoggerFactory.getLogger(ShellSecurityImpl.class);
public static void createSecureConfiguration(Properties properties, String shell) {
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();
try {
int exitVal = executor.execute(cmdLine);
} catch (Exception e) {
LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e);
throw new InterpreterException(e);
}
}
}
}

View file

@ -31,7 +31,10 @@ import org.slf4j.LoggerFactory;
/**
* Interpreter wrapper for Kerberos initialization
*
* runKerberosLogin() method you need to implement that determine Zeppelin's behavior.
* runKerberosLogin() method you need to implement that determine how should this interpeter do a
* kinit for this interpreter.
* isKerboseEnabled() method needs to implement which determines if the kerberos is enabled for that
* interpreter.
* startKerberosLoginThread() needs to be called inside the open() and
* shutdownExecutorService() inside close().
*/