Package javax.security.sasl

Examples of javax.security.sasl.RealmCallback


    public void handle(Callback[] callbacks)
        throws UnsupportedCallbackException {
      NameCallback nc = null;
      PasswordCallback pc = null;
      RealmCallback rc = null;
      for (Callback callback : callbacks) {
        if (callback instanceof RealmChoiceCallback) {
          continue;
        } else if (callback instanceof NameCallback) {
          nc = (NameCallback) callback;
        } else if (callback instanceof PasswordCallback) {
          pc = (PasswordCallback) callback;
        } else if (callback instanceof RealmCallback) {
          rc = (RealmCallback) callback;
        } else {
          throw new UnsupportedCallbackException(callback,
              "Unrecognized SASL client callback");
        }
      }
      if (nc != null) {
        if (LOG.isDebugEnabled())
          LOG.debug("SASL client callback: setting username: " + userName);
        nc.setName(userName);
      }
      if (pc != null) {
        if (LOG.isDebugEnabled())
          LOG.debug("SASL client callback: setting userPassword");
        pc.setPassword(userPassword);
      }
      if (rc != null) {
        if (LOG.isDebugEnabled())
          LOG.debug("SASL client callback: setting realm: "
              + rc.getDefaultText());
        rc.setText(rc.getDefaultText());
      }
    }
View Full Code Here


    when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
    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);
View Full Code Here

                username = nameCB.getDefaultName();
            }
            else if ( callback instanceof RealmCallback )
            {
                RealmCallback realmCB = ( RealmCallback ) callback;
                LOG.debug( "RealmCallback default text:  {}", realmCB.getDefaultText() );

                realm = realmCB.getDefaultText();
            }
            else if ( callback instanceof PasswordCallback )
            {
                PasswordCallback passwordCB = ( PasswordCallback ) callback;
                Attribute userPassword = lookupPassword( getUsername(), getRealm() );
View Full Code Here

     * Assertion: throws IllegalArgumentException if parameters are
     * null or empty String
     */
    public void test01() {
        try {
            new RealmCallback(null, "def");
            fail("IllegalArgumentException should be thrown for null prompt");
        } catch (IllegalArgumentException e) {
        }
        try {
            new RealmCallback("", "def");
            fail("IllegalArgumentException should be thrown for empty prompt");
        } catch (IllegalArgumentException e) {
        }
        try {
            new RealmCallback("prompt", null);
            fail("IllegalArgumentException should be thrown for null default info");
        } catch (IllegalArgumentException e) {
        }
        try {
            new RealmCallback("prompt", "");
            fail("IllegalArgumentException should be thrown for empty default info");
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here

    public void test02() {
        String[] defInfo = {
                "DefaultRealmInfo",
                "Another default realm info",
                "Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info Long string for default realm info " };
        RealmCallback rCB;
        StringBuffer sb = new StringBuffer("");
        String ss;
        for (int i = 0; i < prompts.length; i++) {
            for (int j = 0; j < prompts.length; j++) {
                rCB = new RealmCallback(prompts[i], defInfo[j]);
                assertEquals("Incorrect default info", rCB.getDefaultText(),
                        defInfo[j]);
                assertEquals("Incorrect prompt", rCB.getPrompt(), prompts[i]);
                assertNull("Not null text", rCB.getText());
                sb.replace(0, sb.length(), prompts[i]);
                sb.append(defInfo[j]);
                ss = sb.toString();
                rCB.setText(ss);
                assertEquals("Incorrect text", rCB.getText(), ss);
                rCB.setText(null);
                assertNull("Not null text", rCB.getText());
            }
        }
    }
View Full Code Here

    /**
     * Test for <code>RealmCallback(String prompt)</code> constructor
     * Assertion: creates instance of RealmCallback object
     */
    public void test04() {
        RealmCallback rCB;
        StringBuffer sb = new StringBuffer("");
        String ss;
        for (int i = 0; i < prompts.length; i++) {
            rCB = new RealmCallback(prompts[i]);
            assertNull("Incorrect default info", rCB.getDefaultText());
            assertEquals("Incorrect prompt", rCB.getPrompt(), prompts[i]);
            assertNull("Not null text", rCB.getText());
            sb = new StringBuffer(prompts[i]);
            sb.replace(0, sb.length(), prompts[i]);
            ss = sb.toString();
            rCB.setText(ss);
            assertEquals("Incorrect text", rCB.getText(), ss);
            rCB.setText(null);
            assertNull("Not null text", rCB.getText());
        }
        }
View Full Code Here

    public static String addText = "This text was set to RealmCallback";
   
    @Override
    protected Object[] getData() {
        Object [] oo = {
                new RealmCallback(msgs[0], msgs[1]),
                new RealmCallback(msgs[1], msgs[0]),
                new RealmCallback(msgs[1], msgs[1])
        };
        for (Object element : oo) {
            ((RealmCallback)element).setText(addText);
        }
        return oo;
View Full Code Here

        }
        return oo;
    }

    public void assertDeserialized(Serializable oref, Serializable otest) {
        RealmCallback ref = (RealmCallback) oref;
        RealmCallback test = (RealmCallback) otest;
        String dText = ref.getDefaultText();
        String text = ref.getText();
        String prompt = ref.getPrompt();
        assertEquals(dText, test.getDefaultText());
        assertEquals(text, test.getText());
        assertEquals(prompt, test.getPrompt());

    }
View Full Code Here

            if (callbacks[i] instanceof RealmChoiceCallback) {
                // TODO what to do here?
                // RealmChoiceCallback rcc = (RealmChoiceCallback) callbacks[i];

            } else if (callbacks[i] instanceof RealmCallback) {
                RealmCallback rc = (RealmCallback) callbacks[i];
                if (env.get(JAVA_NAMING_SECURITY_SASL_REALM) != null) {
                    realm = (String) env.get(JAVA_NAMING_SECURITY_SASL_REALM);
                    rc.setText(realm);
                } else {
                    rc.setText(realm);
                }
            } else if (callbacks[i] instanceof PasswordCallback) {
                PasswordCallback pc = (PasswordCallback) callbacks[i];
                pc.setPassword(Utils.getCharArray(env
                        .get(Context.SECURITY_CREDENTIALS)));
View Full Code Here

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

TOP

Related Classes of javax.security.sasl.RealmCallback

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.