Code example for PasswordCallback

Methods: getPassword

0
            final FieldTable ft = FieldTableFactory.newFieldTable(ByteBuffer.wrap(response), response.length);
            String username = (String) ft.getString("LOGIN");
            // we do not care about the prompt but it throws if null 
            NameCallback nameCb = new NameCallback("prompt", username);
            // we do not care about the prompt but it throws if null 
            PasswordCallback passwordCb = new PasswordCallback("prompt", false);
            // TODO: should not get pwd as a String but as a char array... 
            String pwd = (String) ft.getString("PASSWORD");
            AuthorizeCallback authzCb = new AuthorizeCallback(username, username);
            Callback[] callbacks = new Callback[]{nameCb, passwordCb, authzCb};
            _cbh.handle(callbacks);
            String storedPwd = new String(passwordCb.getPassword());
            if (storedPwd.equals(pwd))
            { 
                _complete = true;
            } 
            if (authzCb.isAuthorized() && _complete)
            { 
                _authorizationId = authzCb.getAuthenticationID();
                return null; 
            }