WebView缓存用户标识和密码android

时间:2016-07-13 12:35:15

标签: android authentication webview httprequest ntlm

我正在使用NTLM身份验证协议进行身份验证。

@Override
        public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler, String host, String realm)
        {
            logger.debug("_onReceivedHttpAuthRequest", "host = " + host + " realm = " + realm);
            LayoutInflater inflater = LayoutInflater.from(OAuthLoginActivity.this);
            View dialogView = inflater.inflate(R.layout.dialog_user_credentials_ntlm_support, null);

            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OAuthLoginActivity.this);
            dialogBuilder.setTitle(getResources().getString(R.string.title_login_change_dialog));
            dialogBuilder.setView(dialogView);

            final EditText userNameEditText = (EditText) dialogView.findViewById(R.id.ntlm_username);
            final EditText passwordEditText = (EditText) dialogView.findViewById(R.id.ntlm_password);

            dialogBuilder.setPositiveButton("Login", null);

            dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int which)
                {
                    dialog.cancel();
                    finish();
                }
            });

            final AlertDialog alertDialog = dialogBuilder.create();
            alertDialog.show();

            alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    if (!userNameEditText.getText().toString().isEmpty()
                            && !passwordEditText.getText().toString().isEmpty()) {handler.proceed(userNameEditText.getText().toString(), passwordEditText.getText().toString());
                        alertDialog.dismiss();
                    }
                }
            });

        }

对于此代码,我收到响应并打开对话框,但是一旦我登录,它就会保存用户ID和密码。因此,如果我在某个时间后再次登录,它会使用相同的用户ID和密码登录,它不会进入onReceivedHttpAuthRequest()方法。 我想在打开webView时清除缓存。

0 个答案:

没有答案