[jboss-svn-commits] JBL Code SVN: r20097 - in labs/jbossesb/trunk/product: rosetta/tests/src/org/jboss/soa/esb/actions/routing and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed May 21 05:21:55 EDT 2008
Author: beve
Date: 2008-05-21 05:21:55 -0400 (Wed, 21 May 2008)
New Revision: 20097
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jbm-queue-service.xml
labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml
Log:
Work for JBESB-1627 "Support authentication on outgoing JMS (i.e. JMSRouter)"
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2008-05-21 09:20:45 UTC (rev 20096)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2008-05-21 09:21:55 UTC (rev 20097)
@@ -65,7 +65,7 @@
* <property name="jndiName" value="queue/A"/>
* </action>
*
- * Option properties (default values shown):
+ * Option properties:
* <property name="unwrap" value="false"/>
* <property name="jndi-context-factory" value="org.jnp.interfaces.NamingContextFactory"/>
* <property name="jndi-URL" value="127.0.0.1:1099"/>
@@ -74,17 +74,27 @@
* <property name="persistent" value="true"/>
* <property name="priority" value="javax.jms.Message.DEFAULT_PRIORITY"/>
* <property name="time-to-live" value="javax.jms.Message.DEFAULT_TIME_TO_LIVE"/>
+ * <property name="security-principal" value="username"/>
+ * <property name="security-credential" value="pasword"/>
* <property name="message-prop-<i>>prop-name<</i>="<i>> value="prop-value<</i>" />
* </pre>
- * Note how properties to be set on the message are prefixed with "message-prop-".
- * <p/>
+ * Description of configuration attribues:
* <ul>
- * <li>'unwrap' true will extract the message payload from the ESB Message object before sending</li>
- * <li>'unwrap' false will send the serialized ESB Message object</li>
+ * <li><i>unwrap</i>:true will extract the message payload from the Message object before sending. false (default) will send the serialized Message object.
+ * <li><i>jndi-context-factory</i>: the JNDI context factory to use. Default is "org.jnp.interfaces.NamingContextFactory"
+ * <li><i>jndi-URL</i>: the JNDI URL to use. Default is "127.0.0.1:1099"
+ * <li><i>jndi-pkg-prefix</i>: the JNDI naming package prefixes to use. Default is "org.jboss.naming:org.jnp.interfaces".
+ * <li><i>connection-factory</i>: the name of the ConnectionFactory to use. Default is "ConnectionFactory".
+ * <li><i>persistent</i>: the JMS DeliveryMode. 'true' or 'false'. Default is "true".
+ * <li><i>priority</i>: the JMS Priority to be used. Default is "javax.jms.Message.DEFAULT_PRIORITY"
+ * <li><i>time-to-live</i>: the JMS Time-To-Live to be used. Default is "javax.jms.Message.DEFAULT_TIME_TO_LIVE"
+ * <li><i>security-principal</i>: security principal use when creating the JMS connection.
+ * <li><i>security-credential</i>: the security credentials to use when creating the JMS connection.
+ * <li><i>message-prop</i>: properties to be set on the message are prefixed with "message-prop-".
* </ul>
*
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
- * @author <a href="mailto:daniel.bevenius at redpill.se">daniel.bevenius at redpill.se</a>
+ * @author <a href="mailto:daniel.bevenius at redhat.com">daniel.bevenius at redhat.com</a>
* @since Version 4.0
*/
public class JMSRouter extends AbstractRouter {
@@ -105,6 +115,14 @@
*/
public static final String TIME_TO_LIVE_ATTR = "time-to-live";
/**
+ * Security principal used when creating the JMS connection
+ */
+ public static final String SECURITY_PRINCIPAL = "security-principal";
+ /**
+ * Security credential used when creating the JMS connection
+ */
+ public static final String SECURITY_CREDITIAL = "security-credential";
+ /**
* Routing properties.
*/
private ConfigTree properties;
@@ -140,17 +158,17 @@
private String connectionFactory;
/**
- * Public constructor.
+ * Sole public constructor.
+ *
* @param propertiesTree Action properties.
* @throws ConfigurationException Queue name not configured.
* @throws JMSException Unable to configure JMS destination.
* @throws NamingException Unable to configure JMS destination.
*/
- public JMSRouter(ConfigTree propertiesTree) throws ConfigurationException, NamingException, JMSException {
+ public JMSRouter( final ConfigTree propertiesTree ) throws ConfigurationException, NamingException, JMSException {
super(propertiesTree);
this.properties = propertiesTree;
- logger.debug(properties);
queueName = properties.getAttribute("jndiName");
if(queueName == null) {
@@ -172,8 +190,16 @@
jndiUrl = properties.getAttribute( JMSEpr.JNDI_URL_TAG );
jndiPkgPrefix = properties.getAttribute( JMSEpr.JNDI_PKG_PREFIX_TAG );
connectionFactory = properties.getAttribute( JMSEpr.CONNECTION_FACTORY_TAG );
+
+
+ final String securityPrincipal = properties.getAttribute(SECURITY_PRINCIPAL);
+ final String securityCredential = properties.getAttribute(SECURITY_CREDITIAL);
+ if ( securityPrincipal != null && securityCredential == null )
+ throw new ConfigurationException("'" + SECURITY_PRINCIPAL + "' must be accompanied by a '" + SECURITY_CREDITIAL + "'");
+ else if ( securityCredential != null && securityPrincipal == null )
+ throw new ConfigurationException("'" + SECURITY_CREDITIAL + "' must be accompanied by a '" + SECURITY_PRINCIPAL + "'");
- createQueueSetup( queueName, jndiContextFactory, jndiUrl, jndiPkgPrefix, connectionFactory );
+ createQueueSetup( queueName, jndiContextFactory, jndiUrl, jndiPkgPrefix, connectionFactory, securityPrincipal, securityCredential );
}
/**
@@ -317,17 +343,19 @@
protected void createQueueSetup( String queueName ) throws ConfigurationException
{
- createQueueSetup( queueName, null, null, null, null );
+ createQueueSetup( queueName, null, null, null, null, null, null );
}
protected void createQueueSetup( String queueName,
String jndiContextFactory,
String jndiUrl,
String jndiPkgPrefix,
- String connectionFactory) throws ConfigurationException
+ String connectionFactory,
+ String securityPrincipal,
+ String securityCredential) throws ConfigurationException
{
try {
- queueSetup = new JMSSendQueueSetup(queueName, jndiContextFactory, jndiUrl, jndiPkgPrefix, connectionFactory);
+ queueSetup = new JMSSendQueueSetup(queueName, jndiContextFactory, jndiUrl, jndiPkgPrefix, connectionFactory, securityPrincipal, securityCredential );
queueSetup.setDeliveryMode( deliveryMode );
queueSetup.setPriority( priority );
queueSetup.setTimeToLive( timeToLive );
@@ -350,16 +378,17 @@
JmsConnectionPool pool;
Properties environment;
- // TODO: Modify to support topic destinations too
private JMSSendQueueSetup(String destinationName) throws NamingException, JMSException, ConnectionException, NamingContextException {
- this( destinationName, null, null, null, null);
+ this( destinationName, null, null, null, null, null, null );
}
private JMSSendQueueSetup(String destinationName,
String jndiContextFactory,
String jndiUrl,
String jndiPkgPrefix,
- String connectionFactoryName) throws NamingException, JMSException, ConnectionException, NamingContextException {
+ String connectionFactoryName,
+ String securityPrincipal,
+ String securityCredential) throws NamingException, JMSException, ConnectionException, NamingContextException {
if ( jndiContextFactory == null )
jndiContextFactory = Configuration.getJndiServerContextFactory();
@@ -376,7 +405,9 @@
environment.setProperty(Context.URL_PKG_PREFIXES, jndiPkgPrefix);
Context oCtx = NamingContextPool.getNamingContext(environment);
try {
- pool = JmsConnectionPoolContainer.getPool(environment, connectionFactoryName);
+ pool = ( securityPrincipal != null ) ?
+ JmsConnectionPoolContainer.getPool(environment, connectionFactoryName, securityPrincipal, securityCredential) :
+ JmsConnectionPoolContainer.getPool(environment, connectionFactoryName );
this.destinationName = destinationName;
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java 2008-05-21 09:20:45 UTC (rev 20096)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java 2008-05-21 09:21:55 UTC (rev 20097)
@@ -26,12 +26,10 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.List;
import javax.jms.Destination;
import javax.jms.JMSException;
@@ -46,12 +44,9 @@
import org.jboss.internal.soa.esb.rosetta.pooling.ConnectionException;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.soa.esb.actions.ActionUtils;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.helpers.KeyValuePair;
import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.junit.Before;
import org.junit.Ignore;
@@ -60,9 +55,10 @@
import org.mockejb.jms.TextMessageImpl;
/**
- *
+ * Integration test for {@link JMSRouter}
+ * <p/>
* @author John Doe
- * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @author <a href="daniel.bevenius at redhat.com">Daniel Bevenius</a>
*
*/
public class JmsRouterIntegrationTest
@@ -75,15 +71,9 @@
private Message msg;
private ConfigTree tree;
- @Before
- public void setup() throws URISyntaxException
- {
- msg = createESBMessageObject( messageID, bodyContent );
- tree = createConfigTree();
- }
@Test
- public void process_unwrap_false() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ public void processWithUnwrapFalse() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
{
MockJMSRouter router = new MockJMSRouter(tree);
router.route( msg );
@@ -92,7 +82,7 @@
}
@Test
- public void process_unwrap_true() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ public void processWithUnwrapTrue() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
{
tree.setAttribute( "unwrap", "true" );
MockJMSRouter router = new MockJMSRouter( tree );
@@ -108,9 +98,37 @@
assertEquals ( textMessage.getJMSCorrelationID(), messageID );
assertEquals ( textMessage.getText(), bodyContent );
}
+
+ @Test
+ public void constructorWithSecurity() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ final String principal = "guest";
+ final String credential = "guest";
+ tree.setAttribute( "unwrap", "true" );
+ tree.setAttribute( JMSRouter.SECURITY_PRINCIPAL, principal );
+ tree.setAttribute( JMSRouter.SECURITY_CREDITIAL, credential );
+ MockJMSRouter router = new MockJMSRouter( tree );
+
+ assertEquals ( principal, router.getSecurityPrincipal() );
+ assertEquals ( credential, router.getSecurityCredential() );
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfPrincipalIsNull() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ tree.setAttribute( JMSRouter.SECURITY_CREDITIAL, "testpassword" );
+ new MockJMSRouter( tree );
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfCredentialIsNull() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ tree.setAttribute( JMSRouter.SECURITY_PRINCIPAL, "testuser" );
+ new MockJMSRouter( tree );
+ }
@Test ( expected = ActionProcessingException.class )
- public void route_negative() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
+ public void shouldThrowIfObjectIsNotAMessageObject() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
{
ConfigTree tree = createConfigTree();
JMSRouter router = new MockJMSRouter(tree);
@@ -133,7 +151,6 @@
assertTrue( replyTo instanceof Queue );
Queue replyToQueue = (Queue) replyTo;
assertEquals( queueName , replyToQueue.getQueueName() );
-
}
@Test
@@ -155,61 +172,16 @@
assertEquals( queueName , replyToTopic.getTopicName() );
}
- /*
- * Not quite sure that this is supposed to be testing.
- * Can we remove this test? /Daniel
- */
@Test
- @Ignore
- public void testRouter () throws Exception
+ public void constructWithDefaultPersitentAttribute() throws ConfigurationException, NamingException, JMSException
{
- boolean exception = false;
-
- Message msg = MessageFactory.getInstance().getMessage();
-
- msg.getBody().add("hello world".getBytes());
- JMSRouter router = new JMSRouter( createConfigTree() );
- try
- {
- router.route(msg);
- }
- catch (ActionProcessingException ex)
- {
- exception = true;
- }
-
- if (!exception)
- fail();
-
- router.unwrap = true;
-
- try
- {
- msg.getBody().add("hello world");
- router.process(msg);
- }
- catch (ActionProcessingException ex)
- {
- exception = true;
- }
-
- if (!exception)
- fail();
-
- router.getErrorNotification(null);
- router.getOkNotification(null);
- }
-
- @Test
- public void construct_with_default_persitent_attribute() throws ConfigurationException, NamingException, JMSException
- {
ConfigTree config = createConfigTree();
JMSRouter router = new JMSRouter( config );
assertTrue( router.isDeliveryModePersistent() );
}
@Test
- public void construct_with_persitent_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithPersitentAttribute() throws ConfigurationException, NamingException, JMSException
{
ConfigTree config = createConfigTree();
config.setAttribute( JMSRouter.PERSISTENT_ATTR, "false" );
@@ -219,7 +191,7 @@
}
@Test
- public void construct_with_default_priority_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithDefaultPriorityAttribute() throws ConfigurationException, NamingException, JMSException
{
ConfigTree config = createConfigTree();
JMSRouter router = new JMSRouter( config );
@@ -227,7 +199,7 @@
}
@Test
- public void construct_with_priority_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithPriorityAttribute() throws ConfigurationException, NamingException, JMSException
{
final int expectedPriority = 9;
ConfigTree config = createConfigTree();
@@ -238,7 +210,7 @@
}
@Test
- public void construct_with_default_time_to_live_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithDefaultTimeToLiveAttribute() throws ConfigurationException, NamingException, JMSException
{
ConfigTree config = createConfigTree();
JMSRouter router = new JMSRouter( config );
@@ -246,7 +218,7 @@
}
@Test
- public void construct_with_time_to_live_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithTimeToLiveAttribute() throws ConfigurationException, NamingException, JMSException
{
final long ttl = 6000l;
ConfigTree config = createConfigTree();
@@ -275,8 +247,16 @@
assertEquals( jndiURL, router.getJndiURL() );
assertEquals( jndiPkgPrefix, router.getJndiPkgPrefix() );
assertEquals( connectionFactory, router.getConnectionFactory() );
-
}
+
+ @Before
+ public void setup() throws URISyntaxException
+ {
+ msg = createESBMessageObject( messageID, bodyContent );
+ tree = createConfigTree();
+ }
+
+ // private
private void assertProcessContract( final String messageID, final Message msg, JMSRouter router ) throws ActionProcessingException, JMSException
{
@@ -286,12 +266,30 @@
assertEquals ( jmsMessage.getJMSCorrelationID(), messageID );
}
+ private Message createESBMessageObject( final String messageID, final String body) throws URISyntaxException
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+ msg.getHeader().getCall().setMessageID( new URI ( "1234-junittest" ) );
+ msg.getBody().add(body.getBytes());
+ return msg;
+ }
+
+ private static ConfigTree createConfigTree()
+ {
+ ConfigTree tree = new ConfigTree("test");
+ tree.setAttribute("jndiName", "/queue/A");
+ return tree;
+ }
+
private static class MockJMSRouter extends JMSRouter
{
@SuppressWarnings ( "unused" )
private Logger log = Logger.getLogger( MockJMSRouter.class );
private javax.jms.Message jmsMessage;
+
+ private String securityPrincipal;
+ private String securityCredential;
public MockJMSRouter(ConfigTree propertiesTree) throws ConfigurationException, NamingException, JMSException
{
@@ -302,6 +300,19 @@
protected void createQueueSetup( String queueName ) throws ConfigurationException { }
@Override
+ protected void createQueueSetup( String queueName,
+ String jndiContextFactory,
+ String jndiUrl,
+ String jndiPkgPrefix,
+ String connectionFactory,
+ String securityPrincipal,
+ String securityCredential) throws ConfigurationException
+ {
+ this.securityPrincipal = securityPrincipal;
+ this.securityCredential = securityCredential;
+ }
+
+ @Override
protected void send( javax.jms.Message jmsMessage ) throws JMSException
{
this.jmsMessage = jmsMessage;
@@ -327,23 +338,18 @@
impl.setObject( (Serializable) message );
return impl;
}
- }
+
+ public String getSecurityPrincipal()
+ {
+ return securityPrincipal;
+ }
- private Message createESBMessageObject( final String messageID, final String body) throws URISyntaxException
- {
- Message msg = MessageFactory.getInstance().getMessage();
- msg.getHeader().getCall().setMessageID( new URI ( "1234-junittest" ) );
- msg.getBody().add(body.getBytes());
- return msg;
+ public String getSecurityCredential()
+ {
+ return securityCredential;
+ }
}
- private static ConfigTree createConfigTree()
- {
- ConfigTree tree = new ConfigTree("test");
- tree.setAttribute("jndiName", "/queue/A");
- return tree;
- }
-
/*
* Just here to help Ant to find annotated test.
*/
Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jbm-queue-service.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jbm-queue-service.xml 2008-05-21 09:20:45 UTC (rev 20096)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jbm-queue-service.xml 2008-05-21 09:21:55 UTC (rev 20097)
@@ -20,6 +20,12 @@
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ </security>
+ </attribute>
+
</mbean>
</server>
Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml 2008-05-21 09:20:45 UTC (rev 20096)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml 2008-05-21 09:21:55 UTC (rev 20097)
@@ -50,6 +50,8 @@
<property name="connection-factory" value="ConnectionFactory"/>
<property name="jndiName" value="queue/quickstart_jms_router_routeTo"/>
<property name="unwrap" value="true"/>
+ <property name="security-principal" value="guest"/>
+ <property name="security-credential" value="guest"/>
</action>
</actions>
More information about the jboss-svn-commits
mailing list