Search in sources :

Example 76 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class AbstractConfiguredObjectTest method testIdAndTypeAreImmutableAttribute.

/**
 * Id and Type are key attributes in the model and are thus worthy of test of their own
 */
public void testIdAndTypeAreImmutableAttribute() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, "myName");
    final TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, attributes, null);
    UUID originalUuid = object.getId();
    String originalType = object.getType();
    try {
        object.setAttributes(Collections.singletonMap(TestSingleton.ID, UUID.randomUUID()));
        fail("Exception not thrown");
    } catch (IllegalConfigurationException e) {
    // PASS
    }
    assertEquals(originalUuid, object.getId());
    try {
        object.setAttributes(Collections.singletonMap(TestSingleton.TYPE, "newtype"));
        fail("Exception not thrown");
    } catch (IllegalConfigurationException e) {
    // PASS
    }
    assertEquals(originalType, object.getType());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UUID(java.util.UUID)

Example 77 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testValidateOnCreateFails_ExistingDefaultVHN.

public void testValidateOnCreateFails_ExistingDefaultVHN() throws Exception {
    String nodeName = getTestName();
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(TestVirtualHostNode.NAME, nodeName);
    attributes.put(TestVirtualHostNode.DEFAULT_VIRTUAL_HOST_NODE, Boolean.TRUE);
    VirtualHostNode existingDefault = mock(VirtualHostNode.class);
    when(existingDefault.getName()).thenReturn("existingDefault");
    when(_broker.findDefautVirtualHostNode()).thenReturn(existingDefault);
    final DurableConfigurationStore store = mock(DurableConfigurationStore.class);
    AbstractStandardVirtualHostNode node = createTestStandardVirtualHostNode(attributes, store);
    try {
        node.create();
        fail("Exception not thrown");
    } catch (IllegalConfigurationException e) {
        assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("The existing virtual host node 'existingDefault' is already the default for the Broker"));
    }
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode)

Example 78 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testValidateOnCreateFails_StoreFails.

public void testValidateOnCreateFails_StoreFails() throws Exception {
    String nodeName = getTestName();
    Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName);
    final DurableConfigurationStore store = mock(DurableConfigurationStore.class);
    doThrow(new RuntimeException("Cannot open store")).when(store).init(any(ConfiguredObject.class));
    AbstractStandardVirtualHostNode node = createTestStandardVirtualHostNode(attributes, store);
    try {
        node.create();
        fail("Exception not thrown");
    } catch (IllegalConfigurationException e) {
        assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open node configuration store"));
    }
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 79 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class PrincipalDatabaseAuthenticationManager method onCreate.

@Override
protected void onCreate() {
    super.onCreate();
    File passwordFile = new File(_path);
    if (!passwordFile.exists()) {
        try {
            Path path = new FileHelper().createNewFile(passwordFile, getContextValue(String.class, SystemConfig.POSIX_FILE_PERMISSIONS));
            if (!Files.exists(path)) {
                throw new IllegalConfigurationException(String.format("Cannot create password file at '%s'", _path));
            }
        } catch (IOException e) {
            throw new IllegalConfigurationException(String.format("Cannot create password file at '%s'", _path), e);
        }
    }
}
Also used : Path(java.nio.file.Path) FileHelper(org.apache.qpid.server.util.FileHelper) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) File(java.io.File)

Example 80 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class PrincipalDatabaseAuthenticationManager method validateOnCreate.

@Override
protected void validateOnCreate() {
    super.validateOnCreate();
    File passwordFile = new File(_path);
    if (passwordFile.exists() && !passwordFile.canRead()) {
        throw new IllegalConfigurationException(String.format("Cannot read password file '%s'. Please check permissions.", _path));
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File)

Aggregations

IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)87 HashMap (java.util.HashMap)31 IOException (java.io.IOException)25 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)20 File (java.io.File)15 UUID (java.util.UUID)12 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)12 GeneralSecurityException (java.security.GeneralSecurityException)10 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)9 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)7 AccessControlException (java.security.AccessControlException)6 ArrayList (java.util.ArrayList)6 Protocol (org.apache.qpid.server.model.Protocol)5 UnknownAlternateBindingException (org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)5 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HashSet (java.util.HashSet)4