|
19 | 19 | package org.apache.cxf.transport.jms.util; |
20 | 20 |
|
21 | 21 | import java.util.Enumeration; |
| 22 | +import java.util.Properties; |
22 | 23 | import java.util.Timer; |
23 | 24 |
|
| 25 | +import javax.naming.Context; |
24 | 26 | import javax.transaction.xa.XAException; |
25 | 27 |
|
26 | 28 | import jakarta.jms.Connection; |
|
53 | 55 | import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; |
54 | 56 | import org.apache.activemq.artemis.junit.EmbeddedActiveMQResource; |
55 | 57 | import org.apache.activemq.artemis.ra.ActiveMQResourceAdapter; |
| 58 | +import org.apache.cxf.transport.jms.JMSConfiguration; |
56 | 59 | import org.awaitility.Awaitility; |
57 | 60 | import org.jboss.narayana.jta.jms.ConnectionFactoryProxy; |
58 | 61 | import org.jboss.narayana.jta.jms.TransactionHelperImpl; |
|
64 | 67 | import static org.junit.Assert.assertEquals; |
65 | 68 | import static org.junit.Assert.assertNotNull; |
66 | 69 | import static org.junit.Assert.assertThat; |
| 70 | +import static org.junit.Assert.assertTrue; |
67 | 71 |
|
68 | 72 |
|
69 | 73 | public class MessageListenerTest { |
@@ -94,6 +98,28 @@ public void testConnectionProblem() throws JMSException { |
94 | 98 | assertEquals("Connection is closed", ex.getMessage()); |
95 | 99 | } |
96 | 100 |
|
| 101 | + @Test |
| 102 | + public void testJndiForbiddenProtocolForPollingContainer() { |
| 103 | + Properties env = new Properties(); |
| 104 | + env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); |
| 105 | + env.put(Context.PROVIDER_URL, "ldap://127.0.0.1:12345"); |
| 106 | + env.put(Context.REFERRAL, "follow"); |
| 107 | + |
| 108 | + JMSConfiguration jmsConfig = new JMSConfiguration(); |
| 109 | + jmsConfig.setJndiEnvironment(env); |
| 110 | + |
| 111 | + PollingMessageListenerContainer container = |
| 112 | + new PollingMessageListenerContainer(jmsConfig, false, message -> { }); |
| 113 | + container.setJndiEnvironment(env); |
| 114 | + |
| 115 | + try { |
| 116 | + container.createInitialContext(); |
| 117 | + org.junit.Assert.fail("JNDI context creation should have failed for unsafe LDAP protocol"); |
| 118 | + } catch (IllegalArgumentException ex) { |
| 119 | + assertTrue(ex.getMessage().contains("Unsafe protocol in JNDI URL")); |
| 120 | + } |
| 121 | + } |
| 122 | + |
97 | 123 | @Test |
98 | 124 | public void testConnectionProblemXA() throws JMSException, XAException, ResourceException { |
99 | 125 | TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager(); |
|
0 commit comments