Author: jbonofre
Date: Sat Jun 5 16:12:00 2010
New Revision: 951736
URL: http://svn.apache.org/viewvc?rev=951736&view=rev
Log:
[SMXCOMP-623] Add support of NTLM authentication scheme with domain and host
attribute in the BasicAuthenticationCredentials.
Modified:
servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/BasicAuthCredentialsTest.java
servicemix/components/bindings/servicemix-http/trunk/src/test/resources/org/apache/servicemix/http/basic-auth.xml
Modified:
servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
URL:
http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java?rev=951736&r1=951735&r2=951736&view=diff
==============================================================================
---
servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
(original)
+++
servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
Sat Jun 5 16:12:00 2010
@@ -22,6 +22,7 @@ import javax.jbi.messaging.NormalizedMes
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.servicemix.expression.Expression;
@@ -35,6 +36,8 @@ public class BasicAuthCredentials {
protected Expression username;
protected Expression password;
+ protected Expression host;
+ protected Expression domain;
public BasicAuthCredentials() {
}
@@ -68,14 +71,52 @@ public class BasicAuthCredentials {
}
/**
- * Sets the password to use for authentocation.
+ * Sets the password to use for authentication.
*
- * @param password am <code>Expression</code> containing the password.
+ * @param password an <code>Expression</code> containing the password.
* @org.apache.xbean.Property description="the password to use for
authentication"
*/
public void setPassword(Expression password) {
this.password = password;
}
+
+ /**
+ * Returns the domain for NTLM authentication.
+ *
+ * @return an <code>Expression</code> containing the NTLM domain.
+ */
+ public Expression getDomain() {
+ return domain;
+ }
+
+ /**
+ * Sets the domain to use for NTLM authentication.
+ *
+ * @param domain an <code>Expression</code> containing the NTLM domain.
+ * @org.apache.xbean.Property description="the domain to use for NTLM
authentication"
+ */
+ public void setDomain(Expression domain) {
+ this.domain = domain;
+ }
+
+ /**
+ * Returns the host for NTLM authentication.
+ *
+ * @return an <code>Expression</code> containing the NTLM host.
+ */
+ public Expression getHost() {
+ return host;
+ }
+
+ /**
+ * Sets the host to use for NTLM authentication.
+ *
+ * @param host an <code>Expression</code> containing the NTLM host.
+ * @org.apache.xbean.Property description="the host to use for NTLM
authentication"
+ */
+ public void setHost(Expression host) {
+ this.host = host;
+ }
/**
* Applies this authentication to the given method.
@@ -88,11 +129,20 @@ public class BasicAuthCredentials {
public void applyCredentials(HttpClient client, MessageExchange exchange,
NormalizedMessage message)
throws MessagingException {
AuthScope scope = new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT);
- Credentials credentials = new
UsernamePasswordCredentials((String)this.username.evaluate(exchange,
+ Credentials credentials;
+ if (domain != null && host != null) {
+ credentials = new
NTCredentials((String)this.username.evaluate(exchange, message),
+ (String)this.password.evaluate(exchange, message),
+ (String)this.host.evaluate(exchange, message),
+ (String)this.domain.evaluate(exchange, message));
+ } else {
+ credentials = new
UsernamePasswordCredentials((String)this.username.evaluate(exchange,
message),
(String)this.password.evaluate(exchange,
message));
+ }
client.getState().setCredentials(scope, credentials);
+
}
/**
@@ -106,10 +156,16 @@ public class BasicAuthCredentials {
public void applyProxyCredentials(HttpClient client, MessageExchange
exchange, NormalizedMessage message)
throws MessagingException {
AuthScope scope = new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT);
- Credentials credentials = new
UsernamePasswordCredentials((String)this.username.evaluate(exchange,
-
message),
-
(String)this.password.evaluate(exchange,
-
message));
+ Credentials credentials;
+ if (domain != null && host != null) {
+ credentials = new
NTCredentials((String)this.username.evaluate(exchange, message),
+ (String)this.password.evaluate(exchange, message),
+ (String)this.host.evaluate(exchange, message),
+ (String)this.domain.evaluate(exchange, message));
+ } else {
+ credentials = new
UsernamePasswordCredentials((String)this.username.evaluate(exchange,message),
+
(String)this.password.evaluate(exchange,message));
+ }
client.getState().setProxyCredentials(scope, credentials);
}
Modified:
servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/BasicAuthCredentialsTest.java
URL:
http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/BasicAuthCredentialsTest.java?rev=951736&r1=951735&r2=951736&view=diff
==============================================================================
---
servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/BasicAuthCredentialsTest.java
(original)
+++
servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/BasicAuthCredentialsTest.java
Sat Jun 5 16:12:00 2010
@@ -35,5 +35,13 @@ public class BasicAuthCredentialsTest ex
assertEquals("testuser",
support.getBasicAuth().getUsername().evaluate(null, null));
assertEquals("testpass",
support.getBasicAuth().getPassword().evaluate(null, null));
}
+
+ public void testNTLMCredentials() throws Exception {
+ BasicAuthTestSupport support = (BasicAuthTestSupport)
context.getBean("NTLMAuthTestSupport");
+ assertEquals("testuser",
support.getBasicAuth().getUsername().evaluate(null, null));
+ assertEquals("testpass",
support.getBasicAuth().getPassword().evaluate(null, null));
+ assertEquals("testdomain",
support.getBasicAuth().getDomain().evaluate(null, null));
+ assertEquals("testhost",
support.getBasicAuth().getHost().evaluate(null, null));
+ }
}
Modified:
servicemix/components/bindings/servicemix-http/trunk/src/test/resources/org/apache/servicemix/http/basic-auth.xml
URL:
http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/resources/org/apache/servicemix/http/basic-auth.xml?rev=951736&r1=951735&r2=951736&view=diff
==============================================================================
---
servicemix/components/bindings/servicemix-http/trunk/src/test/resources/org/apache/servicemix/http/basic-auth.xml
(original)
+++
servicemix/components/bindings/servicemix-http/trunk/src/test/resources/org/apache/servicemix/http/basic-auth.xml
Sat Jun 5 16:12:00 2010
@@ -25,5 +25,12 @@
<http:basicAuthCredentials username="testuser" password="testpass"
/>
</property>
</bean>
+
+ <bean id="NTLMAuthTestSupport"
+ class="org.apache.servicemix.http.BasicAuthTestSupport">
+ <property name="basicAuth">
+ <http:basicAuthCredentials username="testuser" password="testpass"
domain="testdomain" host="testhost" />
+ </property>
+ </bean>
</beans>