Java Code Examples for javax.security.sasl.RealmChoiceCallback#setSelectedIndex()

The following examples show how to use javax.security.sasl.RealmChoiceCallback#setSelectedIndex() . 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: 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 2
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 3
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 4
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 5
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 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 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 9
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 ) ) );
            }
        }
    }
}