Author: jochen
Date: Fri Aug 18 03:07:21 2006
New Revision: 432539
URL: http://svn.apache.org/viewvc?rev=432539&view=rev
Log:
Various fixes related to basic authentication.
PR: XMLRPC-103
PR: XMLRPC-104
Submitted by: Landon Fuller, [EMAIL PROTECTED]
Added:
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/AuthenticationTest.java
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/AuthenticationTest.properties
(with props)
Added:
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/AuthenticationTest.java
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/AuthenticationTest.java?rev=432539&view=auto
==============================================================================
---
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/AuthenticationTest.java
(added)
+++
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/AuthenticationTest.java
Fri Aug 18 03:07:21 2006
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import java.io.IOException;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.XmlRpcRequestConfig;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.util.ClientFactory;
+import org.apache.xmlrpc.common.XmlRpcHttpRequestConfig;
+import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
+
+
+/**
+ * Test case for supported authentication variants.
+ */
+public class AuthenticationTest extends XmlRpcTestCase {
+ private static final String PASSWORD =
"98765432109876543210987654321098765432109876543210";
+ private static final String USER_NAME =
"01234567890123456789012345678901234567890123456789";
+// + "\u00C4\u00D6\u00DC\u00F6\u00FC\u00E4\u00DF";
+
+ /** An interface, which is being implemented by the
+ * server.
+ */
+ public interface Adder {
+ /** Returns the sum of the given integers.
+ */
+ public int add(int pNum1, int pNum2);
+ }
+
+ /** Implementation of [EMAIL PROTECTED] DynamicProxyTest.Adder}, which is
used by
+ * the server.
+ */
+ public static class AdderImpl implements Adder {
+ public int add(int pNum1, int pNum2) {
+ return pNum1 + pNum2;
+ }
+ }
+
+ protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
XmlRpcException {
+ XmlRpcHandlerMapping mapping =
getHandlerMapping("AuthenticationTest.properties");
+ ((AbstractReflectiveHandlerMapping)
mapping).setAuthenticationHandler(new AuthenticationHandler(){
+ public boolean isAuthorized(XmlRpcRequest pRequest)
+ throws XmlRpcException {
+ XmlRpcRequestConfig config = pRequest.getConfig();
+ if (config instanceof XmlRpcHttpRequestConfig) {
+ XmlRpcHttpRequestConfig httpRequestConfig =
(XmlRpcHttpRequestConfig) config;
+ return
USER_NAME.equals(httpRequestConfig.getBasicUserName())
+ &&
PASSWORD.equals(httpRequestConfig.getBasicPassword());
+ }
+ return true;
+ }
+ });
+ return mapping;
+ }
+
+ protected XmlRpcClientConfigImpl getConfig(ClientProvider pProvider)
+ throws Exception {
+ XmlRpcClientConfigImpl config = super.getConfig(pProvider);
+ config.setBasicUserName(USER_NAME);
+ config.setBasicPassword(PASSWORD);
+ return config;
+ }
+
+ private ClientFactory getClientFactory(ClientProvider pProvider) throws
Exception {
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ return new ClientFactory(client);
+ }
+
+ /** Tests calling the [EMAIL PROTECTED] Adder#add(int,int)} method
+ * by using an object, which has been created by the
+ * [EMAIL PROTECTED] ClientFactory}.
+ */
+ public void testAdderCall() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testAdderCall(providers[i]);
+ }
+ }
+
+ private void testAdderCall(ClientProvider pProvider) throws Exception {
+ ClientFactory factory = getClientFactory(pProvider);
+ Adder adder = (Adder) factory.newInstance(Adder.class);
+ assertEquals(6, adder.add(2, 4));
+ }
+}
Added:
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/AuthenticationTest.properties
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/AuthenticationTest.properties?rev=432539&view=auto
==============================================================================
---
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/AuthenticationTest.properties
(added)
+++
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/AuthenticationTest.properties
Fri Aug 18 03:07:21 2006
@@ -0,0 +1 @@
+org.apache.xmlrpc.test.AuthenticationTest$Adder=org.apache.xmlrpc.test.AuthenticationTest$AdderImpl
Propchange:
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/AuthenticationTest.properties
------------------------------------------------------------------------------
svn:executable = *