PasswordCallback setPassword - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PasswordCallback setPassword method.

This code example shows how to use the following methods:clearPassword, getPassword, getPrompt, isEchoOn, setPassword
public class PasswordCallbackTest extends TestCase {
 
    PasswordCallback pc;
 
    public final void testPasswordCallback() { 
        pc = new PasswordCallback("prompt", true);
        assertEquals("prompt", pc.getPrompt());
        assertTrue(pc.isEchoOn());
        pc.setPassword(null);
        pc.clearPassword();
        assertNull(pc.getPassword());
        char[] pwd = {'a','b','c'};
        pc.setPassword(pwd);
        assertEquals(new String(pwd), new String(pc.getPassword()));
        pc.clearPassword();
        assertEquals(pwd.length, pc.getPassword().length);
        assertFalse(new String(pwd).equals(pc.getPassword()));
        char[] p = new char[5];
        pc.setPassword(p);
        pc.clearPassword();

7
CodeRank
This code example shows how to use the following methods:setPassword
        SerializationTest.SerializableAssert { 
 
    @Override 
    protected Object[] getData() {
        char[] pwd = {'a', 'b', 'c'};
        PasswordCallback p = new PasswordCallback("prmpt", true);
        p.setPassword(pwd);
        return new Object[] { new PasswordCallback("prompt", true), p };
    } 
 
   
    public void assertDeserialized(Serializable golden, Serializable test) {
        assertTrue(test instanceof PasswordCallback);
        assertEquals(((PasswordCallback) golden).getPrompt(),
                ((PasswordCallback) test).getPrompt());
        if (((PasswordCallback) test).getPassword() != null) {
            assertEquals(new String(((PasswordCallback) golden)
                    .getPassword()), new String(
                    ((PasswordCallback) test).getPassword()));
        } 
5
CodeRank
This code example shows how to use the following methods:setPassword
    } 
 
    private void handlePasswordCallback(PasswordCallback pc) {
        if ("super".equals(this.userName) && System.getProperty(SYSPROP_SUPER_PASSWORD) != null) {
            // superuser: use Java system property for password, if available. 
            pc.setPassword(System.getProperty(SYSPROP_SUPER_PASSWORD).toCharArray());
        } else if (credentials.containsKey(userName) ) {
            pc.setPassword(credentials.get(userName).toCharArray());
        } else { 
            LOG.warn("No password found for user: " + userName);
        } 
    } 
 
    private void handleRealmCallback(RealmCallback rc) {
        LOG.debug("client supplied realm: " + rc.getDefaultText());
        rc.setText(rc.getDefaultText());
    } 
 
    private void handleAuthorizeCallback(AuthorizeCallback ac) {
        String authenticationID = ac.getAuthenticationID();
5
CodeRank
This code example shows how to use the following methods:setPassword
     */ 
    public void handle(Callback callback, Authentication auth)
        throws IOException, UnsupportedCallbackException {
        if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(auth.getCredentials().toString().toCharArray());
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getPrompt, isEchoOn, setPassword
 
  protected synchronized void handlePassword(PasswordCallback c)
  { 
    Frame ownerFrame = new Frame();
    Dialog dialog = new Dialog(ownerFrame);
    dialog.setTitle(c.getPrompt());
    dialog.setLayout(new GridLayout(3, 1));
    Label label = new Label(c.getPrompt());
    TextField input = new TextField();
    if (!c.isEchoOn())
      { 
        input.setEchoChar('*');
      } 
    Panel buttons = new Panel();
    Button ok = new Button(messages.getString("callback.ok"));
    ok.setActionCommand(ACTION_OK);
    ok.addActionListener(this);
    Button cancel = new Button(messages.getString("callback.cancel"));
    cancel.setActionCommand(ACTION_CANCEL);
    cancel.addActionListener(this);

5
CodeRank
This code example shows how to use the following methods:getPrompt, setPassword
      c.setName(name.trim());
  } 
 
  protected void handlePassword(PasswordCallback c) throws IOException
  { 
    out.print(c.getPrompt());
    BufferedReader in =
      new BufferedReader(new InputStreamReader(System.in));
    String pass = in.readLine();
    c.setPassword(pass.toCharArray());
  } 
 
  protected void handleTextInput(TextInputCallback c) throws IOException
  { 
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    out.print(c.getPrompt());
    String text = in.readLine();
    if (text != null)
      c.setText(text);
  } 
5
CodeRank
This code example shows how to use the following methods:setPassword
        // [enddef] 
        if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
 
            if (getRequest().getChallengeResponse() != null) { 
                pc.setPassword(getRequest().getChallengeResponse().getSecret());
            } 
        } else { 
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback"); 
        } 
    } 
 
    /** 
     * Handles the callbacks. The default implementation delegates the handling 
     * to the {@link #handle(Callback)} method. 
     *  
     * @param callbacks 
     *            The callbacks to handle. 
     */ 
5
CodeRank
This code example shows how to use the following methods:setPassword
    } 
 
    private void handlePasswordCallback(PasswordCallback pc) {
        if ("super".equals(this.userName) && System.getProperty(SYSPROP_SUPER_PASSWORD) != null) {
            // superuser: use Java system property for password, if available. 
            pc.setPassword(System.getProperty(SYSPROP_SUPER_PASSWORD).toCharArray());
        } else if (credentials.containsKey(userName) ) {
            pc.setPassword(credentials.get(userName).toCharArray());
        } else { 
            LOG.warn("No password found for user: " + userName);
        } 
    } 
 
    private void handleRealmCallback(RealmCallback rc) {
        LOG.debug("client supplied realm: " + rc.getDefaultText());
        rc.setText(rc.getDefaultText());
    } 
 
    private void handleAuthorizeCallback(AuthorizeCallback ac) {
        String authenticationID = ac.getAuthenticationID();
4
CodeRank
This code example shows how to use the following methods:setPassword
    } 
 
    private void handlePasswordCallback(PasswordCallback pc) {
        if ("super".equals(this.userName) && System.getProperty(SYSPROP_SUPER_PASSWORD) != null) {
            // superuser: use Java system property for password, if available. 
            pc.setPassword(System.getProperty(SYSPROP_SUPER_PASSWORD).toCharArray());
        } else if (credentials.containsKey(userName) ) {
            pc.setPassword(credentials.get(userName).toCharArray());
        } else { 
            LOG.warn("No password found for user: " + userName);
        } 
    } 
 
    private void handleRealmCallback(RealmCallback rc) {
        LOG.debug("client supplied realm: " + rc.getDefaultText());
        rc.setText(rc.getDefaultText());
    } 
 
    private void handleAuthorizeCallback(AuthorizeCallback ac) {
        String authenticationID = ac.getAuthenticationID();
4
CodeRank
This code example shows how to use the following methods:setPassword
 
      if (callbackValues.containsKey(PasswordCallback.class)) {
        String password = (String) callbackValues
            .get(PasswordCallback.class);
        if (password == null) {
          c.setPassword(EMPTY_CHARS);
        } else { 
          c.setPassword(password.toCharArray());
        } 
        return true; 
      } else { 
        return false; 
      } 
    } else { 
      return false; 
    } 
  } 
 
  public void setName(String name) {
    callbackValues.put(NameCallback.class, name);
4
CodeRank
setPassword Method Overview
Set the retrieved password.
See Code Examples for other Java 8 PasswordCallback Methods: