Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
JBWS-3541: Initial support for adding ws-security to wsrp using cxf a…
Browse files Browse the repository at this point in the history
…nd interceptors.
  • Loading branch information
mwringe authored and metacosm committed Sep 29, 2012
1 parent 3692358 commit f254588
Show file tree
Hide file tree
Showing 22 changed files with 1,111 additions and 1 deletion.
50 changes: 50 additions & 0 deletions cxf-integration/pom.xml
@@ -0,0 +1,50 @@
<!--
~ JBoss, a division of Red Hat
~ Copyright 2011, Red Hat Middleware, LLC, and individual
~ contributors as indicated by the @authors tag. See the
~ copyright.txt in the distribution for a full listing of
~ individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.gatein.wsrp</groupId>
<artifactId>wsrp-parent</artifactId>
<version>2.2.0-Beta05-SNAPSHOT</version>
</parent>

<artifactId>wsrp-cxf-integration</artifactId>
<packaging>jar</packaging>
<name>GateIn WSRP CXF Integration</name>
<description>Provides an integration point into cxf for advanced configuration and customizations.</description>

<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,150 @@
/******************************************************************************
* JBoss, a division of Red Hat *
* Copyright 2012, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
* *
* This is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2.1 of *
* the License, or (at your option) any later version. *
* *
* This software is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this software; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
******************************************************************************/
package org.gatein.wsrp.cxf;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.cxf.feature.AbstractFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The role of this class is to provide a means to add a list of features to wsrp-service classes at
* runtime since cxf lacks a means of externally configuring these classes outside of using spring.
*
* This class with look for a specific property file located in the configuration directory with a list
* of feature classes. It will then use reflection to create these classes. The WSRPEndpointFeature will
* call these classes, if any are configured, when ever its own feature methods are called.
*
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
*/
public class FeatureIntegratorFactory
{
private static Logger log = LoggerFactory.getLogger(FeatureIntegratorFactory.class);

protected final static FeatureIntegratorFactory instance = new FeatureIntegratorFactory();

protected List<AbstractFeature> features = new ArrayList<AbstractFeature>();

public static final String DEFAULT_CXF_FEATURES_CONFIG_FILE_NAME = "producer.features";

public FeatureIntegratorFactory()
{
try
{
String wsrpCXFConfDir = Utils.getWSRPCXFConfigDirectory();

File featuresPropertyFile = new File(wsrpCXFConfDir + File.separator + DEFAULT_CXF_FEATURES_CONFIG_FILE_NAME);

if (featuresPropertyFile.exists())
{
FileInputStream fileInStream = new FileInputStream(featuresPropertyFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(fileInStream));

String featureClassName = reader.readLine();
while (featureClassName != null)
{
//Don't use the class if its commented out using '#' or '!'
//TODO: can we read this as normal property file but with null values?
if (!featureClassName.trim().startsWith("#") && !featureClassName.trim().startsWith("!"))
{
AbstractFeature feature = createFeature(featureClassName);
if (feature != null)
{
features.add(feature);
}
}
featureClassName = reader.readLine();
}
reader.close();
}
else
{
log.debug("The wsrp cxf features configuration file does not exist [" + featuresPropertyFile + "]. No features will be added to the wsrp producer service classes.");
}
}
catch (Exception e)
{
log.error("Error processing GateIn CXF Feature configuration files", e);
}
}

/**
* Returns an instance of the FeatureIntegratorFactory
*
* @return The FeatureIntegratorFactory instance
*/
public static FeatureIntegratorFactory getInstance()
{
return instance;
}

/**
* Returns the features
*
* @return The features
*/
public List<AbstractFeature> getFeatures()
{
return features;
}

/**
* Constructs an AbstractFeature class based on the passed classname.
*
* Note: the AbstractFeature must have an empty constructor.
*
* @param className The class to create
* @return The constructed AbstractFeature
*/
protected AbstractFeature createFeature (String className)
{
try
{
Class clazz = Class.forName(className);
Object object = clazz.getConstructor().newInstance();

if (object instanceof AbstractFeature)
{
return (AbstractFeature)object;
}
else
{
log.error("Class " + className + " listed in feature file is not of type AbstractFeature. This entry is ignored.");
}
}
catch (Exception e)
{
log.error("Error try to create class " + className + " listed in the the feature file. This entry will be ignored.", e);
}

return null;
}

}
64 changes: 64 additions & 0 deletions cxf-integration/src/main/java/org/gatein/wsrp/cxf/Utils.java
@@ -0,0 +1,64 @@
/******************************************************************************
* JBoss, a division of Red Hat *
* Copyright 2012, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
* *
* This is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2.1 of *
* the License, or (at your option) any later version. *
* *
* This software is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this software; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
******************************************************************************/
package org.gatein.wsrp.cxf;

import java.io.File;

/**
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
*/
public class Utils
{
/**
* System property to specify location of wsrp configuration files
*/
public static final String GATEIN_WSRP_CONF_DIR = "gatein.wsrp.conf.dir";

/**
* System property to specify location of gatein configuration files
*/
public static final String GATEIN_CONF_DIR = "gatein.conf.dir";

/**
* Default names for the cxf configuration directory
*/
public static final String DEFAULT_WSRP_CONF_DIR_NAME = "wsrp";
public static final String DEFAULT_WSRP_CXF_CONF_DIR_NAME = "cxf";

public static String getWSRPCXFConfigDirectory()
{
String gateinWSRPConfDir = System.getProperty(GATEIN_WSRP_CONF_DIR);

if (gateinWSRPConfDir == null)
{
String gateinConfDir = System.getProperty(GATEIN_CONF_DIR);
gateinWSRPConfDir = gateinConfDir + File.separator + DEFAULT_WSRP_CONF_DIR_NAME;
}

String wsrpCXFConfDir = gateinWSRPConfDir + File.separator + DEFAULT_WSRP_CXF_CONF_DIR_NAME;

return wsrpCXFConfDir;
}
}

@@ -0,0 +1,97 @@
/******************************************************************************
* JBoss, a division of Red Hat *
* Copyright 2012, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
* *
* This is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2.1 of *
* the License, or (at your option) any later version. *
* *
* This software is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this software; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
******************************************************************************/
package org.gatein.wsrp.cxf;

import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.interceptor.InterceptorProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A cxf feature whose role is to call the list of actual features from the FeatureIntegrationFactory.
*
* Note: we can only pass a feature to the service methods using a cxf annotation, and not an external
* configuration file (since that requires integrating spring with the application server running cxf).
* Since the annotation requires a hardcoded feature class name, we need a class like this to allow for
* runtime management of features to be added.
*
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
*/
public class WSRPEndpointFeature extends AbstractFeature
{

private static Logger log = LoggerFactory.getLogger(WSRPEndpointFeature.class);

FeatureIntegratorFactory featureIntergrator;

public WSRPEndpointFeature()
{
log.debug("Construct WSRPEndpointFeature");
featureIntergrator = FeatureIntegratorFactory.getInstance();
}

@Override
public void initialize(Bus bus)
{
for (AbstractFeature feature : featureIntergrator.getFeatures())
{
log.debug("Initializing Bus with " + feature.toString());
feature.initialize(bus);
}
}

@Override
public void initialize(Client client, Bus bus)
{
for (AbstractFeature feature : featureIntergrator.getFeatures())
{
log.debug("Initializing Client with " + feature.toString());
feature.initialize(client, bus);
}
}

@Override
public void initialize(InterceptorProvider interceptorProvider, Bus bus)
{
for (AbstractFeature feature : featureIntergrator.getFeatures())
{
log.debug("Initializing InterceptorProvider with " + feature.toString());
feature.initialize(interceptorProvider, bus);
}
}

@Override
public void initialize(Server server, Bus bus)
{
for (AbstractFeature feature : featureIntergrator.getFeatures())
{
log.debug("Initializing Server with " + feature.toString());
feature.initialize(server, bus);
}
}
}

0 comments on commit f254588

Please sign in to comment.