Example usage for org.apache.hadoop.security.authentication.server PseudoAuthenticationHandler ANONYMOUS_ALLOWED

List of usage examples for org.apache.hadoop.security.authentication.server PseudoAuthenticationHandler ANONYMOUS_ALLOWED

Introduction

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

Prototype

String ANONYMOUS_ALLOWED

To view the source code for org.apache.hadoop.security.authentication.server PseudoAuthenticationHandler ANONYMOUS_ALLOWED.

Click Source Link

Document

Constant for the configuration property that indicates if anonymous users are allowed.

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/* ww  w .  j a va 2s. 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;
}