use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AbstractVirtualHostNode method getInitialRecords.
protected final ConfiguredObjectRecord[] getInitialRecords() throws IOException {
ConfiguredObjectRecordConverter converter = new ConfiguredObjectRecordConverter(getModel());
Collection<ConfiguredObjectRecord> records = new ArrayList<>(converter.readFromJson(VirtualHost.class, this, getInitialConfigReader()));
if (!records.isEmpty()) {
ConfiguredObjectRecord vhostRecord = null;
for (ConfiguredObjectRecord record : records) {
if (record.getType().equals(VirtualHost.class.getSimpleName())) {
vhostRecord = record;
break;
}
}
if (vhostRecord != null) {
records.remove(vhostRecord);
vhostRecord = enrichInitialVirtualHostRootRecord(vhostRecord);
records.add(vhostRecord);
} else {
// this should be impossible as the converter should always generate a parent record
throw new IllegalConfigurationException("Somehow the initial configuration has records but " + "not a VirtualHost. This must be a coding error in Qpid");
}
addStandardExchangesIfNecessary(records, vhostRecord);
enrichWithAuditInformation(records);
}
return records.toArray(new ConfiguredObjectRecord[records.size()]);
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class ManagementModeStoreHandlerTest method testSaveCLIHttpPort.
public void testSaveCLIHttpPort() {
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE, 1000);
_handler = createManagementModeStoreHandler();
_handler.init(_systemConfig);
Collection<ConfiguredObjectRecord> records = openAndGetRecords();
UUID portId = getOptionsPortId(records);
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(Port.NAME, "TEST");
ConfiguredObjectRecord configurationEntry = new ConfiguredObjectRecordImpl(portId, Port.class.getSimpleName(), attributes, Collections.singletonMap(Broker.class.getSimpleName(), getRootEntry(records).getId()));
try {
_handler.update(false, configurationEntry);
fail("Exception should be thrown on trying to save CLI port");
} catch (IllegalConfigurationException e) {
// pass
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AutoGeneratedSelfSignedKeyStoreImpl method generatePrivateKeyAndCertificate.
private void generatePrivateKeyAndCertificate() {
try {
Set<InetAddress> addresses = new HashSet<>();
for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
for (InterfaceAddress inetAddress : networkInterface.getInterfaceAddresses()) {
addresses.add(inetAddress.getAddress());
}
}
Set<String> dnsNames = new HashSet<>();
for (InetAddress address : addresses) {
String hostName = address.getHostName();
if (hostName != null) {
dnsNames.add(hostName);
}
String canonicalHostName = address.getCanonicalHostName();
if (canonicalHostName != null) {
dnsNames.add(canonicalHostName);
}
}
long startTime = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(startTime);
calendar.add(Calendar.MONTH, _durationInMonths);
long duration = (calendar.getTimeInMillis() - startTime) / 1000;
final SSLUtil.KeyCertPair keyCertPair = SSLUtil.generateSelfSignedCertificate(_keyAlgorithm, _signatureAlgorithm, _keyLength, startTime, duration, "CN=Qpid", dnsNames, addresses);
_privateKey = keyCertPair.getPrivateKey();
_certificate = keyCertPair.getCertificate();
_generated = true;
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | IOException e) {
throw new IllegalConfigurationException("Unable to construct keystore", e);
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class FileTrustStoreImpl method initialize.
private void initialize() {
try {
KeyStore ts = initializeKeyStore(this);
_trustManagers = createTrustManagers(ts);
_certificates = createCertificates(ts);
} catch (Exception e) {
throw new IllegalConfigurationException(String.format("Cannot instantiate trust store '%s'", getName()), e);
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class FileTrustStoreImpl method validateTrustStore.
private static void validateTrustStore(FileTrustStore trustStore) {
KeyStore keyStore;
try {
keyStore = initializeKeyStore(trustStore);
} catch (Exception e) {
final String message;
if (e instanceof IOException && e.getCause() != null && e.getCause() instanceof UnrecoverableKeyException) {
message = "Check trust store password. Cannot instantiate trust store from '" + trustStore.getStoreUrl() + "'.";
} else {
message = "Cannot instantiate trust store from '" + trustStore.getStoreUrl() + "'.";
}
throw new IllegalConfigurationException(message, e);
}
try {
final Enumeration<String> aliasesEnum = keyStore.aliases();
boolean certificateFound = false;
while (aliasesEnum.hasMoreElements()) {
String alias = aliasesEnum.nextElement();
if (keyStore.isCertificateEntry(alias)) {
certificateFound = true;
break;
}
}
if (!certificateFound) {
throw new IllegalConfigurationException("Trust store must contain at least one certificate.");
}
} catch (KeyStoreException e) {
throw new ServerScopedRuntimeException("Trust store has not been initialized", e);
}
try {
TrustManagerFactory.getInstance(trustStore.getTrustManagerFactoryAlgorithm());
} catch (NoSuchAlgorithmException e) {
throw new IllegalConfigurationException("Unknown trustManagerFactoryAlgorithm: " + trustStore.getTrustManagerFactoryAlgorithm());
}
}
Aggregations