Package javax.security.auth.callback

Examples of javax.security.auth.callback.NameCallback


            log.debug("super.login()==true");
            return true;
        }

        // Time to see if this is a delegation request.
        NameCallback ncb = new NameCallback("Username:");
        ObjectCallback ocb = new ObjectCallback("Password:");

        try {
            callbackHandler.handle(new Callback[] { ncb, ocb });
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            }
            return false; // If the CallbackHandler can not handle the required callbacks then no chance.
        }

        String name = ncb.getName();
        Object credential = ocb.getCredential();

        if (credential instanceof OuterUserCredential) {
            // This credential type will only be seen for a delegation request, if not seen then the request is not for us.
View Full Code Here


        }
        PasswordPlusCredential ppCredential = (PasswordPlusCredential) credential;

        for (Callback current : callbacks) {
            if (current instanceof NameCallback) {
                NameCallback ncb = (NameCallback) current;
                ncb.setName(principal.getName());
            } else if (current instanceof PasswordCallback) {
                PasswordCallback pcb = (PasswordCallback) current;
                pcb.setPassword(ppCredential.getPassword());
            } else if (current instanceof RealmCallback) {
                RealmCallback rcb = (RealmCallback) current;
View Full Code Here

            log.debug("super.login()==true");
            return true;
        }

        // Time to see if this is a delegation request.
        NameCallback ncb = new NameCallback("Username:");
        ObjectCallback ocb = new ObjectCallback("Password:");

        try {
            callbackHandler.handle(new Callback[] { ncb, ocb });
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            }
            return false; // If the CallbackHandler can not handle the required callbacks then no chance.
        }

        String name = ncb.getName();
        Object credential = ocb.getCredential();

        if (credential instanceof OuterUserPlusCredential) {

            OuterUserPlusCredential oupc = (OuterUserPlusCredential) credential;
View Full Code Here

   public boolean login()
      throws LoginException
   {
      try
      {
         NameCallback cbName = new NameCallback("Enter username");
         PasswordCallback cbPassword = new PasswordCallback("Enter password", false);
  
         // Get the username and password from the callback handler
         callbackHandler.handle(new Callback[] { cbName, cbPassword });
         username = cbName.getName();
      }
      catch (Exception ex)
      {
         log.error("Error logging in", ex);
         LoginException le = new LoginException(ex.getMessage());
View Full Code Here

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback current : callbacks) {
                if (current instanceof NameCallback) {
                    NameCallback ncb = (NameCallback) current;
                    ncb.setName("anonymous");
                } else {
                    throw new UnsupportedCallbackException(current);
                }
            }
        }
View Full Code Here

                @Override
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for (Callback current : callbacks) {
                        if (current instanceof NameCallback) {
                            NameCallback ncb = (NameCallback) current;
                            if (DOLLAR_LOCAL.equals(ncb.getDefaultName()) == false) {
                                throw new SaslException("Only " + DOLLAR_LOCAL + " user is acceptable.");
                            }
                        } else if (current instanceof AuthorizeCallback) {
                            AuthorizeCallback acb = (AuthorizeCallback) current;
                            acb.setAuthorized(acb.getAuthenticationID().equals(acb.getAuthorizationID()));
View Full Code Here

                logger.fine("handle callback i " + i + ": " + callbacks[i]);
                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("user.name: " + System.getProperty("user.name"));
                    cb.setName(System.getProperty("user.name"));
//                    } else {
//                        logger.fine("cb.getPrompt(): " + cb.getPrompt());
//                        throw new UnsupportedCallbackException(callbacks[i]);
//                    }
                } else if (callbacks[i] instanceof PasswordCallback) {
                    PasswordCallback cb = (PasswordCallback) callbacks[i];
                    if (usePW) {
                        // TODO: replace by native func to suppress password echo
                        System.out.print(cb.getPrompt() + " ");
                        System.out.flush();
                        String pw = new BufferedReader(new InputStreamReader(System.in)).readLine();
                        cb.setPassword(pw.toCharArray());
                        pw = null;
                    } else {
                        cb.setPassword(new char[0]);
                    }
                } else if (callbacks[i] instanceof ConfirmationCallback) {
                    ConfirmationCallback cb = (ConfirmationCallback) callbacks[i];
                    cb.setSelectedIndex(cb.getDefaultOption());
                } else {
                    throw new UnsupportedCallbackException(callbacks[i]);
                }
            }
        }
View Full Code Here

                }
            }
            String host = args[0];
            int port = Integer.parseInt(args[1]);
            logger.info("connect to host(" + host + ":" + port + ")");
            NameCallback ncb = new NameCallback("user:");
            PasswordCallback pwcb = new PasswordCallback("password:", false);
            Callback[] callbacks = {ncb, pwcb};
            MyCallbackHandler cb = new MyCallbackHandler();
            usePW = true;
            cb.handle(callbacks);
            String username = ncb.getName();
            String userpw = pwcb.getPassword().toString();
            if (useKS) {
                PasswordCallback kspw = new PasswordCallback("keystore password:", true);
                Callback[] kcallbacks = {kspw};
                cb.handle(kcallbacks);
View Full Code Here

               
            }
            String defaultValue = getDefaultValue();
           
            if(defaultValue == null) {
                return new NameCallback(prompt);
            } else {
                return new NameCallback(prompt, defaultValue);
            }
        }
View Full Code Here

            if (text != null) {
               System.err.println(text);
            }
           
         } else if (callbacks[i] instanceof NameCallback) {
            NameCallback nc = (NameCallback) callbacks[i];
           
            if (nc.getDefaultName() == null) {
               System.err.print(nc.getPrompt());
            } else {
               System.err.print(nc.getPrompt() +
                       " [" + nc.getDefaultName() + "] ");
            }
            System.err.flush();
           
            String result = readLine();
            if (result.equals("")) {
               result = nc.getDefaultName();
            }
           
            nc.setName(result);
           
         } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callbacks[i];
           
            System.err.print(pc.getPrompt());
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.