Search in sources :

Example 1 with AccessControlProvider

use of org.apache.qpid.server.model.AccessControlProvider in project qpid-broker-j by apache.

the class AclFileAccessControlProviderFactoryTest method testCreateInstanceWhenAclFileIsSpecified.

public void testCreateInstanceWhenAclFileIsSpecified() {
    File aclFile = TestFileUtils.createTempFile(this, ".acl", "ACL ALLOW all all");
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(AccessControlProvider.ID, UUID.randomUUID());
    attributes.put(AccessControlProvider.NAME, "acl");
    attributes.put(AccessControlProvider.TYPE, AclFileAccessControlProvider.ACL_FILE_PROVIDER_TYPE);
    attributes.put(AclFileAccessControlProvider.PATH, aclFile.getAbsolutePath());
    AccessControlProvider acl = _objectFactory.create(AccessControlProvider.class, attributes, _broker);
    assertNotNull("ACL was not created from acl file: " + aclFile.getAbsolutePath(), acl);
}
Also used : HashMap(java.util.HashMap) AccessControlProvider(org.apache.qpid.server.model.AccessControlProvider) File(java.io.File)

Example 2 with AccessControlProvider

use of org.apache.qpid.server.model.AccessControlProvider in project qpid-broker-j by apache.

the class AclFileAccessControlProviderFactoryTest method testCreateInstanceWhenAclFileIsSpecifiedButDoesNotExist.

public void testCreateInstanceWhenAclFileIsSpecifiedButDoesNotExist() {
    File aclFile = new File(TMP_FOLDER, "my-non-existing-acl-" + System.currentTimeMillis());
    assertFalse("ACL file " + aclFile.getAbsolutePath() + " actually exists but should not", aclFile.exists());
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(AccessControlProvider.ID, UUID.randomUUID());
    attributes.put(AccessControlProvider.NAME, "acl");
    attributes.put(AccessControlProvider.TYPE, AclFileAccessControlProvider.ACL_FILE_PROVIDER_TYPE);
    attributes.put(AclFileAccessControlProvider.PATH, aclFile.getAbsolutePath());
    try {
        AccessControlProvider control = _objectFactory.create(AccessControlProvider.class, attributes, _broker);
        fail("It should not be possible to create and initialise ACL with non existing file");
    } catch (IllegalConfigurationException e) {
        assertTrue("Unexpected exception message: " + e.getMessage(), Pattern.matches("Cannot convert .* to a readable resource", e.getMessage()));
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlProvider(org.apache.qpid.server.model.AccessControlProvider) File(java.io.File)

Example 3 with AccessControlProvider

use of org.apache.qpid.server.model.AccessControlProvider in project qpid-broker-j by apache.

the class AclFileAccessControlProviderFactoryTest method testCreateInstanceWhenAclFileIsNotPresent.

public void testCreateInstanceWhenAclFileIsNotPresent() {
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(AccessControlProvider.ID, UUID.randomUUID());
    attributes.put(AccessControlProvider.NAME, "acl");
    attributes.put(AccessControlProvider.TYPE, AclFileAccessControlProvider.ACL_FILE_PROVIDER_TYPE);
    try {
        AccessControlProvider acl = _objectFactory.create(AccessControlProvider.class, attributes, _broker);
        fail("ACL was created without a configuration file path specified");
    } catch (IllegalArgumentException e) {
    // pass
    }
}
Also used : HashMap(java.util.HashMap) AccessControlProvider(org.apache.qpid.server.model.AccessControlProvider)

Aggregations

HashMap (java.util.HashMap)3 AccessControlProvider (org.apache.qpid.server.model.AccessControlProvider)3 File (java.io.File)2 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1