Package javax.security.auth.callback

Examples of javax.security.auth.callback.NameCallback


            log.log(Level.FINE, "login failed, no trust manager found");
            log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
            return loginSucceeded;
        }
       
        NameCallback usernameCallback = new NameCallback("username");
        PasswordCallback passwordCallback = new PasswordCallback("password", true);

        try {
            callbackHandler.handle(new Callback[]{usernameCallback, passwordCallback});
        } catch (UnsupportedCallbackException ex) {
            LoginException le = new LoginException("callback is not supported");
            le.initCause(ex);
            throw le;
        } catch (IOException ex) {
            LoginException le = new LoginException("io error in callback handler");
            le.initCause(ex);
            throw le;
        }

        String password = new String(passwordCallback.getPassword());
        Properties props = new Properties();
        try {
            props.load(new ByteArrayInputStream(password.getBytes()));
        } catch (IOException ex) {
            // Can not happen we are reading from a byte array
            log.log(Level.FINE, "login failed, loading password properties failed", ex);
            log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
            return loginSucceeded;
        }
       
        String messageStr = props.getProperty("message");
        if(messageStr == null || messageStr.length() == 0) {
            log.log(Level.FINE, "login failed, message is empty");
            log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
            return loginSucceeded;
        }
       
        String signatureStr = props.getProperty("signature");
        if(signatureStr == null || signatureStr.length() == 0) {
            log.log(Level.FINE, "login failed, signature is empty");
            log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
            return loginSucceeded;
        }
       
        String algorithm = props.getProperty("algorithm");
        if(algorithm == null || algorithm.length() == 0) {
            log.log(Level.FINE, "login failed, algorithm is empty");
            log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
            return loginSucceeded;
        }

        byte[] message = Base64.decode(messageStr);
        if(message == null) {
            log.log(Level.FINE, "login failed, message is not base 64 encoded");
            log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
            return loginSucceeded;
        }
       
        byte[] signature = Base64.decode(signatureStr);
        if(signature == null) {
            log.log(Level.FINE, "login failed, signature is not base 64 encoded");
            log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
            return loginSucceeded;
        }

        if (trustManager.isValidMessage(usernameCallback.getName(), message, signature, algorithm)) {
            log.log(Level.FINE, "login succeeded, message has a valid signature");
            loginSucceeded = true;
            username = usernameCallback.getName();
        } else {
            log.log(Level.FINE, "login failed, message has an invalid signature");
        }
        log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
        return loginSucceeded;
View Full Code Here


        if (confError != null) {
            throw RB.newLoginException("unixlogin.error.conf", new Object[]{confError});
        }
        PasswordCallback pwCallback = new PasswordCallback(RB.getString("unixlogin.userprompt"), false);
        NameCallback nameCallback = new NameCallback(RB.getString("unixlogin.pwprompt"));

        try {
            callbackHandler.handle(new Callback[]{nameCallback, pwCallback});
        } catch (IOException ex) {
            throw RB.newLoginException("unixlogin.error.iocb", ex,
                    new Object[]{ex.getLocalizedMessage()});
        } catch (UnsupportedCallbackException ex) {
            throw RB.newLoginException("unixlogin.error.invalidcb", ex,
                    new Object[]{ex.getLocalizedMessage()});
        }

        String username = nameCallback.getName();
        if (username == null || username.length() == 0) {
            loginSucceded = false;
            log.exiting("UnixLoginModule", "login", Boolean.FALSE);
            return loginSucceded;
        }
View Full Code Here

     *         if username of password is invalid.
     */
    public boolean login() throws LoginException {
        log.entering("TestLoginModule", "login");
        PasswordCallback pwCallback = new PasswordCallback(RB.getString("unixlogin.userprompt"), false);
        NameCallback nameCallback = new NameCallback(RB.getString("unixlogin.pwprompt"));

        try {
            callbackHandler.handle(new Callback[]{nameCallback, pwCallback});
        } catch (IOException ex) {
            throw RB.newLoginException("unixlogin.error.iocb", ex,
                    new Object[]{ex.getLocalizedMessage()});
        } catch (UnsupportedCallbackException ex) {
            throw RB.newLoginException("unixlogin.error.invalidcb", ex,
                    new Object[]{ex.getLocalizedMessage()});
        }

        username = nameCallback.getName();
        log.exiting("TestLoginModule", "login", Boolean.TRUE);
        return true;
    }
View Full Code Here

     */
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
       
        for(int i = 0; i < callbacks.length; i++) {
            if(callbacks[i] instanceof NameCallback) {
                NameCallback cb = (NameCallback)callbacks[i];
                System.out.print(cb.getPrompt());
                if(cb.getDefaultName() != null) {
                    System.out.print(" [" + cb.getDefaultName() + "] ");
                }
                String name = readLine();
                if(name.length() == 0) {
                    name = cb.getDefaultName();
                }
                cb.setName(name);
            } else if(callbacks[i] instanceof TextOutputCallback) {
                TextOutputCallback cb = (TextOutputCallback)callbacks[i];
                switch(cb.getMessageType()) {
                    case TextOutputCallback.ERROR:
                        System.out.print(RB.rb().getString("ccb.error"));
                        break;
                    case TextOutputCallback.WARNING:
                        System.out.print(RB.rb().getString("ccb.warning"));
                        break;
                    default:
                        // do nothing
                }
                System.out.println(cb.getMessage());
            } else if(callbacks[i] instanceof TextInputCallback) {
                TextInputCallback cb = (TextInputCallback)callbacks[i];
                System.out.print(cb.getPrompt());
                if(cb.getDefaultText() != null) {
                    System.out.print(" [" + cb.getDefaultText() + "] ");
                }
                String text = readLine();
                if(text.length() == 0) {
                    text = cb.getDefaultText();
                }
                cb.setText(text);
            } else if(callbacks[i] instanceof PasswordCallback) {
                PasswordCallback cb = (PasswordCallback)callbacks[i];
                cb.setPassword(SGEUtil.getInstance().getPassword(cb.getPrompt()));
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
    }
View Full Code Here

                if (callbacks[i] instanceof TextOutputCallback) {
                    logger.fine("skip text output callback " + callbacks[i]);
                    continue;
                } else if (callbacks[i] instanceof NameCallback) {

                    NameCallback cb = (NameCallback) callbacks[i];

                    if (cb.getPrompt().indexOf("alias") >= 0) {
                        logger.fine("handle alias callback: " + cluster.getUser());
                        cb.setName(cluster.getUser());
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                } else if (callbacks[i] instanceof PasswordCallback) {

                    PasswordCallback cb = (PasswordCallback) callbacks[i];

                    String prompt = cb.getPrompt().toLowerCase();
                    logger.fine("handle password callback " + prompt);
                    if (prompt.indexOf("keystore password") >= 0) {
                        logger.fine("found keystore password callback");
                        cb.setPassword(cluster.getKeystorePassword());
                    } else if (prompt.indexOf("key password") >= 0) {
                        logger.fine("found key password callback");
                        cb.setPassword(cluster.getPrivateKeyPassword());
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                } else if (callbacks[i] instanceof ConfirmationCallback) {
                    logger.fine("handle confirm callback");
                    ConfirmationCallback cb = (ConfirmationCallback) callbacks[i];
                    cb.setSelectedIndex(cb.getDefaultOption());
                } else {
                    throw new UnsupportedCallbackException(callbacks[i]);
                }
            }
        }
View Full Code Here

                LOG.debug( "Processing callback {} of {}: {}" + callback.getClass(), ( i + 1 ), callbacks.length );
            }

            if ( callback instanceof NameCallback )
            {
                NameCallback nameCB = ( NameCallback ) callback;
                LOG.debug( "NameCallback default name:  {}", nameCB.getDefaultName() );

                username = nameCB.getDefaultName();
            }
            else if ( callback instanceof RealmCallback )
            {
                RealmCallback realmCB = ( RealmCallback ) callback;
                LOG.debug( "RealmCallback default text:  {}", realmCB.getDefaultText() );
View Full Code Here

        // Set up our CallbackHandler requests
        if (callbackHandler == null)
            throw new LoginException("No CallbackHandler specified");
        Callback callbacks[] = new Callback[2];
        callbacks[0] = new NameCallback("Username: ");
        callbacks[1] = new PasswordCallback("Password: ", false);

        // Interact with the user to retrieve the username and password
        String username = null;
        String password = null;
View Full Code Here

                Callback callBack = callbacks[ii];

                // Handles username callback.
                if ( callBack instanceof NameCallback )
                {
                    NameCallback nameCallback = ( NameCallback ) callBack;
                    nameCallback.setName( name );
                    // Handles password callback.
                }
                else if ( callBack instanceof PasswordCallback )
                {
                    PasswordCallback passwordCallback = ( PasswordCallback ) callBack;
View Full Code Here

        {
            for ( Callback callback : callbacks )
            {
                if ( callback instanceof NameCallback )
                {
                    NameCallback nameCallback = ( NameCallback ) callback;
                    nameCallback.setName( name );
                }
                else if ( callback instanceof PasswordCallback )
                {
                    PasswordCallback passwordCallback = ( PasswordCallback ) callback;
                    passwordCallback.setPassword( password.toCharArray() );
View Full Code Here

    @Override
    public void handle(Callback[] callbacks) throws InvalidToken,
        UnsupportedCallbackException, StandbyException, RetriableException,
        IOException {
      NameCallback nc = null;
      PasswordCallback pc = null;
      AuthorizeCallback ac = null;
      for (Callback callback : callbacks) {
        if (callback instanceof AuthorizeCallback) {
          ac = (AuthorizeCallback) callback;
        } else if (callback instanceof NameCallback) {
          nc = (NameCallback) callback;
        } else if (callback instanceof PasswordCallback) {
          pc = (PasswordCallback) callback;
        } else if (callback instanceof RealmCallback) {
          continue; // realm is ignored
        } else {
          throw new UnsupportedCallbackException(callback,
              "Unrecognized SASL DIGEST-MD5 Callback");
        }
      }
      if (pc != null) {
        TokenIdentifier tokenIdentifier = getIdentifier(nc.getDefaultName(),
            secretManager);
        char[] password = getPassword(tokenIdentifier);
        UserGroupInformation user = null;
        user = tokenIdentifier.getUser(); // may throw exception
        connection.attemptingUser = user;
View Full Code Here

TOP

Related Classes of javax.security.auth.callback.NameCallback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.