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) 

Source Link

Document

Constructs an UnsupportedCallbackException with no detail message.

Usage

From source file:org.obiba.mica.config.security.SecretKeyCallbackHandler.java

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    if (callbacks == null || callbacks.length < 1)
        return;/*from   www .ja  va  2  s  .  co  m*/
    Callback callback = callbacks[0];
    if (callback instanceof PasswordCallback) {
        ((PasswordCallback) callback).setPassword(getPassword());
        return;
    }
    throw new UnsupportedCallbackException(callback);
}

From source file:com.adaptris.core.management.jmx.SimpleCallbackHandler.java

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; ++i) {
        if (callbacks[i] instanceof AuthenticateCallback) {
            AuthenticateCallback cb = (AuthenticateCallback) callbacks[i];
            cb.setAuthenticated(authenticate(cb.getAuthenticationID(), cb.getPassword()));
        } else if (callbacks[i] instanceof AuthorizeCallback) {
            AuthorizeCallback cb = (AuthorizeCallback) callbacks[i];
            // If you can login; then you're authorized.
            cb.setAuthorized(authorize(cb.getAuthenticationID()));
        } else {/*from   w  w  w .  ja  va2  s .co m*/
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}

From source file:com.adito.activedirectory.UserPasswordCallbackHandler.java

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            if (log.isDebugEnabled()) {
                log.debug("Handling username callback");
            }/*from  www  . ja  va2 s .  c o m*/
            NameCallback cb = (NameCallback) callbacks[i];
            cb.setName(username);

        } else if (callbacks[i] instanceof PasswordCallback) {
            if (log.isDebugEnabled()) {
                log.debug("Handling password callback");
            }
            PasswordCallback cb = (PasswordCallback) callbacks[i];
            cb.setPassword(password);

        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}

From source file:org.apache.cxf.security.spring.ServerPasswordCallbackHandler.java

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof WSPasswordCallback) {
            WSPasswordCallback pwCallback = (WSPasswordCallback) callback;
            // TODO: need to check getUsage
            Authentication authentication = new UsernamePasswordAuthenticationToken(pwCallback.getIdentifier(),
                    pwCallback.getPassword());
            try {
                authentication = authenticationManager.authenticate(authentication);
            } catch (AuthenticationException ex) {
                throw translateException(ex);
            }//ww w.  ja v  a2  s. c o m
            Message message = PhaseInterceptorChain.getCurrentMessage();
            if (message == null) {
                LOG.fine("No current message; can't add the Authentication object to the Exchange.");
            } else {
                message.getExchange().put(Authentication.class, authentication);
            }
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}

From source file:io.fabric8.maven.impl.MavenSecureHttpContext.java

public Subject doAuthenticate(final String username, final String password) {
    try {//from  w ww  .  j ava  2  s  .c om
        Subject subject = new Subject();
        LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (int i = 0; i < callbacks.length; i++) {
                    if (callbacks[i] instanceof NameCallback) {
                        ((NameCallback) callbacks[i]).setName(username);
                    } else if (callbacks[i] instanceof PasswordCallback) {
                        ((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                }
            }
        });
        loginContext.login();
        if (role != null && role.length() > 0) {
            String clazz = "org.apache.karaf.jaas.boot.principal.RolePrincipal";
            String name = role;
            int idx = role.indexOf(':');
            if (idx > 0) {
                clazz = role.substring(0, idx);
                name = role.substring(idx + 1);
            }
            boolean found = false;
            for (Principal p : subject.getPrincipals()) {
                if (p.getClass().getName().equals(clazz) && p.getName().equals(name)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new FailedLoginException("User does not have the required role " + role);
            }
        }
        return subject;
    } catch (AccountException e) {
        LOGGER.warn("Account failure", e);
        return null;
    } catch (LoginException e) {
        LOGGER.debug("Login failed", e);
        return null;
    } catch (GeneralSecurityException e) {
        LOGGER.error("General Security Exception", e);
        return null;
    }
}

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

/**
 * //  www  . ja  v a  2s  . c  om
 */
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:net.java.sip.communicator.impl.certificate.CertificateServiceImpl.java

private Builder loadKeyStore(final CertificateConfigEntry entry) throws KeyStoreException {
    final File f = new File(entry.getKeyStore());
    final KeyStoreType kt = entry.getKeyStoreType();
    if ("PKCS11".equals(kt.getName())) {
        String config = "name=" + f.getName() + "\nlibrary=" + f.getAbsoluteFile();
        try {/*from   www .  j av a  2 s.  c o m*/
            Class<?> pkcs11c = Class.forName("sun.security.pkcs11.SunPKCS11");
            Constructor<?> c = pkcs11c.getConstructor(InputStream.class);
            Provider p = (Provider) c.newInstance(new ByteArrayInputStream(config.getBytes()));
            Security.insertProviderAt(p, 0);
        } catch (Exception e) {
            logger.error(
                    "Tried to access the PKCS11 provider on an " + "unsupported platform or the load failed",
                    e);
        }
    }
    KeyStore.Builder ksBuilder = KeyStore.Builder.newInstance(kt.getName(), null, f,
            new KeyStore.CallbackHandlerProtection(new CallbackHandler() {
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for (Callback cb : callbacks) {
                        if (!(cb instanceof PasswordCallback))
                            throw new UnsupportedCallbackException(cb);

                        PasswordCallback pwcb = (PasswordCallback) cb;
                        if (entry.isSavePassword()) {
                            pwcb.setPassword(entry.getKeyStorePassword().toCharArray());
                            return;
                        } else {
                            AuthenticationWindowService authenticationWindowService = CertificateVerificationActivator
                                    .getAuthenticationWindowService();

                            if (authenticationWindowService == null) {
                                logger.error("No AuthenticationWindowService " + "implementation");
                                throw new IOException("User cancel");
                            }

                            AuthenticationWindowService.AuthenticationWindow aw = authenticationWindowService
                                    .create(f.getName(), null, kt.getName(), false, false, null, null, null,
                                            null, null, null, null);

                            aw.setAllowSavePassword(false);
                            aw.setVisible(true);
                            if (!aw.isCanceled())
                                pwcb.setPassword(aw.getPassword());
                            else
                                throw new IOException("User cancel");
                        }
                    }
                }
            }));
    return ksBuilder;
}

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);
                }//from w  ww .  jav  a  2 s.  c o m
            }
        }
    };

    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:org.alfresco.filesys.auth.cifs.EnterpriseCifsAuthenticator.java

/**
 * JAAS callback handler//from   www. j a v  a 2  s  .  co m
 * 
 * @param callbacks Callback[]
 * @exception IOException
 * @exception UnsupportedCallbackException
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    // Process the callback list

    for (int i = 0; i < callbacks.length; i++) {
        // Request for user name

        if (callbacks[i] instanceof NameCallback) {
            NameCallback cb = (NameCallback) callbacks[i];
            // cb.setName(m_accountName);
            cb.setName("");
        }

        // Request for password
        else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback cb = (PasswordCallback) callbacks[i];
            cb.setPassword(m_password.toCharArray());
        }

        // Request for realm

        else if (callbacks[i] instanceof RealmCallback) {
            RealmCallback cb = (RealmCallback) callbacks[i];
            cb.setText(m_krbRealm);
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}

From source file:org.alfresco.repo.webdav.auth.BaseKerberosAuthenticationFilter.java

/**
 * JAAS callback handler/*from   w ww  .  j  a v  a2 s.c  o  m*/
 * 
 * @param callbacks Callback[]
 * @exception IOException
 * @exception UnsupportedCallbackException
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    // Process the callback list
    if (getLogger().isDebugEnabled())
        getLogger().debug("Processing the JAAS callback list of " + callbacks.length + " items.");
    for (int i = 0; i < callbacks.length; i++) {
        // Request for user name

        if (callbacks[i] instanceof NameCallback) {
            if (getLogger().isDebugEnabled())
                getLogger().debug("Request for user name.");
            NameCallback cb = (NameCallback) callbacks[i];
            cb.setName(m_accountName);
        }

        // Request for password
        else if (callbacks[i] instanceof PasswordCallback) {
            if (getLogger().isDebugEnabled())
                getLogger().debug("Request for password.");
            PasswordCallback cb = (PasswordCallback) callbacks[i];
            cb.setPassword(m_password.toCharArray());
        }

        // Request for realm

        else if (callbacks[i] instanceof RealmCallback) {
            if (getLogger().isDebugEnabled())
                getLogger().debug("Request for realm.");
            RealmCallback cb = (RealmCallback) callbacks[i];
            cb.setText(m_krbRealm);
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}