Example usage for javax.security.sasl RealmCallback setText

List of usage examples for javax.security.sasl RealmCallback setText

Introduction

In this page you can find the example usage for javax.security.sasl RealmCallback setText.

Prototype

public void setText(String text) 

Source Link

Document

Set the retrieved text.

Usage

From source file:org.hawkular.wildfly.agent.itest.util.AbstractITest.java

protected static ModelControllerClient newModelControllerClient(final String host, final int managementPort) {
    final CallbackHandler callbackHandler = new CallbackHandler() {
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback current : callbacks) {
                if (current instanceof NameCallback) {
                    NameCallback ncb = (NameCallback) current;
                    log.fine("ModelControllerClient is sending a username [" + managementUser + "]");
                    ncb.setName(managementUser);
                } else if (current instanceof PasswordCallback) {
                    PasswordCallback pcb = (PasswordCallback) current;
                    log.fine("ModelControllerClient is sending a password [" + managementPasword + "]");
                    pcb.setPassword(managementPasword.toCharArray());
                } else if (current instanceof RealmCallback) {
                    RealmCallback rcb = (RealmCallback) current;
                    log.fine("ModelControllerClient is sending a realm [" + rcb.getDefaultText() + "]");
                    rcb.setText(rcb.getDefaultText());
                } else {
                    throw new UnsupportedCallbackException(current);
                }//  w  w w.  j a  va 2  s .com
            }
        }
    };

    try {
        InetAddress inetAddr = InetAddress.getByName(host);
        log.fine("Connecting a ModelControllerClient to [" + host + ":" + managementPort + "]");
        return ModelControllerClient.Factory.create(inetAddr, managementPort, callbackHandler);
    } catch (Exception e) {
        throw new RuntimeException("Failed to create management client", e);
    }
}

From source file:com.rayo.client.auth.sasl.SASLMechanism.java

/**
 * //  w w w  .j ava  2s  .  co m
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback ncb = (NameCallback) callbacks[i];
            ncb.setName(authenticationId);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) callbacks[i];
            pcb.setPassword(password.toCharArray());
        } else if (callbacks[i] instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) callbacks[i];
            rcb.setText(hostname);
        } else if (callbacks[i] instanceof RealmChoiceCallback) {
            //unused
            //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}

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

@Override
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    NameCallback nc = null;/*w w  w.j  av a  2  s.  co m*/
    PasswordCallback pc = null;
    RealmCallback rc = null;
    for (Callback callback : callbacks) {
        if (callback instanceof RealmChoiceCallback) {
            continue;
        } else if (callback instanceof NameCallback) {
            nc = (NameCallback) callback;
        } else if (callback instanceof PasswordCallback) {
            pc = (PasswordCallback) callback;
        } else if (callback instanceof RealmCallback) {
            rc = (RealmCallback) callback;
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized SASL client callback");
        }
    }
    if (nc != null) {
        log.debug("SASL client callback: setting username: {}", userName);
        nc.setName(userName);
    }
    if (pc != null) {
        log.debug("SASL client callback: setting userPassword");
        pc.setPassword(userPassword);
    }
    if (rc != null) {
        log.debug("SASL client callback: setting realm: {}", rc.getDefaultText());
        rc.setText(rc.getDefaultText());
    }
}

From source file:org.apache.hadoop.io.crypto.bee.key.sasl.KeySaslClient.java

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            // logger.debug("set name");
            NameCallback ncb = (NameCallback) callbacks[i];
            ncb.setName(keyToken.getUser());
        } else if (callbacks[i] instanceof PasswordCallback) {
            // logger.debug("set password");
            PasswordCallback pcb = (PasswordCallback) callbacks[i];
            pcb.setPassword(new String(keyToken.getPassword()).toCharArray());
            // logger.debug("set password:" +
            // Hex.encodeHexString(keyToken.getPassword()));
        } else if (callbacks[i] instanceof RealmCallback) {
            // logger.debug("set realm");
            RealmCallback rcb = (RealmCallback) callbacks[i];
            rcb.setText(SaslUtil.KEY_REALM);
        } else {/*from   w ww . j  a v  a 2s . c o  m*/
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}