Package javax.security.sasl

Examples of javax.security.sasl.RealmChoiceCallback


     *
     * Assertion: creates RealmChoiceCallback object which allows
     * multiple choices
     */
    public void test03() {
        RealmChoiceCallback rCCB;
        for (int i = 0; i < prompts.length; i++) {
            rCCB = new RealmChoiceCallback(prompts[i], choices, 0, true);
            assertEquals("Incorrect prompt", rCCB.getPrompt(), prompts[i]);
            String[] ch = rCCB.getChoices();
            assertEquals("Incorrect choices length", ch.length, choices.length);
            for (int j = 0; j < ch.length; j++) {
                assertEquals("Incorrect choice number: " + j, ch[j], choices[j]);
            }
            assertTrue("Incorrect multiple", rCCB.allowMultipleSelections());
            int[] ind = rCCB.getSelectedIndexes();
            assertNull("Incorrect selected indexes", ind);
            rCCB.setSelectedIndexes(indexes);
            ind = rCCB.getSelectedIndexes();
            assertEquals("Incorrect index length", ind.length, indexes.length);
            for (int j = 0; j < indexes.length; j++) {
                assertEquals("Incorrect index number: " + Integer.toString(j),
                        ind[j], indexes[j]);
            }
            for (int j = indexes.length - 1; j >= 0; j--) {
                rCCB.setSelectedIndex(indexes[j]);
                ind = rCCB.getSelectedIndexes();
                assertEquals("Incorrect index length", ind.length, 1);
                assertEquals("Incorrect index", ind[0], indexes[j]);
            }
            rCCB.setSelectedIndexes(indexes);
            ind = rCCB.getSelectedIndexes();
            assertEquals("Incorrect index length", ind.length, indexes.length);
            for (int j = 0; j < indexes.length; j++) {
                assertEquals("Incorrect index number: " + Integer.toString(j),
                        ind[j], indexes[j]);
            }
            rCCB.setSelectedIndexes(null);
            assertNull("Incorrect indexes array", rCCB.getSelectedIndexes());
        }
    }
View Full Code Here


    public static final int [] idx = {2, 3};
   
    @Override
    protected Object[] getData() {
        Object [] oo = {
                new RealmChoiceCallback(msgs[0], msgs, 0, true),
                new RealmChoiceCallback(msgs[1], msgs, 1, true),
                new RealmChoiceCallback(msgs[1], msgs, 0, false),
                new RealmChoiceCallback(msgs[2], msgs, 0, false)

        };       
        for (Object element : oo) {
            RealmChoiceCallback rc = (RealmChoiceCallback)element;          
            if (rc.allowMultipleSelections()) {
                rc.setSelectedIndexes(idx);
            } else {
                rc.setSelectedIndex(msgs.length - 1);
            }
        }
        return oo;
    }
View Full Code Here

        }
        return oo;
    }

    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);
View Full Code Here

                    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 )
View Full Code Here

    when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());

    final NameCallback nameCallback = mock(NameCallback.class);
    final PasswordCallback passwordCallback = mock(PasswordCallback.class);
    final RealmCallback realmCallback = mock(RealmCallback.class);
    final RealmChoiceCallback realmChoiceCallback = mock(RealmChoiceCallback.class);

    Callback[] callbackArray = {nameCallback, passwordCallback,
        realmCallback, realmChoiceCallback};
    final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
    saslClCallbackHandler.handle(callbackArray);
View Full Code Here

    public void handle(Callback[] callbacks) throws UnsupportedCallbackException,
    IOException {
        NameCallback ncb = null;
        PasswordCallback pcb = null;
        RealmChoiceCallback rccb = null;

        List namePw = new ArrayList(3);

        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                if (auto) {
                    ((NameCallback)callbacks[i]).setName(username);
                } else {
                    // To be processed by TextCallbackHandler
                    namePw.add(callbacks[i]);
                }
            } else if (callbacks[i] instanceof PasswordCallback) {
                if (auto) {
                    ((PasswordCallback)callbacks[i]).setPassword(
                        password.toCharArray());
                } else {
                    // To be processed by TextCallbackHandler
                    namePw.add(callbacks[i]);
                }
            } else if (callbacks[i] instanceof RealmChoiceCallback) {
                RealmChoiceCallback rcb = (RealmChoiceCallback) callbacks[i];
                if (!auto) {
                    System.err.println(rcb.getPrompt());
                }

                String[] choices = rcb.getChoices();

                if (!auto) {
                    for (int j=0; j < choices.length; j++) {
                        System.err.println(j + ":" + choices[j]);
                    }
                }

                int selection;
                if (auto) {
                    selection = 0;
                } else {
                    System.err.print("Enter choice number: ");
                    String result = readLine();
                    if (result.equals("")) {
                        selection = rcb.getDefaultChoice();
                    } else {
                        selection = Integer.parseInt(result);
                    }
                }
                rcb.setSelectedIndex(selection);

            } else if (callbacks[i] instanceof RealmCallback) {
                RealmCallback rcb = (RealmCallback) callbacks[i];
                String realm = rcb.getDefaultText();

                if (auto) {
                    if (realm != null) {
                        rcb.setText(realm);
                    }
                } else {
                    if (realm == null) {
                        System.err.print(rcb.getPrompt());
                    } else {
                        System.err.print(rcb.getPrompt() + " [" + realm + "] ");
                    }

                    System.err.flush();

                    String result = readLine();
                    if (result.equals("")) {
                        result = realm;
                    }
                    rcb.setText(result);
                }
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
View Full Code Here

TOP

Related Classes of javax.security.sasl.RealmChoiceCallback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.