Example usage for org.apache.zookeeper.server.auth KerberosName getShortName

List of usage examples for org.apache.zookeeper.server.auth KerberosName getShortName

Introduction

In this page you can find the example usage for org.apache.zookeeper.server.auth KerberosName getShortName.

Prototype

public String getShortName() throws IOException 

Source Link

Document

Get the translation of the principal name into an operating system user name.

Usage

From source file:com.lami.tuomatuo.mq.zookeeper.server.auth.SaslServerCallbackHandler.java

License:Apache License

private void handleAuthorizeCallback(AuthorizeCallback ac) {
    String authenticationID = ac.getAuthenticationID();
    String authorizationID = ac.getAuthorizationID();

    LOG.info("Successfully authenticated client: authenticationID=" + authenticationID + ";  authorizationID="
            + authorizationID + ".");
    ac.setAuthorized(true);/*from  ww  w .j a  va  2 s .  com*/

    // canonicalize authorization id according to system properties:
    // zookeeper.kerberos.removeRealmFromPrincipal(={true,false})
    // zookeeper.kerberos.removeHostFromPrincipal(={true,false})
    KerberosName kerberosName = new KerberosName(authenticationID);
    try {
        StringBuilder userNameBuilder = new StringBuilder(kerberosName.getShortName());
        if (shouldAppendHost(kerberosName)) {
            userNameBuilder.append("/").append(kerberosName.getHostName());
        }
        if (shouldAppendRealm(kerberosName)) {
            userNameBuilder.append("@").append(kerberosName.getRealm());
        }
        LOG.info("Setting authorizedID: " + userNameBuilder);
        ac.setAuthorizedID(userNameBuilder.toString());
    } catch (IOException e) {
        LOG.error("Failed to set name based on Kerberos authentication rules.");
    }
}