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


                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

    @Override
    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

     * 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

     * Assertion: throws IllegalArgumentException if parameter is null or empty
     * string
     */
    public void test03() {
        try {
            new RealmCallback(null);
            fail("IllegalArgumentException should be thrown for null prompt");
        } catch (IllegalArgumentException e) {
        }
        try {
            new RealmCallback("");
            fail("IllegalArgumentException should be thrown for empty prompt");
        } catch (IllegalArgumentException e) {
        }
    }
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

                ncb.setName(credentials[0]);
            } else if (current instanceof PasswordCallback) {
                PasswordCallback pcb = (PasswordCallback) current;
                pcb.setPassword(credentials[1].toCharArray());
            } else if (current instanceof RealmCallback) {
                RealmCallback realmCallback = (RealmCallback) current;
                realmCallback.setText(realmCallback.getDefaultText());
            } else {
                throw new UnsupportedCallbackException(current);
            }
        }
View Full Code Here

                    return;
                }

                for (Callback current : callbacks) {
                    if (current instanceof RealmCallback) {
                        RealmCallback rcb = (RealmCallback) current;
                        String defaultText = rcb.getDefaultText();
                        rcb.setText(defaultText); // For now just use the realm suggested.
                        if (realmShown == false) {
                            realmShown = true;
                            printLine("Authenticating against security realm: " + defaultText);
                        }
                    } else if (current instanceof RealmChoiceCallback) {
View Full Code Here


        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback current : callbacks) {
                if (current instanceof RealmCallback) {
                    RealmCallback rcb = (RealmCallback) current;
                    String defaultText = rcb.getDefaultText();
                    rcb.setText(defaultText); // For now just use the realm suggested.
                } else if (current instanceof RealmChoiceCallback) {
                    throw MESSAGES.realmNotSupported(current);
                } else if (current instanceof NameCallback) {
                    NameCallback ncb = (NameCallback) current;
                    ncb.setName(userName);
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.