javax.security.sasl.RealmChoiceCallback Java Examples

The following examples show how to use javax.security.sasl.RealmChoiceCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HostControllerConnection.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            String defaultText = rcb.getDefaultText();
            rcb.setText(defaultText); // For now just use the realm suggested.
        } else if (current instanceof RealmChoiceCallback) {
            throw new UnsupportedCallbackException(current, "Realm choice not currently supported.");
        } else if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(authKey.toCharArray());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example #2
Source File: SecretIdentityService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            String defaultText = rcb.getDefaultText();
            rcb.setText(defaultText); // For now just use the realm suggested.
        } else if (current instanceof RealmChoiceCallback) {
            throw DomainManagementLogger.ROOT_LOGGER.realmNotSupported(current);
        } else if (current instanceof OptionalNameCallback) {
            // Do nothing as we don't want to set a name for local authentication.
        } else if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example #3
Source File: ClientServerTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("NameCallback");
            ((NameCallback) callback).setName(userId);
        } else if (callback instanceof PasswordCallback) {
            System.out.println("PasswordCallback");
            ((PasswordCallback) callback).setPassword(passwd);
        } else if (callback instanceof RealmCallback) {
            System.out.println("RealmCallback");
            ((RealmCallback) callback).setText(realm);
        } else if (callback instanceof RealmChoiceCallback) {
            System.out.println("RealmChoiceCallback");
            RealmChoiceCallback choice = (RealmChoiceCallback) callback;
            if (realm == null) {
                choice.setSelectedIndex(choice.getDefaultChoice());
            } else {
                String[] choices = choice.getChoices();
                for (int j = 0; j < choices.length; j++) {
                    if (realm.equals(choices[j])) {
                        choice.setSelectedIndex(j);
                        break;
                    }
                }
            }
        } else if (callback instanceof AuthorizeCallback) {
            System.out.println("AuthorizeCallback");
            ((AuthorizeCallback) callback).setAuthorized(true);
            if (authId == null || authId.trim().length() == 0) {
                authId = userId;
            }
            ((AuthorizeCallback) callback).setAuthorizedID(authId);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #4
Source File: ClientCallbackHandler.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    // Special case for anonymous authentication to avoid prompting user for their name.
    if (callbacks.length == 1 && callbacks[0] instanceof NameCallback) {
        ((NameCallback) callbacks[0]).setName("anonymous demo user");
        return;
    }

    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            final RealmCallback rcb = (RealmCallback) current;
            final String defaultText = rcb.getDefaultText();
            rcb.setText(defaultText); // For now just use the realm suggested.

            prompt(defaultText);
        } else if (current instanceof RealmChoiceCallback) {
            throw new UnsupportedCallbackException(current, "Realm choice not currently supported.");
        } else if (current instanceof NameCallback) {
            final NameCallback ncb = (NameCallback) current;
            final String userName = obtainUsername("Username:");

            ncb.setName(userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            char[] password = obtainPassword("Password:");

            pcb.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example #5
Source File: SASLMechanism.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/** */
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];
      // Retrieve the REALM from the challenge response that the
      // server returned when the client initiated the authentication
      // exchange. If this value is not null or empty, *this value*
      // has to be sent back to the server in the client's response
      // to the server's challenge
      String text = rcb.getDefaultText();
      // The SASL client (sc) created in smack uses rcb.getText when
      // creating the negotiatedRealm to send it back to the server
      // Make sure that this value matches the server's realm
      rcb.setText(text);
    } else if (callbacks[i] instanceof RealmChoiceCallback) {
      // unused
      // RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
    } else {
      throw new UnsupportedCallbackException(callbacks[i]);
    }
  }
}
 
Example #6
Source File: ClientServerTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("NameCallback");
            ((NameCallback) callback).setName(userId);
        } else if (callback instanceof PasswordCallback) {
            System.out.println("PasswordCallback");
            ((PasswordCallback) callback).setPassword(passwd);
        } else if (callback instanceof RealmCallback) {
            System.out.println("RealmCallback");
            ((RealmCallback) callback).setText(realm);
        } else if (callback instanceof RealmChoiceCallback) {
            System.out.println("RealmChoiceCallback");
            RealmChoiceCallback choice = (RealmChoiceCallback) callback;
            if (realm == null) {
                choice.setSelectedIndex(choice.getDefaultChoice());
            } else {
                String[] choices = choice.getChoices();
                for (int j = 0; j < choices.length; j++) {
                    if (realm.equals(choices[j])) {
                        choice.setSelectedIndex(j);
                        break;
                    }
                }
            }
        } else if (callback instanceof AuthorizeCallback) {
            System.out.println("AuthorizeCallback");
            ((AuthorizeCallback) callback).setAuthorized(true);
            if (authId == null || authId.trim().length() == 0) {
                authId = userId;
            }
            ((AuthorizeCallback) callback).setAuthorizedID(authId);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #7
Source File: ClientServerTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("NameCallback");
            ((NameCallback) callback).setName(userId);
        } else if (callback instanceof PasswordCallback) {
            System.out.println("PasswordCallback");
            ((PasswordCallback) callback).setPassword(passwd);
        } else if (callback instanceof RealmCallback) {
            System.out.println("RealmCallback");
            ((RealmCallback) callback).setText(realm);
        } else if (callback instanceof RealmChoiceCallback) {
            System.out.println("RealmChoiceCallback");
            RealmChoiceCallback choice = (RealmChoiceCallback) callback;
            if (realm == null) {
                choice.setSelectedIndex(choice.getDefaultChoice());
            } else {
                String[] choices = choice.getChoices();
                for (int j = 0; j < choices.length; j++) {
                    if (realm.equals(choices[j])) {
                        choice.setSelectedIndex(j);
                        break;
                    }
                }
            }
        } else if (callback instanceof AuthorizeCallback) {
            System.out.println("AuthorizeCallback");
            ((AuthorizeCallback) callback).setAuthorized(true);
            if (authId == null || authId.trim().length() == 0) {
                authId = userId;
            }
            ((AuthorizeCallback) callback).setAuthorizedID(authId);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #8
Source File: ClientServerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("NameCallback");
            ((NameCallback) callback).setName(userId);
        } else if (callback instanceof PasswordCallback) {
            System.out.println("PasswordCallback");
            ((PasswordCallback) callback).setPassword(passwd);
        } else if (callback instanceof RealmCallback) {
            System.out.println("RealmCallback");
            ((RealmCallback) callback).setText(realm);
        } else if (callback instanceof RealmChoiceCallback) {
            System.out.println("RealmChoiceCallback");
            RealmChoiceCallback choice = (RealmChoiceCallback) callback;
            if (realm == null) {
                choice.setSelectedIndex(choice.getDefaultChoice());
            } else {
                String[] choices = choice.getChoices();
                for (int j = 0; j < choices.length; j++) {
                    if (realm.equals(choices[j])) {
                        choice.setSelectedIndex(j);
                        break;
                    }
                }
            }
        } else if (callback instanceof AuthorizeCallback) {
            System.out.println("AuthorizeCallback");
            ((AuthorizeCallback) callback).setAuthorized(true);
            if (authId == null || authId.trim().length() == 0) {
                authId = userId;
            }
            ((AuthorizeCallback) callback).setAuthorizedID(authId);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #9
Source File: ClientServerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("NameCallback");
            ((NameCallback) callback).setName(userId);
        } else if (callback instanceof PasswordCallback) {
            System.out.println("PasswordCallback");
            ((PasswordCallback) callback).setPassword(passwd);
        } else if (callback instanceof RealmCallback) {
            System.out.println("RealmCallback");
            ((RealmCallback) callback).setText(realm);
        } else if (callback instanceof RealmChoiceCallback) {
            System.out.println("RealmChoiceCallback");
            RealmChoiceCallback choice = (RealmChoiceCallback) callback;
            if (realm == null) {
                choice.setSelectedIndex(choice.getDefaultChoice());
            } else {
                String[] choices = choice.getChoices();
                for (int j = 0; j < choices.length; j++) {
                    if (realm.equals(choices[j])) {
                        choice.setSelectedIndex(j);
                        break;
                    }
                }
            }
        } else if (callback instanceof AuthorizeCallback) {
            System.out.println("AuthorizeCallback");
            ((AuthorizeCallback) callback).setAuthorized(true);
            if (authId == null || authId.trim().length() == 0) {
                authId = userId;
            }
            ((AuthorizeCallback) callback).setAuthorizedID(authId);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #10
Source File: ClientServerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("NameCallback");
            ((NameCallback) callback).setName(userId);
        } else if (callback instanceof PasswordCallback) {
            System.out.println("PasswordCallback");
            ((PasswordCallback) callback).setPassword(passwd);
        } else if (callback instanceof RealmCallback) {
            System.out.println("RealmCallback");
            ((RealmCallback) callback).setText(realm);
        } else if (callback instanceof RealmChoiceCallback) {
            System.out.println("RealmChoiceCallback");
            RealmChoiceCallback choice = (RealmChoiceCallback) callback;
            if (realm == null) {
                choice.setSelectedIndex(choice.getDefaultChoice());
            } else {
                String[] choices = choice.getChoices();
                for (int j = 0; j < choices.length; j++) {
                    if (realm.equals(choices[j])) {
                        choice.setSelectedIndex(j);
                        break;
                    }
                }
            }
        } else if (callback instanceof AuthorizeCallback) {
            System.out.println("AuthorizeCallback");
            ((AuthorizeCallback) callback).setAuthorized(true);
            if (authId == null || authId.trim().length() == 0) {
                authId = userId;
            }
            ((AuthorizeCallback) callback).setAuthorizedID(authId);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #11
Source File: ClientServerTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("NameCallback");
            ((NameCallback) callback).setName(userId);
        } else if (callback instanceof PasswordCallback) {
            System.out.println("PasswordCallback");
            ((PasswordCallback) callback).setPassword(passwd);
        } else if (callback instanceof RealmCallback) {
            System.out.println("RealmCallback");
            ((RealmCallback) callback).setText(realm);
        } else if (callback instanceof RealmChoiceCallback) {
            System.out.println("RealmChoiceCallback");
            RealmChoiceCallback choice = (RealmChoiceCallback) callback;
            if (realm == null) {
                choice.setSelectedIndex(choice.getDefaultChoice());
            } else {
                String[] choices = choice.getChoices();
                for (int j = 0; j < choices.length; j++) {
                    if (realm.equals(choices[j])) {
                        choice.setSelectedIndex(j);
                        break;
                    }
                }
            }
        } else if (callback instanceof AuthorizeCallback) {
            System.out.println("AuthorizeCallback");
            ((AuthorizeCallback) callback).setAuthorized(true);
            if (authId == null || authId.trim().length() == 0) {
                authId = userId;
            }
            ((AuthorizeCallback) callback).setAuthorizedID(authId);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #12
Source File: ClientServerTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("NameCallback");
            ((NameCallback) callback).setName(userId);
        } else if (callback instanceof PasswordCallback) {
            System.out.println("PasswordCallback");
            ((PasswordCallback) callback).setPassword(passwd);
        } else if (callback instanceof RealmCallback) {
            System.out.println("RealmCallback");
            ((RealmCallback) callback).setText(realm);
        } else if (callback instanceof RealmChoiceCallback) {
            System.out.println("RealmChoiceCallback");
            RealmChoiceCallback choice = (RealmChoiceCallback) callback;
            if (realm == null) {
                choice.setSelectedIndex(choice.getDefaultChoice());
            } else {
                String[] choices = choice.getChoices();
                for (int j = 0; j < choices.length; j++) {
                    if (realm.equals(choices[j])) {
                        choice.setSelectedIndex(j);
                        break;
                    }
                }
            }
        } else if (callback instanceof AuthorizeCallback) {
            System.out.println("AuthorizeCallback");
            ((AuthorizeCallback) callback).setAuthorized(true);
            if (authId == null || authId.trim().length() == 0) {
                authId = userId;
            }
            ((AuthorizeCallback) callback).setAuthorizedID(authId);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #13
Source File: DefaultCallbackHandler.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #14
Source File: DefaultCallbackHandler.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #15
Source File: SASLJavaXMechanism.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
protected void authenticateInternal()
                throws SmackJavaxSaslException {
    String[] mechanisms = { getName() };
    Map<String, String> props = getSaslProps();
    String authzid = null;
    if (authorizationId != null) {
        authzid = authorizationId.toString();
    }
    try {
        sc = Sasl.createSaslClient(mechanisms, authzid, "xmpp", getServerName().toString(), props,
                        new CallbackHandler() {
                            @Override
                            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];
                                        // Retrieve the REALM from the challenge response that
                                        // the server returned when the client initiated the
                                        // authentication exchange. If this value is not null or
                                        // empty, *this value* has to be sent back to the server
                                        // in the client's response to the server's challenge
                                        String text = rcb.getDefaultText();
                                        // The SASL client (sc) created in smack uses
                                        // rcb.getText when creating the negotiatedRealm to send
                                        // it back to the server. Make sure that this value
                                        // matches the server's realm
                                        rcb.setText(text);
                                    }
                                    else if (callbacks[i] instanceof RealmChoiceCallback) {
                                        // unused, prevents UnsupportedCallbackException
                                        // RealmChoiceCallback rccb =
                                        // (RealmChoiceCallback)callbacks[i];
                                    }
                                    else {
                                        throw new UnsupportedCallbackException(callbacks[i]);
                                    }
                                }
                            }

                        });
    }
    catch (SaslException e) {
        throw new SmackJavaxSaslException(e);
    }
}
 
Example #16
Source File: DefaultCallbackHandler.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #17
Source File: DefaultCallbackHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #18
Source File: DefaultCallbackHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #19
Source File: DefaultCallbackHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #20
Source File: DefaultCallbackHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #21
Source File: DefaultCallbackHandler.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #22
Source File: DefaultCallbackHandler.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #23
Source File: DefaultCallbackHandler.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #24
Source File: DefaultCallbackHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #25
Source File: DefaultCallbackHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuffer allChoices = new StringBuffer();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j] + ",");
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}
 
Example #26
Source File: SaslCallbackHandler.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException
{
    for ( Callback cb : callbacks )
    {
        if ( cb instanceof NameCallback )
        {
            NameCallback ncb = ( NameCallback ) cb;

            String name = saslReq.getUsername();
            
            if ( LOG.isDebugEnabled() )
            {
                LOG.debug( I18n.msg( I18n.MSG_04153_SENDING_NAME_IN_CALLBACK, name ) );
            }
            
            ncb.setName( name );
        }
        else if ( cb instanceof PasswordCallback )
        {
            PasswordCallback pcb = ( PasswordCallback ) cb;

            if ( LOG.isDebugEnabled() )
            {
                LOG.debug( I18n.msg( I18n.MSG_04154_SENDING_CREDS_IN_CALLBACK ) );
            }
            
            pcb.setPassword( Strings.utf8ToString( saslReq.getCredentials() ).toCharArray() );
        }
        else if ( cb instanceof RealmCallback )
        {
            RealmCallback rcb = ( RealmCallback ) cb;

            if ( saslReq.getRealmName() != null )
            {
                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( I18n.msg( I18n.MSG_04155_SENDING_USER_REALM_IN_CALLBACK, saslReq.getRealmName() ) );
                }
                
                rcb.setText( saslReq.getRealmName() );
            }
            else
            {
                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( I18n.msg( I18n.MSG_04156_SENDING_DEFAULT_REALM_IN_CALLBACK, rcb.getDefaultText() ) );
                }
                
                rcb.setText( rcb.getDefaultText() );
            }
        }
        else if ( cb instanceof RealmChoiceCallback )
        {
            RealmChoiceCallback rccb = ( RealmChoiceCallback ) cb;

            boolean foundRealmName = false;

            String[] realmNames = rccb.getChoices();
            for ( int i = 0; i < realmNames.length; i++ )
            {
                String realmName = realmNames[i];
                if ( realmName.equals( saslReq.getRealmName() ) )
                {
                    foundRealmName = true;

                    if ( LOG.isDebugEnabled() )
                    {
                        LOG.debug( I18n.msg( I18n.MSG_04157_SENDING_USER_REALM_IN_CALLBACK, realmName ) );
                    }
                    
                    rccb.setSelectedIndex( i );
                    break;
                }
            }

            if ( !foundRealmName )
            {
                throw new IOException(
                    I18n.err( I18n.ERR_04171_CANNOT_PARSE_MATCHED_DN,
                        saslReq.getRealmName(), getRealmNamesAsString( realmNames ) ) );
            }
        }
    }
}
 
Example #27
Source File: DefaultCallbackHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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(authenticationID);

            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback)callbacks[i]).setPassword(passwd);

            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                /* Deals with a choice of realms */
                String[] choices =
                    ((RealmChoiceCallback)callbacks[i]).getChoices();
                int selected = 0;

                if (authRealm != null && authRealm.length() > 0) {
                    selected = -1; // no realm chosen
                    for (int j = 0; j < choices.length; j++) {
                        if (choices[j].equals(authRealm)) {
                            selected = j;
                        }
                    }
                    if (selected == -1) {
                        StringBuilder allChoices = new StringBuilder();
                        for (int j = 0; j <  choices.length; j++) {
                            allChoices.append(choices[j]).append(',');
                        }
                        throw new IOException("Cannot match " +
                            "'java.naming.security.sasl.realm' property value, '" +
                            authRealm + "' with choices " + allChoices +
                            "in RealmChoiceCallback");
                    }
                }

                ((RealmChoiceCallback)callbacks[i]).setSelectedIndex(selected);

            } else if (callbacks[i] instanceof RealmCallback) {
                /* 1 or 0 realms specified in challenge */
                RealmCallback rcb = (RealmCallback) callbacks[i];
                if (authRealm != null) {
                    rcb.setText(authRealm);  // Use what user supplied
                } else {
                    String defaultRealm = rcb.getDefaultText();
                    if (defaultRealm != null) {
                        rcb.setText(defaultRealm); // Use what server supplied
                    } else {
                        rcb.setText("");  // Specify no realm
                    }
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
}