Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, JBoss Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.remoting3.security;
 
 
A callback handler which performs client authentication steps.
 
 public class PasswordClientCallbackHandler implements CallbackHandler {
 
     private static final Logger log = Logger.getLogger("org.jboss.remoting.security.client");
 
     private final String actualUserName;
     private final String actualUserRealm;
     private final char[] password;

    
An empty password array.
 
     public static final char[] EMPTY_PASSWORD = new char[0];

    
Create a new instance.

Parameters:
actualUserName the user name to supply, or null for none
actualUserRealm the user realm to supply, or null for none
password the password to supply, or null for none
 
     public PasswordClientCallbackHandler(final String actualUserNamefinal String actualUserRealmfinal char[] password) {
         this. = actualUserName;
         this. = actualUserRealm;
         this. = password;
     }

    
Handle the array of given callbacks.

Parameters:
callbacks the callbacks to handle
Throws:
javax.security.auth.callback.UnsupportedCallbackException if a callback is unsupported
 
     public void handle(final Callback[] callbacksthrows UnsupportedCallbackException {
         MAIN: for (Callback callback : callbacks) {
             if (callback instanceof NameCallback) {
                 final NameCallback nameCallback = (NameCallbackcallback;
                 final String defaultName = nameCallback.getDefaultName();
                 .tracef("User name requested; prompt '%s', default is '%s', ours is '%s'"nameCallback.getPrompt(), defaultName);
                 if ( == null) {
                     if (defaultName != null) {
                         nameCallback.setName(defaultName);
                     }
                 } else {
                     nameCallback.setName();
                 }
             } else if (callback instanceof RealmCallback) {
                 final RealmCallback realmCallback = (RealmCallbackcallback;
                 final String defaultRealm = realmCallback.getDefaultText();
                 .tracef("Realm requested; prompt '%s', default is '%s', ours is '%s'"realmCallback.getPrompt(), defaultRealm);
                 if ( == null) {
                     if (defaultRealm != null) {
                         realmCallback.setText(defaultRealm);
                     }
                 } else {
                     realmCallback.setText();
                 }
             } else if (callback instanceof RealmChoiceCallback &&  != null) {
                 final RealmChoiceCallback realmChoiceCallback = (RealmChoiceCallbackcallback;
                 final String[] choices = realmChoiceCallback.getChoices();
                 for (int i = 0; i < choices.lengthi++) {
                     if (choices[i] != null && choices[i].equals()) {
                        realmChoiceCallback.setSelectedIndex(i);
                        continue MAIN;
                    }
                }
                throw new UnsupportedCallbackException(callback"No realm choices match realm '" +  + "'");
            } else if (callback instanceof TextOutputCallback) {
                final TextOutputCallback textOutputCallback = (TextOutputCallbackcallback;
                final String kind;
                switch (textOutputCallback.getMessageType()) {
                    case .kind = "ERROR"break;
                    case .kind = "INFORMATION"break;
                    case .kind = "WARNING"break;
                    defaultkind = "UNKNOWN"break;
                }
                .debugf("Authentication layer produced a %s message: %s"kindtextOutputCallback.getMessage());
            } else if (callback instanceof PasswordCallback) {
                final PasswordCallback passwordCallback = (PasswordCallbackcallback;
                passwordCallback.setPassword();
            } else {
                throw new UnsupportedCallbackException(callback);
            }
        }
    }
New to GrepCode? Check out our FAQ X