use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class ServerSessionDelegate method queueDeclare.
@Override
public void queueDeclare(ServerSession session, final QueueDeclare method) {
final NamedAddressSpace addressSpace = getAddressSpace(session);
String queueName = method.getQueue();
Queue<?> queue;
// TODO: do we need to check that the queue already exists with exactly the same "configuration"?
final boolean exclusive = method.getExclusive();
final boolean autoDelete = method.getAutoDelete();
if (method.getPassive()) {
queue = getQueue(addressSpace, queueName);
if (queue == null) {
String description = "Queue: " + queueName + " not found on VirtualHost(" + addressSpace + ").";
ExecutionErrorCode errorCode = ExecutionErrorCode.NOT_FOUND;
exception(session, method, errorCode, description);
} else if (exclusive) {
if (queue.getExclusive() == ExclusivityPolicy.NONE) {
String description = "Cannot passively declare queue ('" + queueName + "')" + " as exclusive as queue with same name is" + " already declared as non-exclusive";
ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
exception(session, method, errorCode, description);
} else if (!verifySessionAccess(session, queue)) {
String description = "Cannot passively declare queue('" + queueName + "')," + " as exclusive queue with same name " + "declared on another session";
ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
exception(session, method, errorCode, description);
}
}
} else {
try {
final Map<String, Object> arguments = QueueArgumentsConverter.convertWireArgsToModel(queueName, method.getArguments());
final String alternateExchangeName = method.getAlternateExchange();
if (method.hasAlternateExchange() && !nameNullOrEmpty(alternateExchangeName)) {
validateAlternateExchangeIsNotQueue(addressSpace, alternateExchangeName);
arguments.put(Queue.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
}
arguments.put(Queue.NAME, queueName);
if (!arguments.containsKey(Queue.LIFETIME_POLICY)) {
LifetimePolicy lifetime;
if (autoDelete) {
lifetime = exclusive ? LifetimePolicy.DELETE_ON_SESSION_END : LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS;
} else {
lifetime = LifetimePolicy.PERMANENT;
}
arguments.put(Queue.LIFETIME_POLICY, lifetime);
}
if (!arguments.containsKey(Queue.EXCLUSIVE)) {
ExclusivityPolicy exclusivityPolicy = exclusive ? ExclusivityPolicy.SESSION : ExclusivityPolicy.NONE;
arguments.put(Queue.EXCLUSIVE, exclusivityPolicy);
}
arguments.put(Queue.DURABLE, method.getDurable());
queue = addressSpace.createMessageSource(Queue.class, arguments);
} catch (AbstractConfiguredObject.DuplicateNameException qe) {
queue = (Queue<?>) qe.getExisting();
if (!verifySessionAccess(session, queue)) {
String description = "Cannot declare queue('" + queueName + "')," + " as exclusive queue with same name " + "declared on another session";
ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
exception(session, method, errorCode, description);
}
} catch (AccessControlException e) {
exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
} catch (UnknownAlternateBindingException e) {
exception(session, method, ExecutionErrorCode.NOT_FOUND, String.format("Unknown alternate exchange '%s'", e.getAlternateBindingName()));
} catch (IllegalArgumentException | IllegalConfigurationException e) {
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, e.getMessage());
}
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class Main method copyInitialConfigFile.
private void copyInitialConfigFile(final String initialConfigLocation, final File destinationFile) {
URL url = null;
try {
url = new URL(initialConfigLocation);
} catch (MalformedURLException e) {
File locationFile = new File(initialConfigLocation);
try {
url = locationFile.toURI().toURL();
} catch (MalformedURLException e1) {
throw new IllegalConfigurationException("Cannot create URL for file " + locationFile, e1);
}
}
InputStream in = null;
try {
in = url.openStream();
FileUtils.copy(in, destinationFile);
} catch (IOException e) {
throw new IllegalConfigurationException("Cannot create file " + destinationFile + " by copying initial config from " + initialConfigLocation, e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
throw new IllegalConfigurationException("Cannot close initial config input stream: " + initialConfigLocation, e);
}
}
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AbstractQueue method validateOrCreateAlternateBinding.
private void validateOrCreateAlternateBinding(final Queue<?> queue, final boolean mayCreate) {
Object value = queue.getAttribute(ALTERNATE_BINDING);
if (value instanceof AlternateBinding) {
AlternateBinding alternateBinding = (AlternateBinding) value;
String destinationName = alternateBinding.getDestination();
MessageDestination messageDestination = _virtualHost.getAttainedMessageDestination(destinationName, mayCreate);
if (messageDestination == null) {
throw new UnknownAlternateBindingException(destinationName);
} else if (messageDestination == this) {
throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination cannot refer to self.", getName()));
} else if (isDurable() && !messageDestination.isDurable()) {
throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination '%s' is not durable.", getName(), destinationName));
}
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AutoGeneratedSelfSignedKeyStoreImpl method generateKeyManagers.
private void generateKeyManagers() {
try {
X509Certificate[] certs = new X509Certificate[] { _certificate };
java.security.KeyStore inMemoryKeyStore = java.security.KeyStore.getInstance(java.security.KeyStore.getDefaultType());
byte[] bytes = new byte[64];
char[] chars = new char[64];
RANDOM.nextBytes(bytes);
StandardCharsets.US_ASCII.decode(ByteBuffer.wrap(bytes)).get(chars);
inMemoryKeyStore.load(null, chars);
inMemoryKeyStore.setKeyEntry("1", _privateKey, chars, certs);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(inMemoryKeyStore, chars);
_keyManagers = kmf.getKeyManagers();
} catch (IOException | GeneralSecurityException e) {
throw new IllegalConfigurationException("Cannot load private key or certificate(s): " + e, e);
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AutoGeneratedSelfSignedKeyStoreImpl method loadPrivateKeyAndCertificate.
private void loadPrivateKeyAndCertificate() {
byte[] privateKeyEncoded = Strings.decodeBase64((String) getActualAttributes().get(ENCODED_PRIVATE_KEY));
byte[] certificateEncoded = Strings.decodeBase64((String) getActualAttributes().get(ENCODED_CERTIFICATE));
try (ByteArrayInputStream input = new ByteArrayInputStream(certificateEncoded)) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
_certificate = (X509Certificate) cf.generateCertificate(input);
} catch (CertificateException | IOException e) {
throw new IllegalConfigurationException("Could not decode certificate", e);
}
try {
_privateKey = SSLUtil.readPrivateKey(privateKeyEncoded, _keyAlgorithm);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new IllegalConfigurationException("Could not decode private key", e);
}
}
Aggregations