This is an automated email from the ASF dual-hosted git repository. robertlazarski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-rampart.git
commit 80d31a59d1def20949bdffab9789dbe4eec878cd Author: Robert Lazarski <[email protected]> AuthorDate: Wed Nov 18 12:54:32 2026 -1000 RAMPART-450: let the STS request inherit the client's transport settings RampartUtil.getToken built a fresh Options for the STS client and copied only the user name and password, so a proxy, timeout or other HTTP setting on the service client's options never reached the token request and the first call timed out behind a proxy. The connection-level properties now carry over; HTTP credentials, headers, cookies and the Rampart policy properties stay with the service call. StsClientTransportSettingsTest covers both sides. Co-Authored-By: Claude Fable 5.1 <[email protected]> --- .../java/org/apache/rampart/util/RampartUtil.java | 47 +++++++++++- .../rampart/StsClientTransportSettingsTest.java | 86 ++++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java b/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java index 28099363..16109271 100644 --- a/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java +++ b/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java @@ -26,6 +26,7 @@ import org.apache.axiom.soap.*; import org.apache.axis2.AxisFault; import org.apache.axis2.addressing.AddressingConstants; import org.apache.axis2.client.Options; +import org.apache.axis2.kernel.http.HTTPConstants; import org.apache.axis2.context.MessageContext; import org.apache.axis2.dataretrieval.DRConstants; import org.apache.axis2.dataretrieval.client.MexClient; @@ -787,6 +788,49 @@ public class RampartUtil { * @return Return the identifier of the obtained token * @throws RampartException If the arguments are malformed. */ + /** + * HTTP transport properties the token request to the STS inherits from the + * service request it is made on behalf of (RAMPART-450). The STS client builds + * its own Options, so without this a proxy or timeout set on the client is + * silently dropped for the first, token-issuing call. Only connection-level + * settings are listed: the service's HTTP credentials, custom headers and + * cookies belong to the service, and the Rampart policy properties must not + * override the issuer policy the STS client sets itself. + */ + private static final String[] INHERITED_TRANSPORT_PROPERTIES = { + HTTPConstants.PROXY, + HTTPConstants.SO_TIMEOUT, + HTTPConstants.CONNECTION_TIMEOUT, + HTTPConstants.CHUNKED, + HTTPConstants.HTTP_PROTOCOL_VERSION, + HTTPConstants.USER_AGENT, + HTTPConstants.COOKIE_POLICY, + HTTPConstants.MC_GZIP_REQUEST, + HTTPConstants.MC_ACCEPT_GZIP, + HTTPConstants.REUSE_HTTP_CLIENT, + HTTPConstants.CACHED_HTTP_CLIENT, + HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER + }; + + /** + * Copies the transport settings of the service request into the Options used + * for the token request to the STS. + * @param msgContext The service request's message context. + * @param stsOptions The Options the STS client will use. + */ + public static void inheritTransportSettings(MessageContext msgContext, Options stsOptions) { + for (String name : INHERITED_TRANSPORT_PROPERTIES) { + Object value = msgContext.getProperty(name); + if (value != null) { + stsOptions.setProperty(name, value); + } + } + Options serviceOptions = msgContext.getOptions(); + if (serviceOptions != null) { + stsOptions.setTimeOutInMilliSeconds(serviceOptions.getTimeOutInMilliSeconds()); + } + } + public static String getToken(RampartMessageData rmd, OMElement rstTemplate, String issuerEpr, String action, Policy issuerPolicy) throws RampartException { @@ -830,9 +874,10 @@ public class RampartUtil { } Options options = new Options(); - + options.setUserName(rmd.getMsgContext().getOptions().getUserName()); options.setPassword(rmd.getMsgContext().getOptions().getPassword()); + inheritTransportSettings(msgContext, options); /* The commons httpclient 3.x code isn't compatible with 4.x and there doesn't seem to be test coverage for it. diff --git a/modules/rampart-tests/src/test/java/org/apache/rampart/StsClientTransportSettingsTest.java b/modules/rampart-tests/src/test/java/org/apache/rampart/StsClientTransportSettingsTest.java new file mode 100644 index 00000000..010c9fd1 --- /dev/null +++ b/modules/rampart-tests/src/test/java/org/apache/rampart/StsClientTransportSettingsTest.java @@ -0,0 +1,86 @@ +/* + * 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.rampart; + +import org.apache.axis2.client.Options; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.kernel.http.HTTPConstants; +import org.apache.rampart.util.RampartUtil; + +/** + * RAMPART-450: the token request to the STS must go through the proxy and + * connection settings of the service request, while the service's own HTTP + * credentials and the Rampart policy stay behind. The values are opaque to the + * copy, so placeholders stand in for the transport's own property classes. + */ +public class StsClientTransportSettingsTest extends MessageBuilderTestBase { + + public void testProxyAndConnectionSettingsAreInherited() throws Exception { + MessageContext ctx = getMsgCtx(); + Options serviceOptions = ctx.getOptions(); + + Object proxy = new Object(); + serviceOptions.setProperty(HTTPConstants.PROXY, proxy); + serviceOptions.setProperty(HTTPConstants.SO_TIMEOUT, 5000); + serviceOptions.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 2000); + serviceOptions.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); + serviceOptions.setTimeOutInMilliSeconds(42000); + + Options stsOptions = new Options(); + RampartUtil.inheritTransportSettings(ctx, stsOptions); + + assertSame(proxy, stsOptions.getProperty(HTTPConstants.PROXY)); + assertEquals(5000, stsOptions.getProperty(HTTPConstants.SO_TIMEOUT)); + assertEquals(2000, stsOptions.getProperty(HTTPConstants.CONNECTION_TIMEOUT)); + assertEquals(Boolean.FALSE, stsOptions.getProperty(HTTPConstants.CHUNKED)); + assertEquals(42000, stsOptions.getTimeOutInMilliSeconds()); + } + + public void testSettingsFromTheConfigurationContextAreInheritedToo() throws Exception { + MessageContext ctx = getMsgCtx(); + Object proxy = new Object(); + ctx.getConfigurationContext().setProperty(HTTPConstants.PROXY, proxy); + + Options stsOptions = new Options(); + RampartUtil.inheritTransportSettings(ctx, stsOptions); + + assertSame(proxy, stsOptions.getProperty(HTTPConstants.PROXY)); + } + + public void testServiceCredentialsHeadersAndPolicyStayBehind() throws Exception { + MessageContext ctx = getMsgCtx(); + Options serviceOptions = ctx.getOptions(); + serviceOptions.setProperty(HTTPConstants.AUTHENTICATE, new Object()); + serviceOptions.setProperty(HTTPConstants.HTTP_HEADERS, new java.util.ArrayList<Object>()); + serviceOptions.setProperty(HTTPConstants.COOKIE_STRING, "JSESSIONID=1"); + serviceOptions.setProperty(RampartMessageData.KEY_RAMPART_POLICY, + loadPolicy("test-resources/policy/rampart-asymm-binding-6-3des-r15.xml")); + serviceOptions.setProperty(RampartMessageData.KEY_CUSTOM_ISSUED_TOKEN, "#tok"); + + Options stsOptions = new Options(); + RampartUtil.inheritTransportSettings(ctx, stsOptions); + + assertNull(stsOptions.getProperty(HTTPConstants.AUTHENTICATE)); + assertNull(stsOptions.getProperty(HTTPConstants.HTTP_HEADERS)); + assertNull(stsOptions.getProperty(HTTPConstants.COOKIE_STRING)); + assertNull(stsOptions.getProperty(RampartMessageData.KEY_RAMPART_POLICY)); + assertNull(stsOptions.getProperty(RampartMessageData.KEY_CUSTOM_ISSUED_TOKEN)); + } +}
