[jboss-svn-commits] JBL Code SVN: r20770 - labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jun 25 12:34:20 EDT 2008
Author: john.graham at jboss.org
Date: 2008-06-25 12:34:20 -0400 (Wed, 25 Jun 2008)
New Revision: 20770
Added:
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavException.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavSessionAuthenticator.java
Log:
Refactor to use platform key-ring for user name and password
Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavException.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavException.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavException.java 2008-06-25 16:34:20 UTC (rev 20770)
@@ -0,0 +1,18 @@
+package org.guvnor.tools.utils.webdav;
+
+public class WebDavException extends Exception {
+
+ //TODO: put a real serialization value here
+ private static final long serialVersionUID = 1L;
+
+ private int errCode;
+
+ public WebDavException(int errCode) {
+ super();
+ this.errCode = errCode;
+ }
+
+ public int getErrorCode() {
+ return errCode;
+ }
+}
Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavSessionAuthenticator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavSessionAuthenticator.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavSessionAuthenticator.java 2008-06-25 16:34:20 UTC (rev 20770)
@@ -0,0 +1,80 @@
+package org.guvnor.tools.utils.webdav;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.webdav.http.client.IAuthenticator;
+
+public class WebDavSessionAuthenticator implements IAuthenticator {
+
+ private class ServerAuthenInfo {
+ private String serverUrl;
+ private HashMap<String, Map<String, String>> authInfo;
+
+ public ServerAuthenInfo(String serverUrl) {
+ this.serverUrl = serverUrl;
+ authInfo = new HashMap<String, Map<String, String>>();
+ }
+ public Map<String, String> getAuthenicationInfo(String scheme) {
+ return authInfo.get(scheme);
+ }
+ public void addAuthenicationInfo(String scheme, Map<String, String> info) {
+ authInfo.put(scheme, info);
+ }
+ public String getServerURL() {
+ return serverUrl;
+ }
+ }
+
+ private HashMap<String, ServerAuthenInfo> serverAuthMaps;
+
+ public WebDavSessionAuthenticator() {
+ serverAuthMaps = new HashMap<String, ServerAuthenInfo>();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void addAuthenticationInfo(URL serverUrl,
+ String realm,
+ String scheme,
+ Map info) {
+ ServerAuthenInfo authInfo = serverAuthMaps.get(serverUrl);
+ if (authInfo == null) {
+ authInfo = new ServerAuthenInfo(serverUrl.getHost());
+ serverAuthMaps.put(serverUrl.getHost().toLowerCase(), authInfo);
+ }
+ authInfo.addAuthenicationInfo(scheme.toLowerCase(), info);
+ }
+
+ public void addProtectionSpace(URL resourceUrl, String realm) {
+ // Not using the notion of "realm," so do nothing
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map getAuthenticationInfo(URL serverUrl,
+ String realm,
+ String scheme) {
+
+ ServerAuthenInfo authInfo = serverAuthMaps.get(serverUrl.getHost().toLowerCase());
+ if (authInfo == null) {
+ return null;
+ }
+ return authInfo.getAuthenicationInfo(scheme.toLowerCase());
+ }
+
+ public String getProtectionSpace(URL resourceUrl) {
+ // We don't have the notion of "realm," but the client
+ // requires a non-null return value.
+ return "";
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map requestAuthenticationInfo(URL resourceUrl,
+ String realm,
+ String scheme) {
+ // We do not distinguish between resource- and server-based
+ // authentication: all authentication is done on a per-server
+ // basis. Therefore, delegate to a server authentication check.
+ return getAuthenticationInfo(resourceUrl, realm, scheme);
+ }
+}
More information about the jboss-svn-commits
mailing list