Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 910A19AFB for ; Mon, 26 Mar 2012 17:22:59 +0000 (UTC) Received: (qmail 91535 invoked by uid 500); 26 Mar 2012 17:22:59 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 91482 invoked by uid 500); 26 Mar 2012 17:22:59 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 91474 invoked by uid 99); 26 Mar 2012 17:22:59 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Mar 2012 17:22:59 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B912C9142; Mon, 26 Mar 2012 17:22:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bowserj@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: android commit: Work on CB-369, Moving Authentication OUT of DroidGap Message-Id: <20120326172258.B912C9142@tyr.zones.apache.org> Date: Mon, 26 Mar 2012 17:22:58 +0000 (UTC) Updated Branches: refs/heads/CordovaWebView 8ecfcb12c -> 6dabe4c01 Work on CB-369, Moving Authentication OUT of DroidGap Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/6dabe4c0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/6dabe4c0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/6dabe4c0 Branch: refs/heads/CordovaWebView Commit: 6dabe4c0102e5474a887a3297a11abbaff50d9ae Parents: 8ecfcb1 Author: Joe Bowser Authored: Mon Mar 26 10:22:37 2012 -0700 Committer: Joe Bowser Committed: Mon Mar 26 10:22:37 2012 -0700 ---------------------------------------------------------------------- .../src/org/apache/cordova/CordovaWebView.java | 90 ++++++++++++++- .../org/apache/cordova/CordovaWebViewClient.java | 3 +- framework/src/org/apache/cordova/DroidGap.java | 84 -------------- 3 files changed, 90 insertions(+), 87 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6dabe4c0/framework/src/org/apache/cordova/CordovaWebView.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index ff80992..526a183 100644 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -1,11 +1,16 @@ package org.apache.cordova; +import java.util.Hashtable; + import android.content.Context; import android.util.AttributeSet; import android.webkit.WebView; public class CordovaWebView extends WebView { - + + /** The authorization tokens. */ + private Hashtable authenticationTokens = new Hashtable(); + public CordovaWebView(Context context) { super(context); } @@ -22,5 +27,86 @@ public class CordovaWebView extends WebView { boolean privateBrowsing) { super(context, attrs, defStyle, privateBrowsing); } - + + /** + * Sets the authentication token. + * + * @param authenticationToken + * the authentication token + * @param host + * the host + * @param realm + * the realm + */ + public void setAuthenticationToken(AuthenticationToken authenticationToken, String host, String realm) { + + if(host == null) { + host = ""; + } + + if(realm == null) { + realm = ""; + } + + authenticationTokens.put(host.concat(realm), authenticationToken); + } + + /** + * Removes the authentication token. + * + * @param host + * the host + * @param realm + * the realm + * @return the authentication token or null if did not exist + */ + public AuthenticationToken removeAuthenticationToken(String host, String realm) { + return authenticationTokens.remove(host.concat(realm)); + } + + /** + * Gets the authentication token. + * + * In order it tries: + * 1- host + realm + * 2- host + * 3- realm + * 4- no host, no realm + * + * @param host + * the host + * @param realm + * the realm + * @return the authentication token + */ + public AuthenticationToken getAuthenticationToken(String host, String realm) { + AuthenticationToken token = null; + + token = authenticationTokens.get(host.concat(realm)); + + if(token == null) { + // try with just the host + token = authenticationTokens.get(host); + + // Try the realm + if(token == null) { + token = authenticationTokens.get(realm); + } + + // if no host found, just query for default + if(token == null) { + token = authenticationTokens.get(""); + } + } + + return token; + } + + /** + * Clear all authentication tokens. + */ + public void clearAuthenticationTokens() { + authenticationTokens.clear(); + } + } http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6dabe4c0/framework/src/org/apache/cordova/CordovaWebViewClient.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java index 5eb2406..2651687 100755 --- a/framework/src/org/apache/cordova/CordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java @@ -173,7 +173,8 @@ public class CordovaWebViewClient extends WebViewClient { String realm) { // get the authentication token - AuthenticationToken token = ctx.getAuthenticationToken(host,realm); + // Note: The WebView MUST be a CordoaWebView + AuthenticationToken token = ((CordovaWebView) view).getAuthenticationToken(host,realm); if(token != null) { handler.proceed(token.getUserName(), token.getPassword()); http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6dabe4c0/framework/src/org/apache/cordova/DroidGap.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index 39d5c31..f5e256e 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -191,9 +191,6 @@ public class DroidGap extends Activity implements CordovaInterface { // (this is not the color for the webview, which is set in HTML) private int backgroundColor = Color.BLACK; - /** The authorization tokens. */ - private Hashtable authenticationTokens = new Hashtable(); - /* * The variables below are used to cache some of the activity properties. */ @@ -212,87 +209,6 @@ public class DroidGap extends Activity implements CordovaInterface { // preferences read from cordova.xml protected PreferenceSet preferences; - - /** - * Sets the authentication token. - * - * @param authenticationToken - * the authentication token - * @param host - * the host - * @param realm - * the realm - */ - public void setAuthenticationToken(AuthenticationToken authenticationToken, String host, String realm) { - - if(host == null) { - host = ""; - } - - if(realm == null) { - realm = ""; - } - - authenticationTokens.put(host.concat(realm), authenticationToken); - } - - /** - * Removes the authentication token. - * - * @param host - * the host - * @param realm - * the realm - * @return the authentication token or null if did not exist - */ - public AuthenticationToken removeAuthenticationToken(String host, String realm) { - return authenticationTokens.remove(host.concat(realm)); - } - - /** - * Gets the authentication token. - * - * In order it tries: - * 1- host + realm - * 2- host - * 3- realm - * 4- no host, no realm - * - * @param host - * the host - * @param realm - * the realm - * @return the authentication token - */ - public AuthenticationToken getAuthenticationToken(String host, String realm) { - AuthenticationToken token = null; - - token = authenticationTokens.get(host.concat(realm)); - - if(token == null) { - // try with just the host - token = authenticationTokens.get(host); - - // Try the realm - if(token == null) { - token = authenticationTokens.get(realm); - } - - // if no host found, just query for default - if(token == null) { - token = authenticationTokens.get(""); - } - } - - return token; - } - - /** - * Clear all authentication tokens. - */ - public void clearAuthenticationTokens() { - authenticationTokens.clear(); - } /**