src/java.naming/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java

Print this page
rev 10537 : 8055723[core]: Replace concat String to append in StringBuilder parameters
Contributed-by: Otavio Santana <otaviojava@java.net>


  73 
  74                 } else if (callbacks[i] instanceof PasswordCallback) {
  75                     ((PasswordCallback)callbacks[i]).setPassword(passwd);
  76 
  77                 } else if (callbacks[i] instanceof RealmChoiceCallback) {
  78                     /* Deals with a choice of realms */
  79                     String[] choices =
  80                         ((RealmChoiceCallback)callbacks[i]).getChoices();
  81                     int selected = 0;
  82 
  83                     if (authRealm != null && authRealm.length() > 0) {
  84                         selected = -1; // no realm chosen
  85                         for (int j = 0; j < choices.length; j++) {
  86                             if (choices[j].equals(authRealm)) {
  87                                 selected = j;
  88                             }
  89                         }
  90                         if (selected == -1) {
  91                             StringBuilder allChoices = new StringBuilder();
  92                             for (int j = 0; j <  choices.length; j++) {
  93                                 allChoices.append(choices[j] + ",");
  94                             }
  95                             throw new IOException("Cannot match " +
  96                                 "'java.naming.security.sasl.realm' property value, '" +
  97                                 authRealm + "' with choices " + allChoices +
  98                                 "in RealmChoiceCallback");
  99                         }
 100                     }
 101 
 102                     ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);
 103 
 104                 } else if (callbacks[i] instanceof RealmCallback) {
 105                     /* 1 or 0 realms specified in challenge */
 106                     RealmCallback rcb = (RealmCallback) callbacks[i];
 107                     if (authRealm != null) {
 108                         rcb.setText(authRealm);  // Use what user supplied
 109                     } else {
 110                         String defaultRealm = rcb.getDefaultText();
 111                         if (defaultRealm != null) {
 112                             rcb.setText(defaultRealm); // Use what server supplied
 113                         } else {




  73 
  74                 } else if (callbacks[i] instanceof PasswordCallback) {
  75                     ((PasswordCallback)callbacks[i]).setPassword(passwd);
  76 
  77                 } else if (callbacks[i] instanceof RealmChoiceCallback) {
  78                     /* Deals with a choice of realms */
  79                     String[] choices =
  80                         ((RealmChoiceCallback)callbacks[i]).getChoices();
  81                     int selected = 0;
  82 
  83                     if (authRealm != null && authRealm.length() > 0) {
  84                         selected = -1; // no realm chosen
  85                         for (int j = 0; j < choices.length; j++) {
  86                             if (choices[j].equals(authRealm)) {
  87                                 selected = j;
  88                             }
  89                         }
  90                         if (selected == -1) {
  91                             StringBuilder allChoices = new StringBuilder();
  92                             for (int j = 0; j <  choices.length; j++) {
  93                                 allChoices.append(choices[j]).append(',');
  94                             }
  95                             throw new IOException("Cannot match " +
  96                                 "'java.naming.security.sasl.realm' property value, '" +
  97                                 authRealm + "' with choices " + allChoices +
  98                                 "in RealmChoiceCallback");
  99                         }
 100                     }
 101 
 102                     ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);
 103 
 104                 } else if (callbacks[i] instanceof RealmCallback) {
 105                     /* 1 or 0 realms specified in challenge */
 106                     RealmCallback rcb = (RealmCallback) callbacks[i];
 107                     if (authRealm != null) {
 108                         rcb.setText(authRealm);  // Use what user supplied
 109                     } else {
 110                         String defaultRealm = rcb.getDefaultText();
 111                         if (defaultRealm != null) {
 112                             rcb.setText(defaultRealm); // Use what server supplied
 113                         } else {