Example usage for org.apache.hadoop.security.authentication.util KerberosName getServiceName

List of usage examples for org.apache.hadoop.security.authentication.util KerberosName getServiceName

Introduction

In this page you can find the example usage for org.apache.hadoop.security.authentication.util KerberosName getServiceName.

Prototype

public String getServiceName() 

Source Link

Document

Get the first component of the name.

Usage

From source file:org.apache.accumulo.core.client.impl.ClientConfConverter.java

License:Apache License

@SuppressWarnings("deprecation")
public static org.apache.accumulo.core.client.ClientConfiguration toClientConf(AccumuloConfiguration conf) {
    org.apache.accumulo.core.client.ClientConfiguration clientConf = org.apache.accumulo.core.client.ClientConfiguration
            .create();//from  w w w.j av a  2 s.  co  m

    // Servers will only have the full principal in their configuration -- parse the
    // primary and realm from it.
    final String serverPrincipal = conf.get(Property.GENERAL_KERBEROS_PRINCIPAL);

    final KerberosName krbName;
    if (serverPrincipal != null && !serverPrincipal.isEmpty()) {
        krbName = new KerberosName(serverPrincipal);
        clientConf.setProperty(
                org.apache.accumulo.core.client.ClientConfiguration.ClientProperty.KERBEROS_SERVER_PRIMARY,
                krbName.getServiceName());
    }

    HashSet<String> clientKeys = new HashSet<>();
    for (org.apache.accumulo.core.client.ClientConfiguration.ClientProperty prop : org.apache.accumulo.core.client.ClientConfiguration.ClientProperty
            .values()) {
        clientKeys.add(prop.getKey());
    }

    String key;
    for (Map.Entry<String, String> entry : conf) {
        key = entry.getKey();
        if (clientKeys.contains(key)) {
            clientConf.setProperty(key, entry.getValue());
        }
    }
    return clientConf;
}

From source file:org.apache.accumulo.core.rpc.SaslConnectionParams.java

License:Apache License

protected static Map<String, String> getProperties(AccumuloConfiguration conf) {
    final Map<String, String> clientProperties = new HashMap<>();

    // Servers will only have the full principal in their configuration -- parse the
    // primary and realm from it.
    final String serverPrincipal = conf.get(Property.GENERAL_KERBEROS_PRINCIPAL);

    final KerberosName krbName;
    try {//www . j av a  2  s .c  om
        krbName = new KerberosName(serverPrincipal);
        clientProperties.put(ClientProperty.KERBEROS_SERVER_PRIMARY.getKey(), krbName.getServiceName());
    } catch (Exception e) {
        // bad value or empty, assume we're not using kerberos
    }

    HashSet<String> clientKeys = new HashSet<>();
    for (ClientProperty prop : ClientProperty.values()) {
        clientKeys.add(prop.getKey());
    }

    String key;
    for (Entry<String, String> entry : conf) {
        key = entry.getKey();
        if (clientKeys.contains(key)) {
            clientProperties.put(key, entry.getValue());
        }
    }

    return clientProperties;
}