Example usage for javax.security.auth.callback UnsupportedCallbackException UnsupportedCallbackException

List of usage examples for javax.security.auth.callback UnsupportedCallbackException UnsupportedCallbackException

Introduction

In this page you can find the example usage for javax.security.auth.callback UnsupportedCallbackException UnsupportedCallbackException.

Prototype

public UnsupportedCallbackException(Callback callback, String msg) 

Source Link

Document

Constructs a UnsupportedCallbackException with the specified detail message.

Usage

From source file:com.adito.pam.PAMCallbackHandler.java

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {

        /* Handles Id request */
        if (callbacks[i] instanceof NameCallback) {
            if (LOG.isDebugEnabled())
                LOG.debug("Handling username callback");
            NameCallback nc = (NameCallback) callbacks[i];
            nc.setName(username);/* ww w  .j av a2 s .c o m*/
        }

        /* Handles Credentitial request */
        else if (callbacks[i] instanceof PasswordCallback) {
            if (LOG.isDebugEnabled())
                LOG.debug("Handling password callback");
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            pc.setPassword(password);
        }

        /* Cannot Handle other request */
        else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }

}

From source file:com.alfaariss.oa.profile.aselect.ws.security.PWCBHandler.java

/**
 * Handle the retrieval of the signing key password.
 * /*from   www  .j  av  a2s  .c om*/
 * The password and alias are read from the OAS {@link CryptoManager}.
 * @see javax.security.auth.callback.CallbackHandler#handle(
 *  javax.security.auth.callback.Callback[])
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    try {
        CryptoManager manager = Engine.getInstance().getCryptoManager();
        if (manager == null) {
            _logger.warn("Could not create OACrypto, OAS cryptomanager not initialized");
            throw new OAException(SystemErrors.ERROR_CRYPTO_CREATE);
        }

        AbstractSigningFactory asf = manager.getSigningFactory();
        if (asf == null) {
            _logger.warn("Could not create OACrypto, OAS signing not enabled");
            throw new OAException(SystemErrors.ERROR_CRYPTO_CREATE);
        }
        for (Callback callback : callbacks) {
            if (callback instanceof WSPasswordCallback) {
                WSPasswordCallback pc = (WSPasswordCallback) callback;
                if (pc.getUsage() == WSPasswordCallback.SIGNATURE) {
                    if (asf.getAlias().equals(pc.getIdentifier())) {
                        String password = asf.getPrivateKeyPassword();
                        if (password != null)
                            pc.setPassword(password);
                    }
                } else {
                    _logger.warn("The callback usage is not supported: " + pc.getUsage());
                    throw new UnsupportedCallbackException(callback, "Unrecognized Callback usage");
                }
            } else {
                _logger.warn("The callback is not supported: " + callback);
                throw new UnsupportedCallbackException(callback, "Unrecognized Callback");
            }

        }
    } catch (OAException e) {
        _logger.error("OAS not properly initialized", e);
        throw new IOException("OAS not properly initialized");
    }
}

From source file:br.rnp.stcfed.sts.client.impl.UsernamePasswordCallbackHandler.java

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    System.out.println(" ===== UsernamePasswordCallbackHandler =======");
    log.info("  ----> Checking callbacks");
    for (int i = 0; i < callbacks.length; i++) {
        Callback callback = callbacks[i];
        log.info("  ----> STS Callback" + callback);
        if (callback instanceof NameCallback) {
            handleUsernameCallback((NameCallback) callback);
        } else if (callback instanceof PasswordCallback) {
            handlePasswordCallback((PasswordCallback) callback);
        } else {/* w  w  w .j av  a 2s.  c  o  m*/
            throw new UnsupportedCallbackException(callback, "Unknow callback for username or password");
        }
    }
}

From source file:com.flexive.core.security.PassiveCallbackHandler.java

/**
 * Handles the specified set of Callbacks. Uses the username and password that were supplied to our
 * constructor to popluate the Callbacks.
 * <p/>/* w  w  w .  ja v a2s  .c  o  m*/
 * This class supports NameCallback and PasswordCallback.
 *
 * @param callbacks the callbacks to handle
 * @throws IOException                  if an input or output error occurs.
 * @throws UnsupportedCallbackException if the callback is not an instance of NameCallback or PasswordCallback
 */
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    for (Callback callback : callbacks) {
        if (callback == null)
            continue;
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(username);
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword(password);
        } else if (callback instanceof FxCallback) {
            FxCallback ac = ((FxCallback) callback);
            ac.setTakeOverSession(takeOverSession);
            ac.setDataSource(ds);
            ac.setSessionContext(ctx);
        } else {
            UnsupportedCallbackException uce = new UnsupportedCallbackException(callback,
                    "Callback class [" + callback.getClass() + "] not supported");
            LOG.error(uce);
            throw uce;
        }
    }

}

From source file:de.escidoc.core.test.security.client.PWCallback.java

/**
 * The handle method of the callback handler.
 *
 * @param callbacks the WSPasswordCallback implementation
 * @throws IOException                  Exception
 * @throws UnsupportedCallbackException Exception
 * @see javax.security.auth.callback.CallbackHandler#handle (javax.security.auth.callback.Callback[])
 *///from  ww  w  .  j  a  va  2 s . c om
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof WSPasswordCallback) {
            WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
            if ("eSciDocUser".equals(pc.getIdentifer())) {
                pc.setPassword(handle);
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.jaas.ThinClientCallbackHandler.java

/** Implementation of the handle method specified by
 * <code> javax.security.auth.callback.CallbackHandler </code>
 * @param callbacks <code>Array of 
 * javax.security.auth.callback.CallbackHandler</code>
 *
 *//* www. j  a v a2 s .c  o  m*/
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof TextOutputCallback) {
            // Ignore this section for now. This will be used when a generic callback handler
            // is being implemented. In our current implementation, we are only expecting the
            //login type callback handler.
        } else if (callbacks[i] instanceof NameCallback) {
            // For now hard-code the alias of the the RegistryOperator account
            NameCallback nc = (NameCallback) callbacks[i];
            String alias = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.alias");
            if (alias == null) {
                String message = "Error: the jaxr-ebxml.security.alias " + "property must be set";
                log.error(message);
                System.err.println(message);
                alias = "";
            }
            nc.setName(alias);
        } else if (callbacks[i] instanceof PasswordCallback) {
            // For now hard-code the password of the the RegistryOperator account
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            char[] password = null;
            if (handleStorePass) {
                String storepass = ProviderProperties.getInstance()
                        .getProperty("jaxr-ebxml.security.storepass");
                if (storepass == null) {
                    storepass = "ebxmlrr";
                }
                password = storepass.toCharArray();
                handleStorePass = false;
            } else {
                String keypass = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.keypass");
                if (keypass == null) {
                    String message = "Error: the jaxr-ebxml.security.keypass " + "property must be set";
                    log.error(message);
                    System.err.println(message);
                    keypass = "";
                }
                password = keypass.toCharArray();
            }
            pc.setPassword(password);
        } else if (callbacks[i] instanceof ConfirmationCallback) {
            ConfirmationCallback cc = (ConfirmationCallback) callbacks[i];
            cc.setSelectedIndex(ConfirmationCallback.OK);
        } else {
            throw new UnsupportedCallbackException(callbacks[i],
                    JAXRResourceBundle.getInstance().getString("message.error.unrecognized.callback"));
        }
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.jaas.DialogAuthenticationCallbackHandler.java

/** Implementation of the handle method specified by
 * <code> javax.security.auth.callback.CallbackHandler </code>
 * @param callbacks <code>Array of javax.security.auth.callback.CallbackHandler</code>
 *
 *//*from   w w w.j a v  a2  s . c o m*/
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    int result = showDialog();

    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof TextOutputCallback) {
            // Ignore this section for now. This will be used when a generic callback handler
            // is being implemented. In our current implementation, we are only expecting the
            //login type callback handler.
        } else if (callbacks[i] instanceof NameCallback) {
            // prompt the user for a username
            NameCallback nc = (NameCallback) callbacks[i];
            String strPrompt = nc.getPrompt();
            String strName = "";

            //                if (strPrompt.equals(authResBundle.getString("Keystore alias: "))) {
            if (strPrompt.equals(authResBundle.getString("Keystore.alias."))) {
                strName = txtAlias.getText();
            }

            nc.setName(strName);
        } else if (callbacks[i] instanceof PasswordCallback) {
            // prompt the user for sensitive information
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            String strPrompt = pc.getPrompt();
            char[] chrPass = new char[0];

            //                if (strPrompt.equals(authResBundle.getString("Keystore password: "))) {
            if (strPrompt.equals(authResBundle.getString("Keystore.password."))) {
                /* As of now hide the Keystore password part from the user and
                   read directly from the properties file
                   chrPass = txtStorepass.getPassword() ; */
                chrPass = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.storepass")
                        .toCharArray();

                if ((chrPass == null) || (chrPass.length == 0)) {
                    log.error("Property jaxr-ebxml.security.storepass is undefined");
                }
                //                } else if (strPrompt.equals(authResBundle.getString("Private key password (optional): "))) {
            } else if (strPrompt.equals(authResBundle.getString("Private.key.password.optional."))) {
                chrPass = txtKeypass.getPassword();
            }

            pc.setPassword(chrPass);
        } else if (callbacks[i] instanceof ConfirmationCallback) {
            ConfirmationCallback cc = (ConfirmationCallback) callbacks[i];

            if (result == OK) {
                cc.setSelectedIndex(ConfirmationCallback.OK);
            } else {
                cc.setSelectedIndex(ConfirmationCallback.CANCEL);
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i],
                    JAXRResourceBundle.getInstance().getString("message.error.unrecognized.callback"));
        }
    }
}

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

@Override
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    NameCallback nc = null;/* ww  w.  jav  a2s . c o  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.KeySaslServer.java

public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof RealmCallback) {
            // do your business
        } else if (callback instanceof NameCallback) {
            // do your business
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword(new String(keyToken.getPassword()).toCharArray());
            // logger.debug("set password:" +
            // Hex.encodeHexString(keyToken.getPassword()));
        } else if (callback instanceof AuthorizeCallback) {
            // logger.debug("set authorized to true");
            AuthorizeCallback authCallback = ((AuthorizeCallback) callback);
            authCallback.setAuthorized(true);
        } else {/*from  w w  w.jav a2 s  .c  om*/
            // logger.error(callback.getClass().getName());
            throw new UnsupportedCallbackException(callback, "Unrecognized Callback");
        }
    }
}

From source file:org.apache.ws.security.handler.SignatureUTAliasTest.java

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof WSPasswordCallback) {
            WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
            if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN && "alice".equals(pc.getIdentifier())) {
                pc.setPassword("verySecret");
            } else if (pc.getUsage() == WSPasswordCallback.SIGNATURE && "wss40".equals(pc.getIdentifier())) {
                pc.setPassword("security");
            } else {
                throw new IOException("Authentication failed");
            }// w  w w .  ja v  a  2s.  c  o  m
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}