Package javax.security.sasl

Examples of javax.security.sasl.RealmChoiceCallback


    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

     * string parameters are null or empty and if defaultChoice is not
     * within of choices array
     */
    public void test01() {
        try {
            new RealmChoiceCallback(null, choices, 0, true);
            fail("IllegalArgumentException should be thrown for null prompt");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("", choices, 0, true);
            fail("IllegalArgumentException should be thrown for empty prompt");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", null, 0, true);
            fail("IllegalArgumentException should be thrown for null choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", emptyCh, 0, true);
            fail("IllegalArgumentException should be thrown for empty choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", wrongCh1, 0, true);
            fail("IllegalArgumentException should be thrown for incorrect choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", wrongCh2, 0, false);
            fail("IllegalArgumentException should be thrown for incorrect choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", choices, -1, true);
            fail("IllegalArgumentException should be thrown for incorrect choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", choices, choices.length, true);
            fail("IllegalArgumentException should be thrown for incorrect default index");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", choices, choices.length + 1, true);
            fail("IllegalArgumentException should be thrown for incorrect default index");
        } catch (IllegalArgumentException e) {           
        }
    }
View Full Code Here

     *
     * Assertion: creates RealmChoiceCallback object which does not allow
     * multiple choices
     */
    public void test02() {
        RealmChoiceCallback rCCB;
        for (int i = 0; i < prompts.length; i++) {
            rCCB = new RealmChoiceCallback(prompts[i], choices, 0, false);
            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]);               
            }
            assertFalse("Incorrect multiple", rCCB.allowMultipleSelections());
            int [] ind = rCCB.getSelectedIndexes();
            assertNull("Incorrect selected indexes", ind);
            ind = new int[3];
            try {
                rCCB.setSelectedIndexes(ind);
                fail("UnsupportedOperationException should be thrown for non-multiple callback");
            } catch (UnsupportedOperationException e) {
            }
            try {
                rCCB.setSelectedIndexes(null);
                fail("UnsupportedOperationException should be thrown for non-multiple callback");
            } catch (UnsupportedOperationException e) {
            }
            for (int j = 0; j < indexes.length; j++) {
                rCCB.setSelectedIndex(indexes[j]);
                ind = rCCB.getSelectedIndexes();
                assertEquals("Incorrect index length", ind.length, 1);
                assertEquals("Incorrect index", ind[0], indexes[j]);
            }
        }       
    }
View Full Code Here

     *
     * 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

    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

                    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

     * string parameters are null or empty and if defaultChoice is not
     * within of choices array
     */
    public void test01() {
        try {
            new RealmChoiceCallback(null, choices, 0, true);
            fail("IllegalArgumentException should be thrown for null prompt");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("", choices, 0, true);
            fail("IllegalArgumentException should be thrown for empty prompt");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", null, 0, true);
            fail("IllegalArgumentException should be thrown for null choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", emptyCh, 0, true);
            fail("IllegalArgumentException should be thrown for empty choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", wrongCh1, 0, true);
            fail("IllegalArgumentException should be thrown for incorrect choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", wrongCh2, 0, false);
            fail("IllegalArgumentException should be thrown for incorrect choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", choices, -1, true);
            fail("IllegalArgumentException should be thrown for incorrect choices");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", choices, choices.length, true);
            fail("IllegalArgumentException should be thrown for incorrect default index");
        } catch (IllegalArgumentException e) {           
        }
        try {
            new RealmChoiceCallback("prompt", choices, choices.length + 1, true);
            fail("IllegalArgumentException should be thrown for incorrect default index");
        } catch (IllegalArgumentException e) {           
        }
    }
View Full Code Here

     *
     * Assertion: creates RealmChoiceCallback object which does not allow
     * multiple choices
     */
    public void test02() {
        RealmChoiceCallback rCCB;
        for (int i = 0; i < prompts.length; i++) {
            rCCB = new RealmChoiceCallback(prompts[i], choices, 0, false);
            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]);               
            }
            assertFalse("Incorrect multiple", rCCB.allowMultipleSelections());
            int [] ind = rCCB.getSelectedIndexes();
            assertNull("Incorrect selected indexes", ind);
            ind = new int[3];
            try {
                rCCB.setSelectedIndexes(ind);
                fail("UnsupportedOperationException should be thrown for non-multiple callback");
            } catch (UnsupportedOperationException e) {
            }
            try {
                rCCB.setSelectedIndexes(null);
                fail("UnsupportedOperationException should be thrown for non-multiple callback");
            } catch (UnsupportedOperationException e) {
            }
            for (int j = 0; j < indexes.length; j++) {
                rCCB.setSelectedIndex(indexes[j]);
                ind = rCCB.getSelectedIndexes();
                assertEquals("Incorrect index length", ind.length, 1);
                assertEquals("Incorrect index", ind[0], indexes[j]);
            }
        }       
    }
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.