You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2011/03/29 13:35:53 UTC
svn commit: r1086549 - in /chemistry/opencmis/trunk:
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/
chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/o...
Author: fmui
Date: Tue Mar 29 11:35:53 2011
New Revision: 1086549
URL: http://svn.apache.org/viewvc?rev=1086549&view=rev
Log:
CMIS-341: added proxy authorization
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.java?rev=1086549&r1=1086548&r2=1086549&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/AbstractAuthenticationProvider.java Tue Mar 29 11:35:53 2011
@@ -104,4 +104,34 @@ public abstract class AbstractAuthentica
return null;
}
+
+ /**
+ * Gets the proxy user name from the session.
+ *
+ * @return the proxy user name or <code>null</code> if the user name is not
+ * set
+ */
+ protected String getProxyUser() {
+ Object userObject = getSession().get(SessionParameter.PROXY_USER);
+ if (userObject instanceof String) {
+ return (String) userObject;
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets the proxy password from the session.
+ *
+ * @return the proxy password or <code>null</code> if the password is not
+ * set
+ */
+ protected String getProxyPassword() {
+ Object passwordObject = getSession().get(SessionParameter.PROXY_PASSWORD);
+ if (passwordObject instanceof String) {
+ return (String) passwordObject;
+ }
+
+ return null;
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java?rev=1086549&r1=1086548&r2=1086549&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java Tue Mar 29 11:35:53 2011
@@ -56,32 +56,48 @@ public class StandardAuthenticationProvi
return null;
}
+ result = new HashMap<String, List<String>>();
+
// get user and password
String user = getUser();
String password = getPassword();
- // if no user is set, don't create HTTP headers
- if (user == null) {
- return null;
- }
-
- if (password == null) {
- password = "";
+ // if no user is set, don't set HTTP header
+ if (user != null) {
+ if (password == null) {
+ password = "";
+ }
+
+ try {
+ String authHeader = "Basic "
+ + new String(Base64.encodeBase64((user + ":" + password).getBytes("ISO-8859-1")), "ISO-8859-1");
+ result.put("Authorization", Collections.singletonList(authHeader));
+ } catch (UnsupportedEncodingException e) {
+ // shouldn't happen...
+ }
+ }
+
+ // get proxy user and password
+ String proxyUser = getProxyUser();
+ String proxyPassword = getProxyPassword();
+
+ // if no proxy user is set, don't set HTTP header
+ if (proxyUser != null) {
+ if (proxyPassword == null) {
+ proxyPassword = "";
+ }
+
+ try {
+ String authHeader = "Basic "
+ + new String(Base64.encodeBase64((proxyUser + ":" + proxyPassword).getBytes("ISO-8859-1")),
+ "ISO-8859-1");
+ result.put("Proxy-Authorization", Collections.singletonList(authHeader));
+ } catch (UnsupportedEncodingException e) {
+ // shouldn't happen...
+ }
}
- String authHeader = "";
- try {
- authHeader = "Basic "
- + new String(Base64.encodeBase64((user + ":" + password).getBytes("ISO-8859-1")), "ISO-8859-1");
- } catch (UnsupportedEncodingException e) {
- // shouldn't happen...
- return null;
- }
-
- result = new HashMap<String, List<String>>();
- result.put("Authorization", Collections.singletonList(authHeader));
-
- return result;
+ return result.isEmpty() ? null : result;
}
@Override
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java?rev=1086549&r1=1086548&r2=1086549&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java Tue Mar 29 11:35:53 2011
@@ -71,11 +71,18 @@ public final class SessionParameter {
*/
public static final String AUTH_SOAP_USERNAMETOKEN = "org.apache.chemistry.opencmis.binding.auth.soap.usernametoken";
+ // --- connection ---
+
public static final String COMPRESSION = "org.apache.chemistry.opencmis.binding.compression";
public static final String CONNECT_TIMEOUT = "org.apache.chemistry.opencmis.binding.connecttimeout";
public static final String READ_TIMEOUT = "org.apache.chemistry.opencmis.binding.readtimeout";
+ public static final String PROXY_USER = "org.apache.chemistry.opencmis.binding.proxyuser";
+ public static final String PROXY_PASSWORD = "org.apache.chemistry.opencmis.binding.proxypassword";
+
+ // --- cache ---
+
public static final String CACHE_SIZE_OBJECTS = "org.apache.chemistry.opencmis.cache.objects.size";
public static final String CACHE_TTL_OBJECTS = "org.apache.chemistry.opencmis.cache.objects.ttl";
public static final String CACHE_SIZE_PATHTOID = "org.apache.chemistry.opencmis.cache.pathtoid.size";