Java 8 NameCallback - 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 NameCallback class.

This code example shows how to use the following methods:getName, setName
    } 
 
    @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; 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName
    public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState,
            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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDefaultName, setName
        } 
    } 
 
    private void handleNameCallback(NameCallback nc) {
        // check to see if this user is in the user password database. 
        if (credentials.get(nc.getDefaultName()) == null) {
            LOG.warn("User '" + nc.getDefaultName() + "' not found in list of DIGEST-MD5 authenticateable users.");
            return; 
        } 
        nc.setName(nc.getDefaultName());
        userName = nc.getDefaultName();
    } 
 
    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 { 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName, setName
 
   @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");
         } 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setName
                username = ((UserDetails) principal).getUsername();
            } else { 
                username = principal.toString();
            } 
 
            ncb.setName(username);
        } 
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName
This code example shows how to use the following methods:getName
     *  Tests that the callback handler can correctly retrieve the username from the connection url. 
     */ 
    public void testNameCallback() throws Exception
    { 
        final String expectedName = "username";
        NameCallback nameCallback = new NameCallback(PROMPT_UNUSED);
 
        assertNull("Unexpected name before test", nameCallback.getName());
        _callbackHandler.handle(new Callback[] {nameCallback});
        assertEquals("Unexpected name", expectedName, nameCallback.getName());
    } 
 
    /** 
     *  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());
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName
        if (isComplete) {
            // Empty final response from server, just ignore it. 
            return new byte[] { }; 
        } 
 
        NameCallback nameCallback = new NameCallback("Enter name");
        Callback[] callbacks = new Callback[] { nameCallback };
        try { 
            callbackHandler.handle(callbacks);
        } catch (UnsupportedCallbackException e) {
            throw new SaslException("Unsupported callback: " + e);
        } catch (IOException e) {
            throw new SaslException("Failed to execute callback: " + e);
        } 
        String email = nameCallback.getName();
 
        byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", email,
                                        oauthToken).getBytes();
        isComplete = true;
        return response;
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName
     *  Tests that the callback handler can correctly retrieve the username from the connection url. 
     */ 
    public void testNameCallback() throws Exception
    { 
        final String expectedName = "username";
        NameCallback nameCallback = new NameCallback(PROMPT_UNUSED);
 
        assertNull("Unexpected name before test", nameCallback.getName());
        _callbackHandler.handle(new Callback[] {nameCallback});
        assertEquals("Unexpected name", expectedName, nameCallback.getName());
    } 
 
    /** 
     *  Tests that the callback handler can correctly retrieve the password from the connection url 
     *  and calculate a MD5. 
     */ 
    public void testDigestedPasswordCallback() throws Exception
    { 
        final char[] expectedPasswordDigested = getHashPassword("password");
         
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName
    } 
 
    public byte[] evaluateChallenge(byte[] challenge) throws SaslException
    { 
        // we do not care about the prompt or the default name 
        NameCallback nameCallback = new NameCallback("prompt", "defaultName");
        PasswordCallback pwdCallback = new PasswordCallback("prompt", false);
        Callback[] callbacks = new Callback[]{nameCallback, pwdCallback};
        try 
        { 
            _cbh.handle(callbacks);
        } 
        catch (Exception e)
        { 
            throw new SaslException("Error handling SASL callbacks: " + e, e);
        } 
        FieldTable table = FieldTableFactory.newFieldTable();
        table.setString("LOGIN", nameCallback.getName());
        table.setString("PASSWORD", new String(pwdCallback.getPassword()));
        return table.getDataAsBytes();

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 NameCallback Methods: