Java 8 PasswordCallback - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PasswordCallback class.

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, 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
 
    @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:getPrompt, isEchoOn
        } catch (Exception e) {
            fail("Unexpected exception: " + e);
        } 
 
        try { 
            PasswordCallback pc = new PasswordCallback(prompt, false);
            assertNotNull("Null object returned", pc);
            assertEquals(prompt, pc.getPrompt());
            assertEquals(false, pc.isEchoOn());
        } catch (Exception e) {
            fail("Unexpected exception: " + e);
        } 
 
        try { 
            PasswordCallback pc = new PasswordCallback(null, true);
            fail("IllegalArgumentException wasn't thrown");
        } catch (IllegalArgumentException npe) {
        } 
 
        try { 
6
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:clearPassword, getPassword
        this.callbackHandler = callbackHandler;
        this.sharedState = sharedState;
    } 
 
    protected String[] retrieveLogin() throws LoginException {
        PasswordCallback pc = new PasswordCallback("Password: ", false);
        NameCallback nc = new NameCallback("Username: ", "guest");
        Callback[] callbacks = { nc, pc };
        try { 
            String[] login = new String[2];
            callbackHandler.handle(callbacks);
            login[0] = nc.getName();
            char[] tmpPassword = pc.getPassword();
            if (tmpPassword != null) {
                login[1] = new String(tmpPassword);
            } 
            pc.clearPassword();
            return login;
        } catch (IOException ioe) {
            throw new LoginException(ioe.toString());

6
CodeRank
See Code Examples for Java 8 PasswordCallback Methods: