PasswordCallback getPassword - 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 getPassword method.

This code example shows how to use the following methods:clearPassword, getPassword
        if (callbackHandler == null) {
            throw new LoginException("Error: no CallbackHandler available " + "to collect authentication information");
        } 
 
        NameCallback nc = new NameCallback("User name: ", "guest");
        PasswordCallback pc = new PasswordCallback("Password: ", false);
        Callback[] callbacks = { nc, pc };
        String username = null;
        String password = null;
        try { 
            callbackHandler.handle(callbacks);
            username = nc.getName();
            char[] tmpPassword = pc.getPassword();
            if (tmpPassword != null) {
                pc.clearPassword();
                password = new String(tmpPassword);
            } 
        } catch (IOException e) {
            LoginException le = new LoginException("Failed to get username/password");
            le.initCause(e);
8
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
        if (callbackHandler == null) {
            throw new LoginException("Error: no CallbackHandler available " + "to collect authentication information");
        } 
 
        NameCallback nc = new NameCallback("User name: ", "guest");
        PasswordCallback pc = new PasswordCallback("Password: ", false);
        Callback[] callbacks = { nc, pc };
 
        try { 
            callbackHandler.handle(callbacks);
            username = nc.getName();
            char[] tmpPassword = pc.getPassword();
            if (tmpPassword != null) {
                pc.clearPassword();
                password = new String(tmpPassword);
            } 
        } catch (IOException e) {
            LoginException le = new LoginException("Failed to get username/password");
            le.initCause(e);
            throw le;
8
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
 
    @Override 
    public boolean login() throws LoginException {
 
        NameCallback nameCallback = new NameCallback("Name : ");
        PasswordCallback passwordCallback = new PasswordCallback("Password : ", false);
        try { 
            callbackHandler.handle(new Callback[]{nameCallback, passwordCallback});
            String username = nameCallback.getName();
            String password = new String(passwordCallback.getPassword());
            nameCallback.setName("");
            passwordCallback.clearPassword();
            Customer customer = customerService.findCustomer(username, password);
 
            if (customer == null) {
                throw new LoginException("Authentication failed");
            } 
 
            return true; 
        } catch (Exception e) {
6
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
 
    @Override 
    public boolean login() throws LoginException {
        loginSucceeded = true;
        if (credentialsInvalidate) {
            PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
            try { 
                 callbackHandler.handle(new Callback[]{passwordCallback});
                 if (passwordCallback.getPassword() != null) {
                     if (debug) {
                        LOG.debug("Guest login failing (credentialsInvalidate=true) on presence of a password"); 
                     } 
                     loginSucceeded = false;
                     passwordCallback.clearPassword();
                 }; 
             } catch (IOException ioe) {
             } catch (UnsupportedCallbackException uce) {
             } 
        } 
        if (debug) {
6
CodeRank
This code example shows how to use the following methods:getPassword
            Map<String, ?> options) {
        this.subject = subject;
 
        try { 
            NameCallback nameCallback = new NameCallback("prompt");
            PasswordCallback passwordCallback = new PasswordCallback("prompt", false);
 
            callbackHandler.handle(new Callback[] { nameCallback, passwordCallback });
 
            password = new String(passwordCallback.getPassword());
            username = nameCallback.getName();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } 
    } 
 
    public boolean login() throws LoginException {
        if (username == null || !username.equals(password)) {
            throw new LoginException("username is not equal to password");
        } 
6
CodeRank
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:clearPassword, getPassword
 
    @Override 
    public boolean login() throws LoginException { 
        loginSucceeded = true;
        if (credentialsInvalidate) {
            PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
            try { 
                 callbackHandler.handle(new Callback[]{passwordCallback});
                 if (passwordCallback.getPassword() != null) {
                     if (debug) {
                        LOG.debug("Guest login failing (credentialsInvalidate=true) on presence of a password"); 
                     } 
                     loginSucceeded = false;
                     passwordCallback.clearPassword();
                 }; 
             } catch (IOException ioe) {
             } catch (UnsupportedCallbackException uce) {
             } 
        } 
        if (debug) {
7
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
This code example shows how to use the following methods:getPassword
     *  Tests that the callback handler can correctly retrieve the password from the connection url. 
     */ 
    public void testPasswordCallback() throws Exception 
    { 
        final String expectedPassword = "password";
        PasswordCallback passwordCallback = new PasswordCallback(PROMPT_UNUSED, false);
        assertNull("Unexpected password before test", passwordCallback.getPassword());
        _callbackHandler.handle(new Callback[] {passwordCallback});
        assertEquals("Unexpected password", expectedPassword, new String(passwordCallback.getPassword()));
    }     
} 
5
CodeRank
This code example shows how to use the following methods:getPassword
     *  Tests that the callback handler can correctly retrieve the password from the connection url. 
     */ 
    public void testPasswordCallback() throws Exception 
    { 
        final String expectedPassword = "password";
        PasswordCallback passwordCallback = new PasswordCallback(PROMPT_UNUSED, false);
        assertNull("Unexpected password before test", passwordCallback.getPassword());
        _callbackHandler.handle(new Callback[] {passwordCallback});
        assertEquals("Unexpected password", expectedPassword, new String(passwordCallback.getPassword()));
    }     
} 
5
CodeRank
getPassword Method Overview
Get the retrieved password.
See Code Examples for other Java 8 PasswordCallback Methods: