You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/08/14 23:19:12 UTC
svn commit: r431436 - in
/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http:
BasicAuthCredentials.java HttpEndpoint.java processors/ProviderProcessor.java
Author: gnodet
Date: Mon Aug 14 14:19:12 2006
New Revision: 431436
URL: http://svn.apache.org/viewvc?rev=431436&view=rev
Log:
SM-513: support for HTTP basic authentication
Added:
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
Modified:
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
Added: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java?rev=431436&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java (added)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java Mon Aug 14 14:19:12 2006
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.http;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+
+/**
+ *
+ * @author roehl.sioson
+ * @org.apache.xbean.XBean element="basicAuthCredentials"
+ * description="This class contains parameters needed to send basic authentication credentials"
+ *
+ */
+public class BasicAuthCredentials {
+
+ protected String username;
+ protected String password;
+
+ public BasicAuthCredentials()
+ {
+ }
+
+ /**
+ * @return Returns the username.
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * @param ssl The username to set.
+ */
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ /**
+ * @return Returns the password.
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * @param ssl The password to set.
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * Applies this authentication to the given method.
+ * @param method The method to receive authentication headers.
+ */
+ public void applyCredentials( HttpClient client )
+ {
+ AuthScope scope = new AuthScope( AuthScope.ANY_HOST, AuthScope.ANY_PORT );
+ Credentials credentials = new UsernamePasswordCredentials( this.username, this.password );
+ client.getState().setCredentials( scope, credentials );
+ }
+
+}
Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?rev=431436&r1=431435&r2=431436&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java Mon Aug 14 14:19:12 2006
@@ -54,6 +54,7 @@
protected SslParameters ssl;
protected String authMethod;
protected String soapAction;
+ protected BasicAuthCredentials basicAuthentication;
/**
* @return the soapAction
@@ -113,6 +114,23 @@
this.locationURI = locationUri;
}
+ /**
+ * Authentication parameters used for provider endpoints using BASIC
+ * authentication.
+ *
+ * @return Returns the basicAuthentication.
+ */
+ public BasicAuthCredentials getBasicAuthentication() {
+ return basicAuthentication;
+ }
+
+ /**
+ * @param basicAuthentication The basicAuthentication to set.
+ */
+ public void setBasicAuthentication(BasicAuthCredentials basicAuthCredentials) {
+ this.basicAuthentication = basicAuthCredentials;
+ }
+
/**
* @org.apache.xbean.Property alias="role"
* @param role
@@ -252,5 +270,7 @@
ComponentLifeCycle lf = getServiceUnit().getComponent().getLifeCycle();
return ((HttpLifeCycle) lf).getKeystoreManager();
}
+
+
}
Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?rev=431436&r1=431435&r2=431436&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java Mon Aug 14 14:19:12 2006
@@ -138,6 +138,9 @@
// return false;
// }
//});
+ if (endpoint.getBasicAuthentication() != null) {
+ endpoint.getBasicAuthentication().applyCredentials( getClient() );
+ }
int response = getClient().executeMethod(host, method);
if (response != HttpStatus.SC_OK && response != HttpStatus.SC_ACCEPTED) {
if (exchange instanceof InOnly == false) {