Skip to content

Commit

Permalink
This closes #2671
Browse files Browse the repository at this point in the history
  • Loading branch information
clebertsuconic committed May 17, 2019
2 parents 1d0b5c3 + e533bf8 commit c9a7bbc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.activemq.artemis.api.core.ActiveMQSecurityException;
import org.apache.activemq.artemis.core.server.ServerProducer;
import org.apache.activemq.artemis.core.server.impl.ServerProducerImpl;
import org.apache.activemq.artemis.protocol.amqp.broker.AMQPSessionCallback;
Expand Down Expand Up @@ -69,6 +70,8 @@ public void initialise() throws Exception {
if (sessionSPI != null) {
try {
sessionSPI.init(this, connection.getSASLResult());
} catch (ActiveMQSecurityException e) {
throw e;
} catch (Exception e) {
throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.EventLoop;
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException;
import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext;
import org.apache.activemq.artemis.protocol.amqp.proton.ProtonInitializable;
import org.apache.activemq.artemis.protocol.amqp.sasl.ClientSASL;
Expand Down Expand Up @@ -482,6 +483,13 @@ private void dispatch() {
}
try {
Events.dispatch(ev, h);
} catch (ActiveMQSecurityException e) {
log.warn(e.getMessage(), e);
ErrorCondition error = new ErrorCondition();
error.setCondition(AmqpError.UNAUTHORIZED_ACCESS);
error.setDescription(e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage());
connection.setCondition(error);
connection.close();
} catch (Exception e) {
log.warn(e.getMessage(), e);
ErrorCondition error = new ErrorCondition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import javax.jms.TextMessage;

import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
import org.apache.qpid.jms.JmsConnectionFactory;
import org.junit.Test;

import java.net.URI;

public class JMSConnectionWithSecurityTest extends JMSClientTestSupport {

@Override
Expand Down Expand Up @@ -57,6 +60,25 @@ public void testNoUserOrPassword() throws Exception {
}
}

@Test(timeout = 10000)
public void testNoUserOrPasswordWithoutSaslRestrictions() throws Exception {
Connection connection = null;
JmsConnectionFactory factory = new JmsConnectionFactory(new URI("amqp://localhost:" + AMQP_PORT));
try {
connection = factory.createConnection();
connection.start();
fail("Expected Exception");
} catch (JMSSecurityException ex) {
IntegrationTestLogger.LOGGER.debug("Failed to authenticate connection with no user / password.");
} catch (Exception ex) {
fail("Expected JMSSecurityException");
} finally {
if (connection != null) {
connection.close();
}
}
}

@Test(timeout = 10000)
public void testUnknownUser() throws Exception {
Connection connection = null;
Expand Down

0 comments on commit c9a7bbc

Please sign in to comment.