CallbackHandler handle - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:handle
 
    @Override 
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
        final CallbackHandler callbackHandler = this.callbackHandler;
        if(callbackHandler != null) {
            callbackHandler.handle(callbacks);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:handle
        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);
            throw le;
        } catch (UnsupportedCallbackException e) {
            LoginException le = new LoginException("CallbackHandler does not support: " + e.getCallback());
            le.initCause(e);
            throw le;
7
CodeRank
This code example shows how to use the following methods:handle
        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;
        } catch (UnsupportedCallbackException e) {
            LoginException le = new LoginException("CallbackHandler does not support: " + e.getCallback());
            le.initCause(e);
            throw le;
7
CodeRank
This code example shows how to use the following methods:handle
 
        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");
        } 
        if("".equals(username)) {
            throw new LoginException("username cannot be empty string");
5
CodeRank
This code example shows how to use the following methods:handle
    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) {
            LOG.debug("Guest login " + loginSucceeded);
        } 
6
CodeRank
This code example shows how to use the following methods:handle
    public boolean login() throws LoginException { 
        Callback[] callbacks = new Callback[1];
 
        callbacks[0] = new CertificateCallback();
        try { 
            callbackHandler.handle(callbacks);
        } catch (IOException ioe) {
            throw new LoginException(ioe.getMessage());
        } catch (UnsupportedCallbackException uce) {
            throw new LoginException(uce.getMessage() + " Unable to obtain client certificates.");
        } 
        certificates = ((CertificateCallback)callbacks[0]).getCertificates();
 
        username = getUserNameForCertificates(certificates);
        if (username == null) {
            throw new FailedLoginException("No user for client certificate: " + getDistinguishedName(certificates));
        } 
 
        groups = getUserGroups(username);
 
6
CodeRank
This code example shows how to use the following methods:handle
This code example shows how to use the following methods:handle
    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) {
            LOG.debug("Guest login " + loginSucceeded);
        } 
5
CodeRank
This code example shows how to use the following methods:handle
    @CheckForNull 
    protected SecurityProvider getSecurityProvider() { 
        if (securityProvider == null && callbackHandler != null) {
            RepositoryCallback rcb = new RepositoryCallback();
            try { 
                callbackHandler.handle(new Callback[]{rcb});
                securityProvider = rcb.getSecurityProvider();
            } catch (Exception e) {
                log.debug("Unable to retrieve the SecurityProvider via callback", e);
            } 
        } 
        return securityProvider;
    } 
 
    /** 
     * Tries to obtain the {@code Whiteboard} object from the callback 
     * handler using a new WhiteboardCallback and keeps the value as 
     * private field. If the callback handler isn't able to handle the 
     * WhiteboardCallback this method returns {@code null}. 
     * 
4
CodeRank
This code example shows how to use the following methods:handle
        loginSucceeded = false;
        Callback[] callbacks = new Callback[1];
 
        callbacks[0] = new CertificateChainCallback();
        try { 
            handler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        } 
        assert callbacks.length == 1;
        Certificate[] certificateChain = ((CertificateChainCallback)callbacks[0]).getCertificateChain();
        if (certificateChain == null || certificateChain.length == 0) {
            throw new FailedLoginException();
        } 
        if (!(certificateChain[0] instanceof X509Certificate)) {
            throw new FailedLoginException();
        } 
        //TODO actually validate chain 
4
CodeRank
handle Method Overview
Retrieve or display the information requested in the provided Callbacks.
See Code Examples for other Java 8 CallbackHandler Methods: