Author: asoldano
Date: 2014-10-07 12:29:15 -0400 (Tue, 07 Oct 2014)
New Revision: 18979
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/CXFClientConfigurer.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/SecurityActions.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/ServerBeanCustomizer.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/jaas/EJBServiceImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/jaas/ejb/META-INF/jaxws-endpoint-config.xml
Log:
[JBWS-3837] Apache CXF interceptors setup through properties
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java 2014-10-07
10:27:01 UTC (rev 18978)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java 2014-10-07
16:29:15 UTC (rev 18979)
@@ -40,6 +40,8 @@
public static final String CXF_QUEUE_LOW_WATER_MARK_PROP = "lowWaterMark";
public static final String CXF_QUEUE_DEQUEUE_TIMEOUT_PROP =
"dequeueTimeout";
public static final String CXF_POLICY_ALTERNATIVE_SELECTOR_PROP =
"cxf.policy.alternativeSelector";
+ public static final String CXF_IN_INTERCEPTORS_PROP =
"cxf.interceptors.in";
+ public static final String CXF_OUT_INTERCEPTORS_PROP =
"cxf.interceptors.out";
public static final String CXF_MANAGEMENT_ENABLED =
"cxf.management.enabled";
public static final String CXF_MANAGEMENT_INSTALL_RESPONSE_TIME_INTERCEPTORS =
"cxf.management.installResponseTimeInterceptors";
public static final String CXF_WS_DISCOVERY_ENABLED =
"cxf.ws-discovery.enabled";
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/CXFClientConfigurer.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/CXFClientConfigurer.java 2014-10-07
10:27:01 UTC (rev 18978)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/CXFClientConfigurer.java 2014-10-07
16:29:15 UTC (rev 18979)
@@ -21,21 +21,29 @@
*/
package org.jboss.wsf.stack.cxf.client.configuration;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import javax.xml.ws.Dispatch;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.InterceptorProvider;
import org.apache.cxf.jaxws.DispatchImpl;
import org.jboss.ws.api.util.ServiceLoader;
import org.jboss.ws.common.configuration.ConfigHelper;
+import org.jboss.ws.common.utils.DelegateClassLoader;
import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
import org.jboss.wsf.spi.metadata.config.ClientConfig;
import org.jboss.wsf.spi.security.JASPIAuthenticationProvider;
import org.jboss.wsf.stack.cxf.Loggers;
+import org.jboss.wsf.stack.cxf.client.Constants;
/**
* CXF extension of common ClientConfigurer
@@ -80,6 +88,7 @@
public void setConfigProperties(Client client, Map<String, String> properties)
{
client.getEndpoint().putAll(properties);
+ addInterceptors(client, properties);
}
private void savePropList(Client client, Map<String, String> props) {
@@ -92,9 +101,68 @@
String[] previousProps = (String[])ep.get(JBOSSWS_CXF_CLIENT_CONF_PROPS);
if (previousProps != null) {
for (String p : previousProps) {
+ if (Constants.CXF_IN_INTERCEPTORS_PROP.equals(p)) {
+ removeInterceptors(client.getInInterceptors(), (String)ep.get(p));
+ } else if (Constants.CXF_OUT_INTERCEPTORS_PROP.equals(p)) {
+ removeInterceptors(client.getOutInterceptors(), (String)ep.get(p));
+ }
ep.remove(p);
}
ep.remove(JBOSSWS_CXF_CLIENT_CONF_PROPS);
}
}
+
+ public void addInterceptors(InterceptorProvider interceptorProvider, Map<String,
String> properties) {
+ final String inInterceptors = properties.get(Constants.CXF_IN_INTERCEPTORS_PROP);
+ if (inInterceptors != null) {
+
interceptorProvider.getInInterceptors().addAll(createInterceptors(inInterceptors));
+ }
+ final String outInterceptors =
properties.get(Constants.CXF_OUT_INTERCEPTORS_PROP);
+ if (outInterceptors != null) {
+
interceptorProvider.getOutInterceptors().addAll(createInterceptors(outInterceptors));
+ }
+ }
+
+ private void removeInterceptors(List<Interceptor<?>> interceptorsList,
String interceptors) {
+ Set<String> set = new HashSet<String>();
+ StringTokenizer st = new StringTokenizer(interceptors, ", ", false);
+ while (st.hasMoreTokens()) {
+ set.add(st.nextToken());
+ }
+ List<Interceptor<?>> toBeRemoved = new
ArrayList<Interceptor<?>>();
+ for (Interceptor<?> itc : interceptorsList) {
+ if (set.contains(itc.getClass().getName())) {
+ toBeRemoved.add(itc);
+ }
+ }
+ interceptorsList.removeAll(toBeRemoved);
+ }
+
+ private static List<Interceptor<?>> createInterceptors(String propValue)
{
+ List<Interceptor<?>> list = new
ArrayList<Interceptor<?>>();
+ StringTokenizer st = new StringTokenizer(propValue, ", ", false );
+ while (st.hasMoreTokens()) {
+ String itc = st.nextToken();
+ Interceptor<?> interceptor = (Interceptor<?>)newInstance(itc);
+ if (interceptor != null) {
+ list.add(interceptor);
+ }
+ }
+ return list;
+ }
+
+ private static Object newInstance(String className)
+ {
+ try
+ {
+ ClassLoader loader = new
DelegateClassLoader(ClassLoaderProvider.getDefaultProvider()
+ .getServerIntegrationClassLoader(),
SecurityActions.getContextClassLoader());
+ Class<?> clazz = SecurityActions.loadClass(loader, className);
+ return clazz.newInstance();
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
}
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/SecurityActions.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/SecurityActions.java 2014-10-07
10:27:01 UTC (rev 18978)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/SecurityActions.java 2014-10-07
16:29:15 UTC (rev 18979)
@@ -23,6 +23,8 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
/**
*
@@ -99,6 +101,38 @@
}
/**
+ * Load a class using the provided classloader
+ *
+ * @param name
+ * @return
+ * @throws PrivilegedActionException
+ */
+ static Class<?> loadClass(final ClassLoader cl, final String name) throws
PrivilegedActionException, ClassNotFoundException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return cl.loadClass(name);
+ }
+ else
+ {
+ return AccessController.doPrivileged(new
PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws PrivilegedActionException
+ {
+ try
+ {
+ return cl.loadClass(name);
+ }
+ catch (Exception e)
+ {
+ throw new PrivilegedActionException(e);
+ }
+ }
+ });
+ }
+ }
+
+ /**
* Return the current value of the specified system property
*
* @param name
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/ServerBeanCustomizer.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/ServerBeanCustomizer.java 2014-10-07
10:27:01 UTC (rev 18978)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/ServerBeanCustomizer.java 2014-10-07
16:29:15 UTC (rev 18979)
@@ -33,7 +33,6 @@
import org.jboss.ws.api.util.ServiceLoader;
import org.jboss.ws.common.management.AbstractServerConfig;
import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
-import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
import org.jboss.wsf.spi.management.ServerConfig;
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-10-07
10:27:01 UTC (rev 18978)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-10-07
16:29:15 UTC (rev 18979)
@@ -44,6 +44,7 @@
import org.jboss.wsf.spi.metadata.config.SOAPAddressRewriteMetadata;
import org.jboss.wsf.stack.cxf.Loggers;
import org.jboss.wsf.stack.cxf.addressRewrite.SoapAddressRewriteHelper;
+import org.jboss.wsf.stack.cxf.client.configuration.CXFClientConfigurer;
/**
@@ -97,14 +98,17 @@
Map<String, String> epConfProps = config.getProperties();
if (!epConfProps.isEmpty())
{
- if (getProperties() == null)
+ final Map<String, Object> propMap = getProperties();
+ if (propMap == null)
{
setProperties(new HashMap<String, Object>(epConfProps));
}
else
{
- getProperties().putAll(epConfProps);
+ propMap.putAll(epConfProps);
}
+ CXFClientConfigurer helper = new CXFClientConfigurer();
+ helper.addInterceptors(this, epConfProps);
}
//handlers config is done later, as when this methods is called getBinding()
can't
//be used without messing with the servlet destinations due to the endpoint
address
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/jaas/EJBServiceImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/jaas/EJBServiceImpl.java 2014-10-07
10:27:01 UTC (rev 18978)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/jaas/EJBServiceImpl.java 2014-10-07
16:29:15 UTC (rev 18979)
@@ -43,8 +43,6 @@
)
@SecurityDomain("JBossWS")
@EndpointConfig(configFile = "META-INF/jaxws-endpoint-config.xml", configName =
"Custom WS-Security Endpoint")
-//be sure to have dependency on org.apache.cxf module when on AS7, otherwise Apache CXF
annotations are ignored
-@InInterceptors(interceptors =
{"org.jboss.wsf.stack.cxf.security.authentication.SubjectCreatingPolicyInterceptor"})
public class EJBServiceImpl
{
// Provide logging
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/jaas/ejb/META-INF/jaxws-endpoint-config.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/jaas/ejb/META-INF/jaxws-endpoint-config.xml 2014-10-07
10:27:01 UTC (rev 18978)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/jaas/ejb/META-INF/jaxws-endpoint-config.xml 2014-10-07
16:29:15 UTC (rev 18979)
@@ -9,6 +9,10 @@
<property-name>ws-security.validate.token</property-name>
<property-value>false</property-value>
</property>
+ <property>
+ <property-name>cxf.interceptors.in</property-name>
+
<property-value>org.jboss.wsf.stack.cxf.security.authentication.SubjectCreatingPolicyInterceptor</property-value>
+ </property>
</endpoint-config>
</jaxws-config>
\ No newline at end of file