Example usage for org.apache.hadoop.security.authentication.server KerberosAuthenticationHandler KEYTAB

List of usage examples for org.apache.hadoop.security.authentication.server KerberosAuthenticationHandler KEYTAB

Introduction

In this page you can find the example usage for org.apache.hadoop.security.authentication.server KerberosAuthenticationHandler KEYTAB.

Prototype

String KEYTAB

To view the source code for org.apache.hadoop.security.authentication.server KerberosAuthenticationHandler KEYTAB.

Click Source Link

Document

Constant for the configuration property that indicates the keytab file path.

Usage

From source file:org.apache.sqoop.filter.SqoopAuthenticationFilter.java

License:Apache License

@Override
protected Properties getConfiguration(String configPrefix, FilterConfig filterConfig) throws ServletException {
    Properties properties = new Properties();
    MapContext mapContext = SqoopConfiguration.getInstance().getContext();
    String type = mapContext//from   w ww  . j ava2 s.c  o m
            .getString(SecurityConstants.AUTHENTICATION_TYPE, SecurityConstants.TYPE.SIMPLE.name()).trim();

    if (type.equalsIgnoreCase(SecurityConstants.TYPE.KERBEROS.name())) {
        properties.setProperty(AUTH_TYPE, KerberosDelegationTokenAuthenticationHandler.class.getName());

        String keytab = mapContext.getString(SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_KEYTAB).trim();
        if (keytab.length() == 0) {
            throw new SqoopException(SecurityError.AUTH_0005,
                    SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_KEYTAB);
        }

        String principal = mapContext.getString(SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL)
                .trim();
        if (principal.length() == 0) {
            throw new SqoopException(SecurityError.AUTH_0006,
                    SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL);
        }

        String hostPrincipal = "";
        try {
            hostPrincipal = SecurityUtil.getServerPrincipal(principal, "0.0.0.0");
        } catch (IOException e) {
            throw new SqoopException(SecurityError.AUTH_0006,
                    SecurityConstants.AUTHENTICATION_KERBEROS_HTTP_PRINCIPAL);
        }

        properties.setProperty(KerberosAuthenticationHandler.PRINCIPAL, hostPrincipal);
        properties.setProperty(KerberosAuthenticationHandler.KEYTAB, keytab);
    } else if (type.equalsIgnoreCase(SecurityConstants.TYPE.SIMPLE.name())) {
        properties.setProperty(AUTH_TYPE, PseudoDelegationTokenAuthenticationHandler.class.getName());
        properties.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED,
                mapContext.getString(SecurityConstants.AUTHENTICATION_ANONYMOUS, "true").trim());
    } else {
        throw new SqoopException(SecurityError.AUTH_0004, type);
    }

    properties.setProperty(DelegationTokenAuthenticationHandler.TOKEN_KIND, SecurityConstants.TOKEN_KIND);

    return properties;
}