[jboss-svn-commits] JBL Code SVN: r28600 - in labs/jbossesb/trunk/product: services/slsb and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 30 09:10:57 EDT 2009
Author: beve
Date: 2009-07-30 09:10:57 -0400 (Thu, 30 Jul 2009)
New Revision: 28600
Added:
labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/ConfigBuilder.java
Modified:
labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
labs/jbossesb/trunk/product/services/slsb/build.xml
labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions/EJBProcessor.java
labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/EJBProcessorUnitTest.java
labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/MockEjbProcessor.java
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2695 "Add jndi security support to EJBProcessor".
Modified: labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
===================================================================
(Binary files differ)
Modified: labs/jbossesb/trunk/product/services/slsb/build.xml
===================================================================
--- labs/jbossesb/trunk/product/services/slsb/build.xml 2009-07-30 12:56:16 UTC (rev 28599)
+++ labs/jbossesb/trunk/product/services/slsb/build.xml 2009-07-30 13:10:57 UTC (rev 28600)
@@ -3,7 +3,11 @@
<property file="build.properties"/>
<!-- Import the base Ant build script... -->
<import file="${services.base.build}"/>
-
+
+ <target name="jar" depends="compile,check.for.files" unless="dir_empty">
+ <jar basedir="build/classes" destfile="build/jbossesb-${ant.project.name}.jar" includes="**/EJBProcessor*.class" excludes="**/*Test*.class"/>
+ </target>
+
<target name="test" depends="base.test"/>
Modified: labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions/EJBProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions/EJBProcessor.java 2009-07-30 12:56:16 UTC (rev 28599)
+++ labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions/EJBProcessor.java 2009-07-30 13:10:57 UTC (rev 28600)
@@ -43,8 +43,12 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
import org.apache.log4j.Logger;
+import org.jboss.security.auth.callback.AppCallbackHandler;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
@@ -52,19 +56,23 @@
/**
* EJBProcessor is an action that can call stateless session beans
- * deployed in an application server.
+ * deployed in an application server.
* <p/>
* This implementation currently supports EJB2.x and EJB3.x session beans.
- *
+ *
* Example EJB 2.x configuration:
* <pre>{@code
* <action name="EJBTest" class="org.jboss.soa.esb.actions.EJBProcessor">
* <property name="ejb-name" value="MyBean" />
* <property name="jndi-name" value="ejb/MyBean" />
* <property name="initial-context-factory" value="org.jnp.interfaces.NamingContextFactory" />
+ * <property name="security-principal" value="username" />
+ * <property name="security-credentials" value="password" />
+ * <!-- Optional property for JAAS login -->"
+ * <property name="security-login-module" value="securityDomain" />
* <property name="provider-url" value="localhost:1099" />
* <property name="method" value="login" />
- *
+ *
* <!-- Optional output location, defaults to "DEFAULT_EJB_OUT"
* <property name="esb-out-var" value="MY_OUT_LOCATION"/> -->
* <property name="ejb-params">
@@ -74,16 +82,20 @@
* </property>
* </action>
* }</pre>
- *
+ *
* Example EJB 3.x configuration:
* <pre>{@code
* <action name="EJBTest" class="org.jboss.soa.esb.actions.EJBProcessor">
* <property name="ejb3" value="true" />
* <property name="jndi-name" value="ejb/MyBean" />
* <property name="initial-context-factory" value="org.jnp.interfaces.NamingContextFactory" />
+ * <property name="security-principal" value="username" />
+ * <property name="security-credentials" value="password" />
+ * <!-- Optional property for JAAS login -->"
+ * <property name="security-login-module" value="securityDomain" />
* <property name="provider-url" value="localhost:1099" />
* <property name="method" value="login" />
- *
+ *
* <!-- Optional output location, defaults to "DEFAULT_EJB_OUT"
* <property name="esb-out-var" value="MY_OUT_LOCATION"/> -->
* <property name="ejb-params">
@@ -93,7 +105,7 @@
* </property>
* </action>
* }</pre>
- *
+ *
*/
public class EJBProcessor extends AbstractActionLifecycle
{
@@ -114,8 +126,12 @@
public static final String OUT_VAR = "esb-out-var";
public static final String DEFAULT_OUT = "DEFAULT_EJB_OUT";
+
+ public static final String EJB3_ATTRIBUTE = "ejb3";
- public static final String EJB3_ATTRIBUTE = "ejb3";
+ public static final String SECURITY_PRINCIPAL = "security-principal";
+ public static final String SECURITY_CREDENTIALS = "security-credentials";
+ public static final String SECURITY_LOGIN_MODULE = "security-login-module";
public static final int ARG_PREFIX_LENGTH = 3;
@@ -126,15 +142,17 @@
private Map<Integer, Argument> ejbParams;
private List<String> ejbParamTypeNames;
-
+
private EJBHome ejbHome;
private EJBObject ejbObject;
private Object ejb3Interface;
private boolean ejb3;
-
-
+
+ private LoginContext loginContext;
+
+
public EJBProcessor(ConfigTree config)
{
configTree = config;
@@ -164,7 +182,7 @@
// invoke EJB2.x
ret = invoke( ejbHome.getEJBMetaData().getRemoteInterfaceClass(), ejbObject, ejbRef.get(EJB_METHOD), param);
}
-
+
// add return object to messages output location
if ( ret != null )
{
@@ -184,6 +202,7 @@
return msg;
}
+ @Override
public void initialise () throws ActionLifecycleException
{
/*
@@ -191,11 +210,11 @@
* all of this data is statically defined and not
* modified by the incoming Message during process execution.
*/
-
+
ejbRef = new HashMap<String, String>();
ejbParams = new HashMap<Integer, Argument>();
ejbParamTypeNames = new ArrayList<String>();
-
+
ejb3 = Boolean.parseBoolean(configTree.getAttribute(EJB3_ATTRIBUTE, "false"));
// get properties common to both EJB2.x and EJB3.x
@@ -203,10 +222,10 @@
ejbRef.put(EJB_METHOD, configTree.getAttribute(EJB_METHOD));
ejbRef.put(INICTXFACTORY, configTree.getAttribute(INICTXFACTORY));
ejbRef.put(PROVIDERURL, configTree.getAttribute(PROVIDERURL));
-
+
if ( !ejb3 )
ejbRef.put(EJB_NAME, configTree.getAttribute(EJB_NAME));
-
+
if (configTree.getAttribute(OUT_VAR) != null)
{
ejbRef.put(OUT_VAR, configTree.getAttribute(OUT_VAR));
@@ -215,7 +234,7 @@
{
ejbRef.put(OUT_VAR, DEFAULT_OUT);
}
-
+
// Get all parameters for the EJB method, defined in jboss-esb.xml
ConfigTree[] subElements = configTree.getAllChildren();
@@ -241,15 +260,40 @@
throw new ActionLifecycleException( "Error configuring EJBProcessor.[" + entry.getKey() + "] must not be null");
}
}
-
+
// Build Properties for InitialContext lookup
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, ejbRef.get(INICTXFACTORY));
props.put(Context.PROVIDER_URL, ejbRef.get(PROVIDERURL));
+ // extract security principal from config
+ final String username = configTree.getAttribute(SECURITY_PRINCIPAL);
+ if (username != null)
+ {
+ // extract security credential from config
+ final String password = configTree.getAttribute(SECURITY_CREDENTIALS);
+ if (password == null)
+ {
+ throw new ActionLifecycleException("'" + SECURITY_CREDENTIALS + "' configuration property is missing from esb configuration. It is required when '" + SECURITY_PRINCIPAL + "' is specified");
+ }
+ // Check if a jaas login module was specified. If so use a jaas login.
+ final String loginModuleName = configTree.getAttribute(SECURITY_LOGIN_MODULE);
+ if (loginModuleName != null)
+ {
+ login(loginModuleName, createCallbackHandler(configTree));
+ }
+ // assume that the principal and credential are to be used by the initial context factory.
+ else
+ {
+ props.setProperty(Context.SECURITY_CREDENTIALS, password);
+ props.setProperty(Context.SECURITY_PRINCIPAL, username);
+ }
+ }
+
InitialContext initCtx = getInitialContext(props);
-
+
+
if ( ejb3 )
{
ejb3Interface = getEjb3FromJndi(initCtx);
@@ -263,7 +307,7 @@
// Get the EJB metadata
EJBMetaData metaData = ejbHome.getEJBMetaData();
- Class homeClass = metaData.getHomeInterfaceClass();
+ Class<?> homeClass = metaData.getHomeInterfaceClass();
// convert handle to real home type
ejbHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow(ejbHome, homeClass);
@@ -273,7 +317,7 @@
throw new ActionLifecycleException("Only SLSBs are supported!");
}
- ejbObject = (EJBObject) this.create(homeClass, ejbHome);
+ ejbObject = (EJBObject) EJBProcessor.create(homeClass, ejbHome);
}
catch (Exception e)
{
@@ -281,7 +325,7 @@
}
}
}
-
+
InitialContext getInitialContext(final Properties props) throws ActionLifecycleException
{
InitialContext context;
@@ -294,7 +338,7 @@
}
return context;
}
-
+
Object getEjb3FromJndi(final Context context) throws ActionLifecycleException
{
Object ejb3Interface;
@@ -308,8 +352,51 @@
return ejb3Interface;
}
- private static Object create (Class c, Object obj) throws Exception
+ /**
+ * Creates an {@link AppCallbackHandler} that takes a username and password.
+ * This method is protected to let subclasses override it to implement other
+ * security authentication mechanisms.
+ *
+ * @param config The configuration for this action. Gives access to all config parameters.
+ * @return CallbackHandler A callback handler that suitable for the login module configured.
+ */
+ protected CallbackHandler createCallbackHandler(final ConfigTree config)
{
+ final String username = configTree.getAttribute(SECURITY_PRINCIPAL);
+ return new AppCallbackHandler(username, ((String)configTree.getAttribute(SECURITY_CREDENTIALS)).toCharArray());
+ }
+
+ void login(final String loginModuleName, final CallbackHandler callbackHandler) throws ActionLifecycleException
+ {
+ try
+ {
+ loginContext = new LoginContext (loginModuleName, callbackHandler);
+ loginContext.login();
+ }
+ catch (final Exception e)
+ {
+ throw new ActionLifecycleException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public void destroy()
+ {
+ if (loginContext != null)
+ {
+ try
+ {
+ loginContext.logout();
+ }
+ catch (LoginException e)
+ {
+ log.warn(e.getMessage(), e);
+ }
+ }
+ }
+
+ private static Object create (Class<?> c, Object obj) throws Exception
+ {
Object ret = null;
Method create = c.getMethod("create");
@@ -318,14 +405,14 @@
return ret;
}
- private Object invoke (Class c, Object obj, String mname, Object[] params) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
+ private Object invoke (Class<?> c, Object obj, String mname, Object[] params) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
// The return Object
Object r = null;
// Assemble method signature array
- Class[] sigArray = new Class[ejbParams.size()];
+ Class<?>[] sigArray = new Class[ejbParams.size()];
for (int i = 0; i < ejbParams.size(); i++)
{
sigArray[i] = ClassUtil.forName(ejbParams.get(i).getType(), getClass());
@@ -339,7 +426,7 @@
return r;
}
-
+
// Helper inner class for method arguments and where to find it in the esb
// message
class Argument
Added: labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/ConfigBuilder.java
===================================================================
--- labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/ConfigBuilder.java (rev 0)
+++ labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/ConfigBuilder.java 2009-07-30 13:10:57 UTC (rev 28600)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, Red Hat Middleware
+ * LLC, and individual contributors 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.jboss.soa.esb.actions;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class ConfigBuilder
+{
+ private ConfigTree config;
+
+ // key=type
+ // value=location
+ private Map<String, String> args;
+
+ public ConfigBuilder()
+ {
+ config = new ConfigTree("ejbprocessor");
+ }
+
+ public ConfigBuilder methodName(final String methodName)
+ {
+ if (methodName != null)
+ config.setAttribute(EJBProcessor.EJB_METHOD, methodName);
+ return this;
+ }
+
+ public ConfigBuilder outputLocation(final String outputLocation)
+ {
+ if (outputLocation != null)
+ config.setAttribute(EJBProcessor.OUT_VAR, outputLocation);
+ return this;
+ }
+
+ public ConfigBuilder jndiName(final String jndiName)
+ {
+ if (jndiName != null)
+ config.setAttribute(EJBProcessor.JNDI_NAME, jndiName);
+ return this;
+ }
+
+ public ConfigBuilder initCtxFactory(final String factory)
+ {
+ if (factory != null)
+ config.setAttribute(EJBProcessor.INICTXFACTORY, factory);
+ return this;
+ }
+
+ public ConfigBuilder providerUrl(final String url)
+ {
+ if (url != null)
+ config.setAttribute(EJBProcessor.PROVIDERURL, url);
+ return this;
+ }
+
+ public ConfigBuilder isEjb3(final Boolean on)
+ {
+ if (on != null)
+ config.setAttribute(EJBProcessor.EJB3_ATTRIBUTE, on.toString());
+ return this;
+ }
+
+ public ConfigBuilder arg(final Class<?> type, final String location)
+ {
+ if (args == null)
+ args = new LinkedHashMap<String, String>();
+
+ args.put(type.getName(), location);
+ return this;
+ }
+
+ public ConfigBuilder username(final String username)
+ {
+ if (username != null)
+ config.setAttribute(EJBProcessor.SECURITY_PRINCIPAL, username);
+ return this;
+ }
+
+ public ConfigBuilder password(final String password)
+ {
+ if (password != null)
+ config.setAttribute(EJBProcessor.SECURITY_CREDENTIALS, password);
+ return this;
+ }
+
+ public ConfigBuilder securityLoginModule(String moduleName)
+ {
+ if (moduleName != null)
+ config.setAttribute(EJBProcessor.SECURITY_LOGIN_MODULE, moduleName);
+ return this;
+ }
+
+ public ConfigTree build()
+ {
+ if (args != null)
+ {
+ int i = 0;
+ Set<Entry<String, String>> entrySet = args.entrySet();
+ for (Entry<String, String> entry : entrySet)
+ {
+ ConfigTree arg = new ConfigTree("arg" + i, config);
+ arg.setAttribute("type", entry.getKey());
+ arg.addTextChild(entry.getValue());
+ i++;
+ }
+ }
+ return config;
+ }
+
+}
+
Modified: labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/EJBProcessorUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/EJBProcessorUnitTest.java 2009-07-30 12:56:16 UTC (rev 28599)
+++ labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/EJBProcessorUnitTest.java 2009-07-30 13:10:57 UTC (rev 28600)
@@ -2,17 +2,17 @@
* JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
* LLC, and individual contributors 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
@@ -23,8 +23,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+
import junit.framework.JUnit4TestAdapter;
+import org.jboss.security.auth.callback.AppCallbackHandler;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
@@ -33,7 +39,7 @@
/**
* Unittest for {@link EJBProcessor}
- *
+ *
* @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
*/
public class EJBProcessorUnitTest
@@ -41,65 +47,176 @@
final String payloadLocation = "location";
final String payload = "Hello, hello Clarice";
final String outputLocation = "output";
-
+
@Test
public void processEjb3() throws ActionLifecycleException, ActionProcessingException, ConfigurationException
{
Message message = MessageFactory.getInstance().getMessage();
message.getBody().add(payloadLocation, payload);
- EJBProcessor processor = new MockEjbProcessor(createConfigTree(payloadLocation, "printMessage", outputLocation));
+ final ConfigBuilder builder = new ConfigBuilder();
+ builder.methodName("printMessage");
+ builder.outputLocation(outputLocation);
+ builder.jndiName("Simple");
+ builder.isEjb3(true);
+ builder.initCtxFactory("org.jnp.interfaces.NamingContextFactory");
+ builder.providerUrl("jnp://localhost:1099");
+ builder.arg(String.class, payloadLocation);
+
+ final ConfigTree config = builder.build();
+
+ EJBProcessor processor = new MockEjbProcessor(config);
processor.initialise();
-
+
Message process = processor.process(message);
assertNull( process.getBody().get(outputLocation));
}
-
+
@Test
public void processEjb3WithReturnValue() throws ActionLifecycleException, ActionProcessingException, ConfigurationException
{
Message message = MessageFactory.getInstance().getMessage();
message.getBody().add(payloadLocation, payload);
- EJBProcessor processor = new MockEjbProcessor(createConfigTree(payloadLocation, "printMessageAndReturn", outputLocation));
+ final ConfigBuilder builder = new ConfigBuilder();
+ builder.methodName("printMessageAndReturn");
+ builder.outputLocation(outputLocation);
+ builder.jndiName("Simple");
+ builder.isEjb3(true);
+ builder.initCtxFactory("org.jnp.interfaces.NamingContextFactory");
+ builder.providerUrl("jnp://localhost:1099");
+ builder.arg(String.class, payloadLocation);
+ final ConfigTree config = builder.build();
+
+ EJBProcessor processor = new MockEjbProcessor(config);
processor.initialise();
-
+
Message process = processor.process(message);
Object object = process.getBody().get(outputLocation);
assertTrue( object instanceof String);
assertEquals( payload, object );
}
-
+
@Test (expected = ActionLifecycleException.class )
- public void initWithNullValue() throws ActionLifecycleException, ActionProcessingException, ConfigurationException
+ public void initWithNullMethodName() throws ActionLifecycleException, ActionProcessingException, ConfigurationException
{
Message message = MessageFactory.getInstance().getMessage();
message.getBody().add(payloadLocation, payload);
- EJBProcessor processor = new MockEjbProcessor(createConfigTree(payloadLocation, null, outputLocation));
+ final ConfigBuilder builder = new ConfigBuilder();
+ builder.outputLocation(outputLocation);
+ builder.jndiName("Simple");
+ builder.isEjb3(true);
+ builder.initCtxFactory("org.jnp.interfaces.NamingContextFactory");
+ builder.providerUrl("jnp://localhost:1099");
+ builder.arg(String.class, payloadLocation);
+ final ConfigTree config = builder.build();
+
+ EJBProcessor processor = new MockEjbProcessor(config);
processor.initialise();
}
- private ConfigTree createConfigTree(final String payloadLocation, final String methodName, String outputLocation)
+ @Test
+ public void nullPayload() throws ActionLifecycleException, ActionProcessingException, ConfigurationException
{
- ConfigTree configTree = new ConfigTree("ejb-processor");
- configTree.setAttribute(EJBProcessor.EJB3_ATTRIBUTE, "true");
+ Message message = MessageFactory.getInstance().getMessage();
+ // Not adding a message body
- configTree.setAttribute(EJBProcessor.JNDI_NAME, "Simple");
- configTree.setAttribute(EJBProcessor.EJB_METHOD, methodName);
- configTree.setAttribute(EJBProcessor.INICTXFACTORY, "org.jnp.interfaces.NamingContextFactory");
- configTree.setAttribute(EJBProcessor.PROVIDERURL, "jnp://localhost:1099");
- configTree.setAttribute(EJBProcessor.OUT_VAR, outputLocation);
- ConfigTree arg0 = new ConfigTree("arg0", configTree);
- arg0.setAttribute("type", "java.lang.String");
- arg0.addTextChild(payloadLocation);
-
- return configTree;
+ final ConfigBuilder builder = new ConfigBuilder();
+ builder.methodName("printMessage");
+ builder.outputLocation(outputLocation);
+ builder.jndiName("Simple");
+ builder.isEjb3(true);
+ builder.initCtxFactory("org.jnp.interfaces.NamingContextFactory");
+ builder.providerUrl("jnp://localhost:1099");
+ builder.arg(String.class, null);
+ final ConfigTree config = builder.build();
+
+ EJBProcessor processor = new MockEjbProcessor(config);
+ processor.initialise();
+ Message process = processor.process(message);
+ Object object = process.getBody().get(outputLocation);
+ assertNull(object);
}
+ @Test
+ public void verifySecurityConfig() throws ActionLifecycleException, ActionProcessingException, ConfigurationException
+ {
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().add(payloadLocation, payload);
+
+ final ConfigBuilder builder = new ConfigBuilder();
+ builder.methodName("printMessageAndReturn");
+ builder.outputLocation(outputLocation);
+ builder.jndiName("Simple");
+ builder.isEjb3(true);
+ builder.initCtxFactory("org.jnp.interfaces.NamingContextFactory");
+ builder.providerUrl("jnp://localhost:1099");
+ builder.arg(String.class, payloadLocation);
+ builder.username("kalle");
+ builder.password("12345");
+ final ConfigTree config = builder.build();
+
+ MockEjbProcessor processor = new MockEjbProcessor(config);
+ processor.initialise();
+
+ Properties jndiProperties = processor.getJndiProperties();
+ assertTrue(jndiProperties.containsKey(Context.SECURITY_PRINCIPAL));
+ assertTrue(jndiProperties.containsKey(Context.SECURITY_CREDENTIALS));
+ assertEquals("kalle", jndiProperties.get(Context.SECURITY_PRINCIPAL));
+ assertEquals("12345", jndiProperties.get(Context.SECURITY_CREDENTIALS));
+ }
+
+ @Test (expected = ActionLifecycleException.class)
+ public void verifyMissingSecurityCredentials() throws ActionLifecycleException, ActionProcessingException, ConfigurationException
+ {
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().add(payloadLocation, payload);
+
+ final ConfigBuilder builder = new ConfigBuilder();
+ builder.methodName("printMessageAndReturn");
+ builder.outputLocation(outputLocation);
+ builder.jndiName("Simple");
+ builder.isEjb3(true);
+ builder.initCtxFactory("org.jnp.interfaces.NamingContextFactory");
+ builder.providerUrl("jnp://localhost:1099");
+ builder.arg(String.class, payloadLocation);
+ builder.username("kalle");
+ final ConfigTree config = builder.build();
+
+ MockEjbProcessor processor = new MockEjbProcessor(config);
+ processor.initialise();
+ }
+
+ @Test
+ public void verifySecurityLoginModuleConfig() throws ActionLifecycleException, ActionProcessingException, ConfigurationException
+ {
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().add(payloadLocation, payload);
+
+ final ConfigBuilder builder = new ConfigBuilder();
+ builder.methodName("printMessageAndReturn");
+ builder.outputLocation(outputLocation);
+ builder.jndiName("Simple");
+ builder.isEjb3(true);
+ builder.initCtxFactory("org.jnp.interfaces.NamingContextFactory");
+ builder.providerUrl("jnp://localhost:1099");
+ builder.arg(String.class, payloadLocation);
+ builder.username("kalle");
+ builder.password("12345");
+ builder.securityLoginModule("SampleModule");
+ final ConfigTree config = builder.build();
+
+ MockEjbProcessor processor = new MockEjbProcessor(config);
+ processor.initialise();
+
+ assertEquals("SampleModule", processor.getLoginModuleName());
+ assertTrue(processor.getCallbackHandler() instanceof AppCallbackHandler);
+ }
+
public static junit.framework.Test suite()
{
return new JUnit4TestAdapter(EJBProcessorUnitTest.class);
}
-
+
}
Modified: labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/MockEjbProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/MockEjbProcessor.java 2009-07-30 12:56:16 UTC (rev 28599)
+++ labs/jbossesb/trunk/product/services/slsb/src/test/java/org/jboss/soa/esb/actions/MockEjbProcessor.java 2009-07-30 13:10:57 UTC (rev 28600)
@@ -24,6 +24,7 @@
import javax.naming.Context;
import javax.naming.InitialContext;
+import javax.security.auth.callback.CallbackHandler;
import org.jboss.soa.esb.helpers.ConfigTree;
@@ -34,6 +35,12 @@
*/
public class MockEjbProcessor extends EJBProcessor
{
+ private Properties jndiProperties;
+
+ private String loginModuleName;
+
+ private CallbackHandler callbackHandler;
+
public MockEjbProcessor(ConfigTree config)
{
super(config);
@@ -48,7 +55,32 @@
@Override
InitialContext getInitialContext(Properties props) throws ActionLifecycleException
{
+ this.jndiProperties = props;
return null;
}
+
+ @Override
+ void login(String loginModuleName, final CallbackHandler callbackHandler) throws ActionLifecycleException
+ {
+ this.loginModuleName = loginModuleName;
+ this.callbackHandler = callbackHandler;
+ }
+ public Properties getJndiProperties()
+ {
+ return jndiProperties;
+ }
+
+ public CallbackHandler getCallbackHandler()
+ {
+ return callbackHandler;
+ }
+
+ public String getLoginModuleName()
+ {
+ return loginModuleName;
+ }
+
+
+
}
More information about the jboss-svn-commits
mailing list