mirror of
https://github.com/apache/sqoop.git
synced 2025-05-05 05:09:46 +08:00
SQOOP-2002: Sqoop2: Refactor existing security component
(Richard Zhou via Abraham Elmahrek)
This commit is contained in:
parent
f4beb543ee
commit
bca7671f85
@ -31,7 +31,7 @@ public class AuthenticationManager implements Reconfigurable {
|
|||||||
/**
|
/**
|
||||||
* Default authentication handler
|
* Default authentication handler
|
||||||
*/
|
*/
|
||||||
public static final String DEFAULT_AUTHENTICATION_HANDLER = "org.apache.sqoop.security.SimpleAuthenticationHandler";
|
public static final String DEFAULT_AUTHENTICATION_HANDLER = "org.apache.sqoop.security.Authentication.SimpleAuthenticationHandler";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,9 +92,9 @@ public synchronized void initialize() throws ClassNotFoundException, IllegalAcce
|
|||||||
}
|
}
|
||||||
|
|
||||||
String handler = SqoopConfiguration.getInstance().getContext().getString(
|
String handler = SqoopConfiguration.getInstance().getContext().getString(
|
||||||
AuthenticationConstants.AUTHENTICATION_HANDLER,
|
SecurityConstants.AUTHENTICATION_HANDLER,
|
||||||
DEFAULT_AUTHENTICATION_HANDLER).trim();
|
DEFAULT_AUTHENTICATION_HANDLER).trim();
|
||||||
authenticationHandler = AuthenticationHandlerFactory.getAuthenticationHandler(handler);
|
authenticationHandler = SecurityFactory.getAuthenticationHandler(handler);
|
||||||
authenticationHandler.doInitialize();
|
authenticationHandler.doInitialize();
|
||||||
authenticationHandler.secureLogin();
|
authenticationHandler.secureLogin();
|
||||||
|
|
||||||
|
@ -22,19 +22,24 @@
|
|||||||
/**
|
/**
|
||||||
* Constants that are used in authentication module.
|
* Constants that are used in authentication module.
|
||||||
*/
|
*/
|
||||||
public final class AuthenticationConstants {
|
public final class SecurityConstants {
|
||||||
|
/**
|
||||||
|
* All security related configuration is prefixed with this:
|
||||||
|
* <tt>org.apache.sqoop.security.</tt>
|
||||||
|
*/
|
||||||
|
public static final String PREFIX_SECURITY_CONFIG =
|
||||||
|
ConfigurationConstants.PREFIX_GLOBAL_CONFIG + "security.";
|
||||||
/**
|
/**
|
||||||
* All authentication related configuration is prefixed with this:
|
* All authentication related configuration is prefixed with this:
|
||||||
* <tt>org.apache.sqoop.authentication.</tt>
|
* <tt>org.apache.sqoop.security.authentication.</tt>
|
||||||
*/
|
*/
|
||||||
public static final String PREFIX_AUTHENTICATION_CONFIG =
|
public static final String PREFIX_AUTHENTICATION_CONFIG =
|
||||||
ConfigurationConstants.PREFIX_GLOBAL_CONFIG + "authentication.";
|
PREFIX_SECURITY_CONFIG + "authentication.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The config specifies the sqoop authentication type (SIMPLE, KERBEROS).
|
* The config specifies the sqoop authentication type (SIMPLE, KERBEROS).
|
||||||
* The default type is SIMPLE
|
* The default type is SIMPLE
|
||||||
* <tt>org.apache.sqoop.authentication.type</tt>.
|
* <tt>org.apache.sqoop.security.authentication.type</tt>.
|
||||||
*/
|
*/
|
||||||
public static final String AUTHENTICATION_TYPE =
|
public static final String AUTHENTICATION_TYPE =
|
||||||
PREFIX_AUTHENTICATION_CONFIG + "type";
|
PREFIX_AUTHENTICATION_CONFIG + "type";
|
||||||
@ -42,56 +47,56 @@ public final class AuthenticationConstants {
|
|||||||
/**
|
/**
|
||||||
* The config specifies the sqoop authentication handler class.
|
* The config specifies the sqoop authentication handler class.
|
||||||
* The default type is org.apache.sqoop.security.SimpleAuthenticationHandler
|
* The default type is org.apache.sqoop.security.SimpleAuthenticationHandler
|
||||||
* <tt>org.apache.sqoop.authentication.handler</tt>.
|
* <tt>org.apache.sqoop.security.authentication.handler</tt>.
|
||||||
*/
|
*/
|
||||||
public static final String AUTHENTICATION_HANDLER =
|
public static final String AUTHENTICATION_HANDLER =
|
||||||
PREFIX_AUTHENTICATION_CONFIG + "handler";
|
PREFIX_AUTHENTICATION_CONFIG + "handler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The config enables or disables anonymous authentication.
|
* The config enables or disables anonymous authentication.
|
||||||
* <tt>org.apache.sqoop.authentication.anonymous</tt>.
|
* <tt>org.apache.sqoop.security.authentication.anonymous</tt>.
|
||||||
*/
|
*/
|
||||||
public static final String AUTHENTICATION_ANONYMOUS =
|
public static final String AUTHENTICATION_ANONYMOUS =
|
||||||
PREFIX_AUTHENTICATION_CONFIG + "anonymous";
|
PREFIX_AUTHENTICATION_CONFIG + "anonymous";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All kerberos authentication related configuration is prefixed with this:
|
* All kerberos authentication related configuration is prefixed with this:
|
||||||
* <tt>org.apache.sqoop.authentication.kerberos.</tt>
|
* <tt>org.apache.security.sqoop.authentication.kerberos.</tt>
|
||||||
*/
|
*/
|
||||||
public static final String PREFIX_AUTHENTICATION_KERBEROS_CONFIG =
|
public static final String PREFIX_AUTHENTICATION_KERBEROS_CONFIG =
|
||||||
PREFIX_AUTHENTICATION_CONFIG + "kerberos.";
|
PREFIX_AUTHENTICATION_CONFIG + "kerberos.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The config specifies the kerberos principal.
|
* The config specifies the kerberos principal.
|
||||||
* <tt>org.apache.sqoop.authentication.kerberos.principal</tt>.
|
* <tt>org.apache.sqoop.security.authentication.kerberos.principal</tt>.
|
||||||
*/
|
*/
|
||||||
public static final String AUTHENTICATION_KERBEROS_PRINCIPAL =
|
public static final String AUTHENTICATION_KERBEROS_PRINCIPAL =
|
||||||
PREFIX_AUTHENTICATION_KERBEROS_CONFIG + "principal";
|
PREFIX_AUTHENTICATION_KERBEROS_CONFIG + "principal";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The config specifies the kerberos keytab.
|
* The config specifies the kerberos keytab.
|
||||||
* <tt>org.apache.sqoop.authentication.kerberos.principal</tt>.
|
* <tt>org.apache.sqoop.security.authentication.kerberos.principal</tt>.
|
||||||
*/
|
*/
|
||||||
public static final String AUTHENTICATION_KERBEROS_KEYTAB =
|
public static final String AUTHENTICATION_KERBEROS_KEYTAB =
|
||||||
PREFIX_AUTHENTICATION_KERBEROS_CONFIG + "keytab";
|
PREFIX_AUTHENTICATION_KERBEROS_CONFIG + "keytab";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All kerberos authentication for http related configuration is prefixed with this:
|
* All kerberos authentication for http related configuration is prefixed with this:
|
||||||
* <tt>org.apache.sqoop.authentication.kerberos.http.</tt>
|
* <tt>org.apache.sqoop.security.authentication.kerberos.http.</tt>
|
||||||
*/
|
*/
|
||||||
public static final String PREFIX_AUTHENTICATION_KERBEROS_HTTP_CONFIG =
|
public static final String PREFIX_AUTHENTICATION_KERBEROS_HTTP_CONFIG =
|
||||||
PREFIX_AUTHENTICATION_KERBEROS_CONFIG + "http.";
|
PREFIX_AUTHENTICATION_KERBEROS_CONFIG + "http.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The config specifies the kerberos principal for http.
|
* The config specifies the kerberos principal for http.
|
||||||
* <tt>org.apache.sqoop.authentication.kerberos.http.principal</tt>.
|
* <tt>org.apache.sqoop.security.authentication.kerberos.http.principal</tt>.
|
||||||
*/
|
*/
|
||||||
public static final String AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL =
|
public static final String AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL =
|
||||||
PREFIX_AUTHENTICATION_KERBEROS_HTTP_CONFIG + "principal";
|
PREFIX_AUTHENTICATION_KERBEROS_HTTP_CONFIG + "principal";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The config specifies the kerberos keytab for http.
|
* The config specifies the kerberos keytab for http.
|
||||||
* <tt>org.apache.sqoop.authentication.kerberos.http.principal</tt>.
|
* <tt>org.apache.sqoop.security.authentication.kerberos.http.principal</tt>.
|
||||||
*/
|
*/
|
||||||
public static final String AUTHENTICATION_KERBEROS_HTTP_KEYTAB =
|
public static final String AUTHENTICATION_KERBEROS_HTTP_KEYTAB =
|
||||||
PREFIX_AUTHENTICATION_KERBEROS_HTTP_CONFIG + "keytab";
|
PREFIX_AUTHENTICATION_KERBEROS_HTTP_CONFIG + "keytab";
|
||||||
@ -103,7 +108,7 @@ public final class AuthenticationConstants {
|
|||||||
|
|
||||||
public static enum TYPE {SIMPLE, KERBEROS}
|
public static enum TYPE {SIMPLE, KERBEROS}
|
||||||
|
|
||||||
private AuthenticationConstants() {
|
private SecurityConstants() {
|
||||||
// Instantiation of this class is prohibited
|
// Instantiation of this class is prohibited
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
import org.apache.sqoop.common.ErrorCode;
|
import org.apache.sqoop.common.ErrorCode;
|
||||||
|
|
||||||
public enum AuthenticationError implements ErrorCode {
|
public enum SecurityError implements ErrorCode {
|
||||||
|
|
||||||
/** An unknown error has occurred. */
|
/** An unknown error has occurred. */
|
||||||
AUTH_0000("An unknown error has occurred"),
|
AUTH_0000("An unknown error has occurred"),
|
||||||
@ -44,7 +44,7 @@ public enum AuthenticationError implements ErrorCode {
|
|||||||
|
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
private AuthenticationError(String message) {
|
private SecurityError(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
@ -23,14 +23,14 @@
|
|||||||
/**
|
/**
|
||||||
* Create authentication manager.
|
* Create authentication manager.
|
||||||
*/
|
*/
|
||||||
public class AuthenticationHandlerFactory {
|
public class SecurityFactory {
|
||||||
|
|
||||||
public static AuthenticationHandler getAuthenticationHandler(String handler) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
public static AuthenticationHandler getAuthenticationHandler(String handler) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||||
|
|
||||||
Class<?> handlerClass = ClassUtils.loadClass(handler);
|
Class<?> handlerClass = ClassUtils.loadClass(handler);
|
||||||
|
|
||||||
if (handlerClass == null) {
|
if (handlerClass == null) {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0004,
|
throw new SqoopException(SecurityError.AUTH_0004,
|
||||||
"Authentication Handler Class: " + handler);
|
"Authentication Handler Class: " + handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ public static AuthenticationHandler getAuthenticationHandler(String handler) thr
|
|||||||
try {
|
try {
|
||||||
newHandler = (AuthenticationHandler) handlerClass.newInstance();
|
newHandler = (AuthenticationHandler) handlerClass.newInstance();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0004,
|
throw new SqoopException(SecurityError.AUTH_0004,
|
||||||
"Authentication Handler Class: " + handler, ex);
|
"Authentication Handler Class: " + handler, ex);
|
||||||
}
|
}
|
||||||
return newHandler;
|
return newHandler;
|
26
dist/src/main/server/conf/sqoop.properties
vendored
26
dist/src/main/server/conf/sqoop.properties
vendored
@ -144,16 +144,16 @@ org.apache.sqoop.execution.engine=org.apache.sqoop.execution.mapreduce.Mapreduce
|
|||||||
#
|
#
|
||||||
# Authentication configuration
|
# Authentication configuration
|
||||||
#
|
#
|
||||||
#org.apache.sqoop.authentication.type=SIMPLE
|
#org.apache.sqoop.security.authentication.type=SIMPLE
|
||||||
#org.apache.sqoop.authentication.handler=org.apache.sqoop.security.SimpleAuthenticationHandler
|
#org.apache.sqoop.security.authentication.handler=org.apache.sqoop.security.Authentication.SimpleAuthenticationHandler
|
||||||
#org.apache.sqoop.authentication.anonymous=true
|
#org.apache.sqoop.security.authentication.anonymous=true
|
||||||
#org.apache.sqoop.authentication.type=KERBEROS
|
#org.apache.sqoop.security.authentication.type=KERBEROS
|
||||||
#org.apache.sqoop.authentication.handler=org.apache.sqoop.security.KerberosAuthenticationHandler
|
#org.apache.sqoop.security.authentication.handler=org.apache.sqoop.security.Authentication.KerberosAuthenticationHandler
|
||||||
#org.apache.sqoop.authentication.kerberos.principal=sqoop/_HOST@NOVALOCAL
|
#org.apache.sqoop.security.authentication.kerberos.principal=sqoop/_HOST@NOVALOCAL
|
||||||
#org.apache.sqoop.authentication.kerberos.keytab=/home/kerberos/sqoop.keytab
|
#org.apache.sqoop.security.authentication.kerberos.keytab=/home/kerberos/sqoop.keytab
|
||||||
#org.apache.sqoop.authentication.kerberos.http.principal=HTTP/_HOST@NOVALOCAL
|
#org.apache.sqoop.security.authentication.kerberos.http.principal=HTTP/_HOST@NOVALOCAL
|
||||||
#org.apache.sqoop.authentication.kerberos.http.keytab=/home/kerberos/sqoop.keytab
|
#org.apache.sqoop.security.authentication.kerberos.http.keytab=/home/kerberos/sqoop.keytab
|
||||||
#org.apache.sqoop.authentication.enable.doAs=true
|
#org.apache.sqoop.security.authentication.enable.doAs=true
|
||||||
#org.apache.sqoop.authentication.proxyuser.#USER#.users=*
|
#org.apache.sqoop.security.authentication.proxyuser.#USER#.users=*
|
||||||
#org.apache.sqoop.authentication.proxyuser.#USER#.groups=*
|
#org.apache.sqoop.security.authentication.proxyuser.#USER#.groups=*
|
||||||
#org.apache.sqoop.authentication.proxyuser.#USER#.hosts=*
|
#org.apache.sqoop.security.authentication.proxyuser.#USER#.hosts=*
|
@ -30,7 +30,7 @@ Modify Sqoop configuration file, normally in <Sqoop Folder>/server/config/sqoop.
|
|||||||
::
|
::
|
||||||
|
|
||||||
org.apache.sqoop.authentication.type=SIMPLE
|
org.apache.sqoop.authentication.type=SIMPLE
|
||||||
org.apache.sqoop.authentication.handler=org.apache.sqoop.security.SimpleAuthenticationHandler
|
org.apache.sqoop.authentication.handler=org.apache.sqoop.security.Authentication.SimpleAuthenticationHandler
|
||||||
org.apache.sqoop.anonymous=true
|
org.apache.sqoop.anonymous=true
|
||||||
|
|
||||||
- Simple authentication is used by default. Commenting out authentication configuration will yield the use of simple authentication.
|
- Simple authentication is used by default. Commenting out authentication configuration will yield the use of simple authentication.
|
||||||
@ -88,7 +88,7 @@ Modify Sqoop configuration file, normally in <Sqoop Folder>/server/config/sqoop.
|
|||||||
::
|
::
|
||||||
|
|
||||||
org.apache.sqoop.authentication.type=KERBEROS
|
org.apache.sqoop.authentication.type=KERBEROS
|
||||||
org.apache.sqoop.authentication.handler=org.apache.sqoop.security.KerberosAuthenticationHandler
|
org.apache.sqoop.authentication.handler=org.apache.sqoop.security.Authentication.KerberosAuthenticationHandler
|
||||||
org.apache.sqoop.authentication.kerberos.principal=sqoop/_HOST@<REALM>
|
org.apache.sqoop.authentication.kerberos.principal=sqoop/_HOST@<REALM>
|
||||||
org.apache.sqoop.authentication.kerberos.keytab=/home/kerberos/sqoop.keytab
|
org.apache.sqoop.authentication.kerberos.keytab=/home/kerberos/sqoop.keytab
|
||||||
org.apache.sqoop.authentication.kerberos.http.principal=HTTP/_HOST@<REALM>
|
org.apache.sqoop.authentication.kerberos.http.principal=HTTP/_HOST@<REALM>
|
||||||
@ -132,7 +132,7 @@ If the Sqoop server has started successfully with Kerberos authentication, the f
|
|||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
2014-12-04 15:02:58,038 INFO security.KerberosAuthenticationHandler [org.apache.sqoop.security.KerberosAuthenticationHandler.secureLogin(KerberosAuthenticationHandler.java:84)] Using Kerberos authentication, principal [sqoop/_HOST@HADOOP.COM] keytab [/home/kerberos/sqoop.keytab]
|
2014-12-04 15:02:58,038 INFO security.KerberosAuthenticationHandler [org.apache.sqoop.security.Authentication.KerberosAuthenticationHandler.secureLogin(KerberosAuthenticationHandler.java:84)] Using Kerberos authentication, principal [sqoop/_HOST@HADOOP.COM] keytab [/home/kerberos/sqoop.keytab]
|
||||||
|
|
||||||
If the Sqoop client was able to communicate with the Sqoop server, the following will be in <Sqoop Folder>/server/log/catalina.out:
|
If the Sqoop client was able to communicate with the Sqoop server, the following will be in <Sqoop Folder>/server/log/catalina.out:
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.apache.sqoop.security;
|
package org.apache.sqoop.security.Authentication;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.security.SecurityUtil;
|
import org.apache.hadoop.security.SecurityUtil;
|
||||||
@ -24,6 +24,9 @@
|
|||||||
import org.apache.sqoop.common.MapContext;
|
import org.apache.sqoop.common.MapContext;
|
||||||
import org.apache.sqoop.common.SqoopException;
|
import org.apache.sqoop.common.SqoopException;
|
||||||
import org.apache.sqoop.core.SqoopConfiguration;
|
import org.apache.sqoop.core.SqoopConfiguration;
|
||||||
|
import org.apache.sqoop.security.AuthenticationHandler;
|
||||||
|
import org.apache.sqoop.security.SecurityConstants;
|
||||||
|
import org.apache.sqoop.security.SecurityError;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -56,30 +59,30 @@ public void doInitialize() {
|
|||||||
public void secureLogin() {
|
public void secureLogin() {
|
||||||
MapContext mapContext = SqoopConfiguration.getInstance().getContext();
|
MapContext mapContext = SqoopConfiguration.getInstance().getContext();
|
||||||
String keytab = mapContext.getString(
|
String keytab = mapContext.getString(
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_KEYTAB).trim();
|
SecurityConstants.AUTHENTICATION_KERBEROS_KEYTAB).trim();
|
||||||
if (keytab.length() == 0) {
|
if (keytab.length() == 0) {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0001,
|
throw new SqoopException(SecurityError.AUTH_0001,
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_KEYTAB);
|
SecurityConstants.AUTHENTICATION_KERBEROS_KEYTAB);
|
||||||
}
|
}
|
||||||
keytabFile = keytab;
|
keytabFile = keytab;
|
||||||
|
|
||||||
String principal = mapContext.getString(
|
String principal = mapContext.getString(
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_PRINCIPAL).trim();
|
SecurityConstants.AUTHENTICATION_KERBEROS_PRINCIPAL).trim();
|
||||||
if (principal.length() == 0) {
|
if (principal.length() == 0) {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0002,
|
throw new SqoopException(SecurityError.AUTH_0002,
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_PRINCIPAL);
|
SecurityConstants.AUTHENTICATION_KERBEROS_PRINCIPAL);
|
||||||
}
|
}
|
||||||
keytabPrincipal = principal;
|
keytabPrincipal = principal;
|
||||||
|
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.set(get_hadoop_security_authentication(),
|
conf.set(get_hadoop_security_authentication(),
|
||||||
AuthenticationConstants.TYPE.KERBEROS.name());
|
SecurityConstants.TYPE.KERBEROS.name());
|
||||||
UserGroupInformation.setConfiguration(conf);
|
UserGroupInformation.setConfiguration(conf);
|
||||||
try {
|
try {
|
||||||
String hostPrincipal = SecurityUtil.getServerPrincipal(principal, "0.0.0.0");
|
String hostPrincipal = SecurityUtil.getServerPrincipal(principal, "0.0.0.0");
|
||||||
UserGroupInformation.loginUserFromKeytab(hostPrincipal, keytab);
|
UserGroupInformation.loginUserFromKeytab(hostPrincipal, keytab);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0003, ex);
|
throw new SqoopException(SecurityError.AUTH_0003, ex);
|
||||||
}
|
}
|
||||||
LOG.info("Using Kerberos authentication, principal ["
|
LOG.info("Using Kerberos authentication, principal ["
|
||||||
+ principal + "] keytab [" + keytab + "]");
|
+ principal + "] keytab [" + keytab + "]");
|
@ -15,11 +15,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.apache.sqoop.security;
|
package org.apache.sqoop.security.Authentication;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.sqoop.security.AuthenticationHandler;
|
||||||
|
import org.apache.sqoop.security.SecurityConstants;
|
||||||
|
|
||||||
public class SimpleAuthenticationHandler extends AuthenticationHandler {
|
public class SimpleAuthenticationHandler extends AuthenticationHandler {
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ public void secureLogin() {
|
|||||||
//no secureLogin, just set configurations
|
//no secureLogin, just set configurations
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.set(get_hadoop_security_authentication(),
|
conf.set(get_hadoop_security_authentication(),
|
||||||
AuthenticationConstants.TYPE.SIMPLE.name());
|
SecurityConstants.TYPE.SIMPLE.name());
|
||||||
UserGroupInformation.setConfiguration(conf);
|
UserGroupInformation.setConfiguration(conf);
|
||||||
LOG.info("Using simple/pseudo authentication, principal ["
|
LOG.info("Using simple/pseudo authentication, principal ["
|
||||||
+ System.getProperty("user.name") + "]");
|
+ System.getProperty("user.name") + "]");
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.security.SecurityUtil;
|
import org.apache.hadoop.security.SecurityUtil;
|
||||||
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
|
|
||||||
import org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler;
|
import org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler;
|
||||||
import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler;
|
import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler;
|
||||||
import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter;
|
import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter;
|
||||||
@ -29,8 +28,8 @@
|
|||||||
import org.apache.sqoop.common.MapContext;
|
import org.apache.sqoop.common.MapContext;
|
||||||
import org.apache.sqoop.common.SqoopException;
|
import org.apache.sqoop.common.SqoopException;
|
||||||
import org.apache.sqoop.core.SqoopConfiguration;
|
import org.apache.sqoop.core.SqoopConfiguration;
|
||||||
import org.apache.sqoop.security.AuthenticationConstants;
|
import org.apache.sqoop.security.SecurityConstants;
|
||||||
import org.apache.sqoop.security.AuthenticationError;
|
import org.apache.sqoop.security.SecurityError;
|
||||||
|
|
||||||
import javax.servlet.FilterConfig;
|
import javax.servlet.FilterConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
@ -46,46 +45,46 @@ protected Properties getConfiguration(String configPrefix,
|
|||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
MapContext mapContext = SqoopConfiguration.getInstance().getContext();
|
MapContext mapContext = SqoopConfiguration.getInstance().getContext();
|
||||||
String type = mapContext.getString(
|
String type = mapContext.getString(
|
||||||
AuthenticationConstants.AUTHENTICATION_TYPE,
|
SecurityConstants.AUTHENTICATION_TYPE,
|
||||||
AuthenticationConstants.TYPE.SIMPLE.name()).trim();
|
SecurityConstants.TYPE.SIMPLE.name()).trim();
|
||||||
|
|
||||||
if (type.equalsIgnoreCase(AuthenticationConstants.TYPE.KERBEROS.name())) {
|
if (type.equalsIgnoreCase(SecurityConstants.TYPE.KERBEROS.name())) {
|
||||||
properties.setProperty(AUTH_TYPE, KerberosDelegationTokenAuthenticationHandler.class.getName());
|
properties.setProperty(AUTH_TYPE, KerberosDelegationTokenAuthenticationHandler.class.getName());
|
||||||
|
|
||||||
String keytab = mapContext.getString(
|
String keytab = mapContext.getString(
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_HTTP_KEYTAB).trim();
|
SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_KEYTAB).trim();
|
||||||
if (keytab.length() == 0) {
|
if (keytab.length() == 0) {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0005,
|
throw new SqoopException(SecurityError.AUTH_0005,
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_HTTP_KEYTAB);
|
SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_KEYTAB);
|
||||||
}
|
}
|
||||||
|
|
||||||
String principal = mapContext.getString(
|
String principal = mapContext.getString(
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL).trim();
|
SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL).trim();
|
||||||
if (principal.length() == 0) {
|
if (principal.length() == 0) {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0006,
|
throw new SqoopException(SecurityError.AUTH_0006,
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL);
|
SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
String hostPrincipal = "";
|
String hostPrincipal = "";
|
||||||
try {
|
try {
|
||||||
hostPrincipal = SecurityUtil.getServerPrincipal(principal, "0.0.0.0");
|
hostPrincipal = SecurityUtil.getServerPrincipal(principal, "0.0.0.0");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0006,
|
throw new SqoopException(SecurityError.AUTH_0006,
|
||||||
AuthenticationConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL);
|
SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
properties.setProperty(KerberosAuthenticationHandler.PRINCIPAL, hostPrincipal);
|
properties.setProperty(KerberosAuthenticationHandler.PRINCIPAL, hostPrincipal);
|
||||||
properties.setProperty(KerberosAuthenticationHandler.KEYTAB, keytab);
|
properties.setProperty(KerberosAuthenticationHandler.KEYTAB, keytab);
|
||||||
} else if (type.equalsIgnoreCase(AuthenticationConstants.TYPE.SIMPLE.name())) {
|
} else if (type.equalsIgnoreCase(SecurityConstants.TYPE.SIMPLE.name())) {
|
||||||
properties.setProperty(AUTH_TYPE, PseudoDelegationTokenAuthenticationHandler.class.getName());
|
properties.setProperty(AUTH_TYPE, PseudoDelegationTokenAuthenticationHandler.class.getName());
|
||||||
properties.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED,
|
properties.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED,
|
||||||
mapContext.getString(AuthenticationConstants.AUTHENTICATION_ANONYMOUS, "true").trim());
|
mapContext.getString(SecurityConstants.AUTHENTICATION_ANONYMOUS, "true").trim());
|
||||||
} else {
|
} else {
|
||||||
throw new SqoopException(AuthenticationError.AUTH_0004, type);
|
throw new SqoopException(SecurityError.AUTH_0004, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
properties.setProperty(DelegationTokenAuthenticationHandler.TOKEN_KIND,
|
properties.setProperty(DelegationTokenAuthenticationHandler.TOKEN_KIND,
|
||||||
AuthenticationConstants.TOKEN_KIND);
|
SecurityConstants.TOKEN_KIND);
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user