當前位置: 首頁>>代碼示例>>Java>>正文


Java RealmChoiceCallback.getChoices方法代碼示例

本文整理匯總了Java中javax.security.sasl.RealmChoiceCallback.getChoices方法的典型用法代碼示例。如果您正苦於以下問題:Java RealmChoiceCallback.getChoices方法的具體用法?Java RealmChoiceCallback.getChoices怎麽用?Java RealmChoiceCallback.getChoices使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.security.sasl.RealmChoiceCallback的用法示例。


在下文中一共展示了RealmChoiceCallback.getChoices方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handle

import javax.security.sasl.RealmChoiceCallback; //導入方法依賴的package包/類
@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);
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:40,代碼來源:ClientServerTest.java

示例2: assertDeserialized

import javax.security.sasl.RealmChoiceCallback; //導入方法依賴的package包/類
public void assertDeserialized(Serializable oref, Serializable otest) {
        RealmChoiceCallback ref = (RealmChoiceCallback) oref;
        RealmChoiceCallback test = (RealmChoiceCallback) otest;
        
        boolean all = ref.allowMultipleSelections();
        assertEquals(all, test.allowMultipleSelections());
        String prompt = ref.getPrompt();
        assertEquals(prompt, test.getPrompt());
        
        String [] ch = ref.getChoices();
        String [] tCh = test.getChoices();        
        assertEquals(ch.length, tCh.length);        
        for (int i = 0; i < ch.length; i++) {
            assertEquals(ch[i], tCh[i]);
        }
        assertEquals(ref.getDefaultChoice(), test.getDefaultChoice());
        int [] in = ref.getSelectedIndexes();
        int [] tIn = test.getSelectedIndexes();
//        assertNull("in is not null", in);            
//        assertNull("tIn is not null", tIn);

        if (!all) {
            assertEquals("Incorrect length in ", in.length, 1);
            assertEquals("Incorrect length tIn ", tIn.length, 1);
            assertEquals("Incorrect index", in[0], tIn[0]);
        } else {
            assertEquals("Incorrect length", in.length, tIn.length);
            for (int i = 0; i < in.length; i++) {
                assertEquals(in[i], tIn[i]);
            }            
        }
    }
 
開發者ID:shannah,項目名稱:cn1,代碼行數:33,代碼來源:RealmChoiceCallbackTest.java

示例3: handle

import javax.security.sasl.RealmChoiceCallback; //導入方法依賴的package包/類
/**
 * {@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();
            LOG.debug( "sending name {} in the NameCallback", name );
            ncb.setName( name );
        }
        else if ( cb instanceof PasswordCallback )
        {
            PasswordCallback pcb = ( PasswordCallback ) cb;

            LOG.debug( "sending credentials in the PasswordCallback" );
            pcb.setPassword( Strings.utf8ToString( saslReq.getCredentials() ).toCharArray() );
        }
        else if ( cb instanceof RealmCallback )
        {
            RealmCallback rcb = ( RealmCallback ) cb;

            if ( saslReq.getRealmName() != null )
            {
                LOG.debug( "sending the user specified realm value {} in the RealmCallback", saslReq.getRealmName() );
                rcb.setText( saslReq.getRealmName() );
            }
            else
            {
                LOG.debug(
                    "No user specified relam value, sending the default realm value {} in the RealmCallback",
                    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;

                    LOG.debug( "sending the user specified realm value {} in the RealmChoiceCallback", realmName );
                    rccb.setSelectedIndex( i );
                    break;
                }
            }

            if ( !foundRealmName )
            {
                throw new IOException(
                    I18n.format(
                        "Cannot match ''java.naming.security.sasl.realm'' property value ''{0}'' with choices ''{1}'' in RealmChoiceCallback.",
                        saslReq.getRealmName(), getRealmNamesAsString( realmNames ) ) );
            }
        }
    }
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:71,代碼來源:SaslCallbackHandler.java


注:本文中的javax.security.sasl.RealmChoiceCallback.getChoices方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。