org.apache.qpid.server.security.acl
Class AbstractACLTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.qpid.test.utils.QpidTestCase
              extended by org.apache.qpid.test.utils.QpidBrokerTestCase
                  extended by org.apache.qpid.server.security.acl.AbstractACLTestCase
All Implemented Interfaces:
junit.framework.Test, org.apache.qpid.jms.ConnectionListener
Direct Known Subclasses:
ExhaustiveACLTest, ExternalACLFileTest, ExternalACLJMXTest, ExternalAdminACLTest, SimpleACLTest

public abstract class AbstractACLTestCase
extends QpidBrokerTestCase
implements org.apache.qpid.jms.ConnectionListener

Abstract test case for ACLs. This base class contains convenience methods to mange ACL files and implements a mechanism that allows each test method to run its own setup code before the broker starts. TODO move the pre broker-startup setup method invocation code to QpidBrokerTestCase

See Also:
SimpleACLTest, ExternalACLTest, ExternalACLFileTest, ExternalACLJMXTest, ExternalAdminACLTest, ExhaustiveACLTest

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
QpidBrokerTestCase.MessageType
 
Field Summary
protected  CountDownLatch _exceptionReceived
          Used to synchronise tearDown() when exceptions are thrown
 
Fields inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
_broker, _brokerLanguage, _brokerLogPrefix, _brokerOutputStream, _brokerPersistent, _brokers, _configFile, _connectionFactory, _connections, _initialContext, _interleaveBrokerLog, _logger, _output, _outputFile, _testName, BROKER_READY, CONTENT, CPP, DEFAULT_MANAGEMENT_PORT, DEFAULT_MESSAGE_SIZE, DEFAULT_PORT, DEFAULT_SSL_PORT, DEFAULT_VM_PORT, EXTERNAL, INDEX, JAVA, LOGMONITOR_TIMEOUT, QPID_HOME, QpidHome, QUEUE, RECEIVE_TIMEOUT, TOPIC, VM
 
Fields inherited from class org.apache.qpid.test.utils.QpidTestCase
MEMORY_STORE_CLASS_NAME, MS_CLASS_NAME_KEY
 
Constructor Summary
AbstractACLTestCase()
           
 
Method Summary
 void bytesReceived(long count)
           
 void bytesSent(long count)
           
 void check403Exception(Throwable t)
          Convenience method to validate a JMS exception with a linked AMQConstant.ACCESS_REFUSED 403 error code exception.
 org.apache.qpid.client.AMQConnectionURL createConnectionURL(String vhost, String username, String password)
          Convenience method to build an AMQConnectionURL with the right parameters.
 void failoverComplete()
           
 String getConfig()
          Override this to return the name of the configuration XML file.
 Connection getConnection(String vhost, String username, String password)
          Creates a connection to the broker, and sets a connection listener to prevent failover and an exception listener with a CountDownLatch to synchronise in the check403Exception(Throwable) method and allow the tearDown() method to complete properly.
 List<String> getHostList()
          Override this to setup external ACL files for virtual hosts.
 boolean preFailover(boolean redirect)
           
 boolean preResubscribe()
           
 void setUp()
          This setup method checks getConfig() and getHostList() to initialise the broker with specific ACL configurations and then runs an optional per-test setup method, which is simply a method with the same name as the test, but starting with setUp rather than test.
 void setUpACLFile(String virtualHost)
          Configures specific ACL files for a virtual host.
 void tearDown()
           
 void writeACLFile(String vhost, String... rules)
           
 
Methods inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
cleanBroker, createMessage, createNextMessage, drainQueue, getBroker, getBrokerCommand, getClientConnection, getConfigurationStringProperty, getConnection, getConnection, getConnection, getConnectionFactory, getConnectionFactory, getConnectionURL, getInitialContext, getLogger, getManagementPort, getMessageSize, getPort, getPort, getTestConfigFile, getTestQueue, getTestQueueName, getTestVirtualhostsFile, isBroker010, isBroker08, isBrokerStorePersistent, isCppBroker, isExternalBroker, isJavaBroker, makeVirtualHostPersistent, reloadBrokerSecurityConfig, restartBroker, restartBroker, revertLoggingLevels, revertSystemProperties, runBare, saveTestConfiguration, saveTestVirtualhosts, sendMessage, sendMessage, sendMessage, setBrokerEnvironment, setBrokerOnlySystemProperty, setConfigurationProperty, setLoggerLevel, setMessageSize, setSystemProperty, setSystemProperty, setTestClientSystemProperty, startBroker, startBroker, stopBroker, stopBroker
 
Methods inherited from class org.apache.qpid.test.utils.QpidTestCase
getTestProfileMessageStoreClassName, run
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_exceptionReceived

protected CountDownLatch _exceptionReceived
Used to synchronise tearDown() when exceptions are thrown

Constructor Detail

AbstractACLTestCase

public AbstractACLTestCase()
Method Detail

getConfig

public String getConfig()
Override this to return the name of the configuration XML file.


getHostList

public List<String> getHostList()
Override this to setup external ACL files for virtual hosts.


setUp

public void setUp()
           throws Exception
This setup method checks getConfig() and getHostList() to initialise the broker with specific ACL configurations and then runs an optional per-test setup method, which is simply a method with the same name as the test, but starting with setUp rather than test.

Overrides:
setUp in class QpidBrokerTestCase
Throws:
Exception
See Also:
setUpACLFile(String), QpidBrokerTestCase.setUp()

tearDown

public void tearDown()
              throws Exception
Overrides:
tearDown in class QpidBrokerTestCase
Throws:
Exception

setUpACLFile

public void setUpACLFile(String virtualHost)
                  throws IOException,
                         ConfigurationException
Configures specific ACL files for a virtual host. This method checks for ACL files that exist on the filesystem. If dynamically generatyed ACL files are required in a test, then it is easier to use the setUp prefix on a method to generate the ACL file. In order, this method looks for three files:
  1. virtualhost-class-test.txt
  2. virtualhost-class.txt
  3. virtualhost-default.txt
The class and test parts are the test class and method names respectively, with the word test removed and the rest of the text converted to lowercase. For example, the test class and method named org.apache.qpid.test.AccessExampleTest#testExampleMethod on the testhost virtualhost would use one of the following files:
  1. testhost-accessexample-examplemethod.txt
  2. testhost-accessexample.txt
  3. testhost-default.txt
These files should be copied to the ${QPID_HOME}/etc directory when the test is run.

Throws:
IOException
ConfigurationException
See Also:
writeACLFile(String, String...)

writeACLFile

public void writeACLFile(String vhost,
                         String... rules)
                  throws ConfigurationException,
                         IOException
Throws:
ConfigurationException
IOException

getConnection

public Connection getConnection(String vhost,
                                String username,
                                String password)
                         throws NamingException,
                                JMSException,
                                org.apache.qpid.url.URLSyntaxException
Creates a connection to the broker, and sets a connection listener to prevent failover and an exception listener with a CountDownLatch to synchronise in the check403Exception(Throwable) method and allow the tearDown() method to complete properly.

Throws:
NamingException
JMSException
org.apache.qpid.url.URLSyntaxException

bytesSent

public void bytesSent(long count)
Specified by:
bytesSent in interface org.apache.qpid.jms.ConnectionListener

bytesReceived

public void bytesReceived(long count)
Specified by:
bytesReceived in interface org.apache.qpid.jms.ConnectionListener

preFailover

public boolean preFailover(boolean redirect)
Specified by:
preFailover in interface org.apache.qpid.jms.ConnectionListener

preResubscribe

public boolean preResubscribe()
Specified by:
preResubscribe in interface org.apache.qpid.jms.ConnectionListener

failoverComplete

public void failoverComplete()
Specified by:
failoverComplete in interface org.apache.qpid.jms.ConnectionListener

createConnectionURL

public org.apache.qpid.client.AMQConnectionURL createConnectionURL(String vhost,
                                                                   String username,
                                                                   String password)
                                                            throws org.apache.qpid.url.URLSyntaxException
Convenience method to build an AMQConnectionURL with the right parameters.

Throws:
org.apache.qpid.url.URLSyntaxException

check403Exception

public void check403Exception(Throwable t)
                       throws Exception
Convenience method to validate a JMS exception with a linked AMQConstant.ACCESS_REFUSED 403 error code exception.

Throws:
Exception


Licensed to the Apache Software Foundation