本文整理汇总了Java中javax.jms.JMSSecurityException类的典型用法代码示例。如果您正苦于以下问题:Java JMSSecurityException类的具体用法?Java JMSSecurityException怎么用?Java JMSSecurityException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JMSSecurityException类属于javax.jms包,在下文中一共展示了JMSSecurityException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFailedCreateConsumerConnectionStillWorks
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test
public void testFailedCreateConsumerConnectionStillWorks() throws JMSException {
Connection connection = pooledConnFact.createConnection("guest", "password");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(name.getMethodName());
try {
session.createConsumer(queue);
fail("Should fail to create consumer");
} catch (JMSSecurityException ex) {
LOG.info("Caught expected security error");
}
queue = session.createQueue("GUESTS." + name.getMethodName());
MessageProducer producer = session.createProducer(queue);
producer.close();
connection.close();
}
示例2: ensureConnected
import javax.jms.JMSSecurityException; //导入依赖的package包/类
private void ensureConnected() throws JMSException {
if (isConnected() || closed.get()) {
return;
}
synchronized(this.connectionId) {
if (isConnected() || closed.get()) {
return;
}
if (clientID == null || clientID.trim().isEmpty()) {
throw new IllegalArgumentException("Client ID cannot be null or empty string");
}
if (!user.isValid()) {
executor.shutdown();
throw new JMSSecurityException(user.getFailureCause());
}
connected.set(true);
}
}
示例3: createMockConnection
import javax.jms.JMSSecurityException; //导入依赖的package包/类
private MockJMSConnection createMockConnection(String username, String password) throws JMSException {
MockJMSUser user = validateUser(username, password);
if (!user.isValid() && !deferAuthenticationToConnection) {
throw new JMSSecurityException(user.getFailureCause());
}
MockJMSConnection connection = new MockJMSConnection(user);
if (clientID != null && !clientID.isEmpty()) {
connection.setClientID(clientID, true);
} else {
connection.setClientID(UUID.randomUUID().toString(), false);
}
try {
connection.initialize();
} catch (JMSException e) {
connection.close();
}
return connection;
}
示例4: testFailedConnectThenSucceeds
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test
public void testFailedConnectThenSucceeds() throws JMSException {
Connection connection = pooledConnFact.createConnection("invalid", "credentials");
try {
connection.start();
fail("Should fail to connect");
} catch (JMSSecurityException ex) {
LOG.info("Caught expected security error");
}
connection = pooledConnFact.createConnection("system", "manager");
connection.start();
LOG.info("Successfully create new connection.");
connection.close();
}
示例5: testFailedConnectThenSucceedsWithListener
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test
public void testFailedConnectThenSucceedsWithListener() throws JMSException {
Connection connection = pooledConnFact.createConnection("invalid", "credentials");
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
LOG.warn("Connection get error: {}", exception.getMessage());
}
});
try {
connection.start();
fail("Should fail to connect");
} catch (JMSSecurityException ex) {
LOG.info("Caught expected security error");
}
connection = pooledConnFact.createConnection("system", "manager");
connection.start();
LOG.info("Successfully create new connection.");
connection.close();
}
示例6: testFailoverWithInvalidCredentialsCanConnect
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test
public void testFailoverWithInvalidCredentialsCanConnect() throws JMSException {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(
"failover:(" + connectionURI + ")");
pooledConnFact = new JmsPoolConnectionFactory();
pooledConnFact.setConnectionFactory(cf);
pooledConnFact.setMaxConnections(1);
Connection connection = pooledConnFact.createConnection("invalid", "credentials");
try {
connection.start();
fail("Should fail to connect");
} catch (JMSSecurityException ex) {
LOG.info("Caught expected security error");
}
connection = pooledConnFact.createConnection("system", "manager");
connection.start();
LOG.info("Successfully create new connection.");
connection.close();
}
示例7: testAutoCreateOnSendToQueueSecurity
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test
public void testAutoCreateOnSendToQueueSecurity() throws Exception {
((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest");
((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest");
((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "rejectAll");
Role role = new Role("rejectAll", false, false, false, false, false, false, false, false, false, false);
Set<Role> roles = new HashSet<>();
roles.add(role);
server.getSecurityRepository().addMatch("#", roles);
Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = ActiveMQJMSClient.createQueue(QUEUE_NAME);
try {
session.createProducer(queue);
Assert.fail("Sending a message here should throw a JMSSecurityException");
} catch (Exception e) {
Assert.assertTrue(e instanceof JMSSecurityException);
}
connection.close();
}
示例8: testRepeatedWrongPasswordAttempts
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test(timeout = 30000)
public void testRepeatedWrongPasswordAttempts() throws Exception {
for (int i = 0; i < 25; ++i) {
Connection connection = null;
try {
connection = createConnection(fullUser, "wrongPassword", null, false);
connection.start();
fail("Expected JMSException");
} catch (JMSSecurityException ex) {
IntegrationTestLogger.LOGGER.debug("Failed to authenticate connection with incorrect password.");
} finally {
if (connection != null) {
connection.close();
}
}
}
}
示例9: testConsumerNotAuthorized
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test(timeout = 30000)
public void testConsumerNotAuthorized() throws Exception {
Connection connection = createConnection(noprivUser, noprivPass);
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(getQueueName());
try {
session.createConsumer(queue);
fail("Should not be able to consume here.");
} catch (JMSSecurityException jmsSE) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
} finally {
connection.close();
}
}
示例10: testBrowserNotAuthorized
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test(timeout = 30000)
public void testBrowserNotAuthorized() throws Exception {
Connection connection = createConnection(noprivUser, noprivPass);
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(getQueueName());
try {
QueueBrowser browser = session.createBrowser(queue);
// Browser is not created until an enumeration is requesteda
browser.getEnumeration();
fail("Should not be able to consume here.");
} catch (JMSSecurityException jmsSE) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
} finally {
connection.close();
}
}
示例11: testConsumerNotAuthorizedToCreateQueues
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test(timeout = 30000)
public void testConsumerNotAuthorizedToCreateQueues() throws Exception {
Connection connection = createConnection(noprivUser, noprivPass);
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(getQueueName(getPrecreatedQueueSize() + 1));
try {
session.createConsumer(queue);
fail("Should not be able to consume here.");
} catch (JMSSecurityException jmsSE) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
} finally {
connection.close();
}
}
示例12: testProducerNotAuthorized
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test(timeout = 30000)
public void testProducerNotAuthorized() throws Exception {
Connection connection = createConnection(guestUser, guestPass);
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(getQueueName());
try {
session.createProducer(queue);
fail("Should not be able to produce here.");
} catch (JMSSecurityException jmsSE) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
} finally {
connection.close();
}
}
示例13: testAnonymousProducerNotAuthorized
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test(timeout = 30000)
public void testAnonymousProducerNotAuthorized() throws Exception {
Connection connection = createConnection(guestUser, guestPass);
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(getQueueName());
MessageProducer producer = session.createProducer(null);
try {
producer.send(queue, session.createTextMessage());
fail("Should not be able to produce here.");
} catch (JMSSecurityException jmsSE) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
} finally {
connection.close();
}
}
示例14: testCreateTemporaryQueueNotAuthorized
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test(timeout = 30000)
public void testCreateTemporaryQueueNotAuthorized() throws JMSException {
Connection connection = createConnection(guestUser, guestPass);
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
session.createTemporaryQueue();
} catch (JMSSecurityException jmsse) {
IntegrationTestLogger.LOGGER.info("Client should have thrown a JMSSecurityException but only threw JMSException");
}
// Should not be fatal
assertNotNull(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
} finally {
connection.close();
}
}
示例15: testCreateTemporaryTopicNotAuthorized
import javax.jms.JMSSecurityException; //导入依赖的package包/类
@Test(timeout = 30000)
public void testCreateTemporaryTopicNotAuthorized() throws JMSException {
Connection connection = createConnection(guestUser, guestPass);
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
session.createTemporaryTopic();
} catch (JMSSecurityException jmsse) {
IntegrationTestLogger.LOGGER.info("Client should have thrown a JMSSecurityException but only threw JMSException");
}
// Should not be fatal
assertNotNull(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
} finally {
connection.close();
}
}