Example usage for org.apache.zookeeper.server ServerCnxn getAuthInfo

List of usage examples for org.apache.zookeeper.server ServerCnxn getAuthInfo

Introduction

In this page you can find the example usage for org.apache.zookeeper.server ServerCnxn getAuthInfo.

Prototype

public List<Id> getAuthInfo() 

Source Link

Document

auth info for the cnxn, returns an unmodifyable list

Usage

From source file:org.talend.esb.locator.server.auth.SLAuthenticationProvider.java

License:Apache License

@Override
public Code handleAuthentication(ServerCnxn cnxn, byte[] authData) {

    String id = new String(authData, utf8CharSet);
    String userInfo[] = id.split(":");
    String user = "";
    String password = "";
    StringBuilder roles = new StringBuilder("");

    if (userInfo.length >= 1) {
        user = userInfo[0];/*from ww w.  j  av a 2 s .  c  o m*/
        if (userInfo.length >= 2) {
            password = userInfo[1];
        }
        try {

            ArrayList<String> rolesList = getUserRoles(user, password);
            int size = rolesList.size();

            for (int i = 0; i < size; i++) {
                roles.append(rolesList.get(i));
                if (i < size - 1)
                    roles.append(",");
            }

            if (size >= 1) {
                cnxn.getAuthInfo().add(new Id(getScheme(), roles.toString()));
                return KeeperException.Code.OK;
            }

        } catch (LoginException e) {
            if (LOG.isLoggable(Level.WARNING)) {
                LOG.log(Level.WARNING, "Login failed");
            }
        }
    }
    return KeeperException.Code.AUTHFAILED;
}