use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class NonJavaKeyStoreImpl method updateKeyManagers.
@SuppressWarnings("unused")
private void updateKeyManagers() {
try {
if (_privateKeyUrl != null && _certificateUrl != null) {
PrivateKey privateKey = SSLUtil.readPrivateKey(getUrlFromString(_privateKeyUrl));
X509Certificate[] certs = SSLUtil.readCertificates(getUrlFromString(_certificateUrl));
List<X509Certificate> allCerts = new ArrayList<>(Arrays.asList(certs));
if (_intermediateCertificateUrl != null) {
allCerts.addAll(Arrays.asList(SSLUtil.readCertificates(getUrlFromString(_intermediateCertificateUrl))));
certs = allCerts.toArray(new X509Certificate[allCerts.size()]);
}
checkCertificateExpiry(certs);
java.security.KeyStore inMemoryKeyStore = java.security.KeyStore.getInstance(java.security.KeyStore.getDefaultType());
byte[] bytes = new byte[64];
char[] chars = "".toCharArray();
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();
_certificate = certs[0];
_certificates = Collections.unmodifiableCollection(allCerts);
}
} 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 ManagementModeStoreHandlerTest method testRemoveCLIPort.
@Test
public void testRemoveCLIPort() {
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE, 1000);
_handler = createManagementModeStoreHandler();
_handler.init(_systemConfig);
Collection<ConfiguredObjectRecord> records = openAndGetRecords();
UUID portId = getOptionsPortId(records);
ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class);
when(record.getId()).thenReturn(portId);
try {
_handler.remove(record);
fail("Exception should be thrown on trying to remove CLI port");
} catch (IllegalConfigurationException e) {
// pass
}
}
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 {
Queue.BehaviourOnUnknownDeclareArgument unknownArgumentBehaviour = session.getAMQPConnection().getContextValue(Queue.BehaviourOnUnknownDeclareArgument.class, Queue.UNKNOWN_QUEUE_DECLARE_ARGUMENT_BEHAVIOUR_NAME);
final Map<String, Object> arguments = QueueArgumentsConverter.convertWireArgsToModel(queueName, method.getArguments(), session.getAMQPConnection().getModel(), unknownArgumentBehaviour);
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 destination '%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 BoneCPConnectionProvider method createBoneCPConfig.
static BoneCPConfig createBoneCPConfig(final String connectionUrl, final String username, final String password, final Map<String, String> providerAttributes) {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(connectionUrl);
if (username != null) {
config.setUsername(username);
config.setPassword(password);
}
Map<String, String> attributes = new HashMap<>(providerAttributes);
attributes.putIfAbsent(MIN_CONNECTIONS_PER_PARTITION, String.valueOf(DEFAULT_MIN_CONNECTIONS_PER_PARTITION));
attributes.putIfAbsent(MAX_CONNECTIONS_PER_PARTITION, String.valueOf(DEFAULT_MAX_CONNECTIONS_PER_PARTITION));
attributes.putIfAbsent(PARTITION_COUNT, String.valueOf(DEFAULT_PARTITION_COUNT));
Map<String, String> propertiesMap = attributes.entrySet().stream().collect(Collectors.toMap(p -> p.getKey().substring(JDBCSTORE_PREFIX.length()), Map.Entry::getValue));
Properties properties = new Properties();
properties.putAll(propertiesMap);
try {
config.setProperties(properties);
} catch (Exception e) {
throw new IllegalConfigurationException("Unexpected exception on applying BoneCP configuration", e);
}
return config;
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class JDBCLoggerHelper method createAppenderInstance.
Appender<ILoggingEvent> createAppenderInstance(final Context context, final ConfiguredObject<?> logger, final JDBCSettings settings) {
try {
final JDBCSettingsDBNameResolver dbNameResolver = new JDBCSettingsDBNameResolver(settings);
final ConnectionSource connectionSource = createConnectionSource(context, logger, settings);
final DBAppender appender = new DBAppender();
appender.setDbNameResolver(dbNameResolver);
appender.setConnectionSource(connectionSource);
appender.setContext(context);
appender.start();
return appender;
} catch (Exception e) {
LOGGER.error("Failed to create appender", e);
throw new IllegalConfigurationException("Cannot create appender");
}
}
Aggregations