use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class SimpleLDAPAuthenticationManagerImpl method validateInitialDirContext.
private void validateInitialDirContext(Class<? extends SocketFactory> sslSocketFactoryOverrideClass, final String providerUrl, final String searchUsername, final String searchPassword) {
Hashtable<String, Object> env = createInitialDirContextEnvironment(providerUrl);
setupSearchContext(env, searchUsername, searchPassword);
InitialDirContext ctx = null;
try {
ctx = createInitialDirContext(env, sslSocketFactoryOverrideClass);
} catch (NamingException e) {
LOGGER.error("Failed to establish connectivity to the ldap server for '{}'", providerUrl, e);
throw new IllegalConfigurationException("Failed to establish connectivity to the ldap server.", e);
} finally {
closeSafely(ctx);
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class SimpleLDAPAuthenticationManagerImpl method createSslSocketFactoryOverrideClass.
private Class<? extends SocketFactory> createSslSocketFactoryOverrideClass(final TrustStore trustStore) {
String managerName = String.format("%s_%s_%s", getName(), getId(), trustStore == null ? "none" : trustStore.getName());
String clazzName = new StringUtil().createUniqueJavaName(managerName);
SSLContext sslContext = null;
try {
sslContext = SSLUtil.tryGetSSLContext();
sslContext.init(null, trustStore == null ? null : trustStore.getTrustManagers(), null);
} catch (GeneralSecurityException e) {
LOGGER.error("Exception creating SSLContext", e);
if (trustStore != null) {
throw new IllegalConfigurationException("Error creating SSLContext with trust store : " + trustStore.getName(), e);
} else {
throw new IllegalConfigurationException("Error creating SSLContext (no trust store)", e);
}
}
SSLSocketFactory sslSocketFactory = new CipherSuiteAndProtocolRestrictingSSLSocketFactory(sslContext.getSocketFactory(), _tlsCipherSuiteWhiteList, _tlsCipherSuiteBlackList, _tlsProtocolWhiteList, _tlsProtocolBlackList);
Class<? extends AbstractLDAPSSLSocketFactory> clazz = LDAPSSLSocketFactoryGenerator.createSubClass(clazzName, sslSocketFactory);
LOGGER.debug("Connection to Directory will use custom SSL socket factory : {}", clazz);
return clazz;
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AESKeyFileEncrypterFactory method createEncrypter.
@Override
public ConfigurationSecretEncrypter createEncrypter(final ConfiguredObject<?> object) {
String fileLocation;
if (object.getContextKeys(false).contains(ENCRYPTER_KEY_FILE)) {
fileLocation = object.getContextValue(String.class, ENCRYPTER_KEY_FILE);
} else {
fileLocation = object.getContextValue(String.class, SystemConfig.QPID_WORK_DIR) + File.separator + DEFAULT_KEYS_SUBDIR_NAME + File.separator + object.getCategoryClass().getSimpleName() + "_" + object.getName() + ".key";
Map<String, String> context = object.getContext();
Map<String, String> modifiedContext = new LinkedHashMap<>(context);
modifiedContext.put(ENCRYPTER_KEY_FILE, fileLocation);
object.setAttributes(Collections.<String, Object>singletonMap(ConfiguredObject.CONTEXT, modifiedContext));
}
File file = new File(fileLocation);
if (!file.exists()) {
LOGGER.warn("Configuration encryption is enabled, but no configuration secret was found. A new configuration secret will be created at '{}'.", fileLocation);
createAndPopulateKeyFile(file);
}
if (!file.isFile()) {
throw new IllegalArgumentException("File '" + fileLocation + "' is not a regular file.");
}
try {
checkFilePermissions(fileLocation, file);
if (Files.size(file.toPath()) != AES_KEY_SIZE_BYTES) {
throw new IllegalArgumentException("Key file '" + fileLocation + "' contains an incorrect about of data");
}
try (FileInputStream inputStream = new FileInputStream(file)) {
byte[] key = new byte[AES_KEY_SIZE_BYTES];
int pos = 0;
int read;
while (pos < key.length && -1 != (read = inputStream.read(key, pos, key.length - pos))) {
pos += read;
}
if (pos != key.length) {
throw new IllegalConfigurationException("Key file '" + fileLocation + "' contained an incorrect about of data");
}
SecretKeySpec keySpec = new SecretKeySpec(key, AES_ALGORITHM);
return new AESKeyFileEncrypter(keySpec);
}
} catch (IOException e) {
throw new IllegalConfigurationException("Unable to get file permissions: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class BrokerStoreUpgraderAndRecoverer method createVirtualHostsRecordsFromBrokerRecordForModel_1_x.
private static ConfiguredObjectRecord createVirtualHostsRecordsFromBrokerRecordForModel_1_x(ConfiguredObjectRecord brokerRecord, StoreUpgraderPhase upgrader) {
Map<String, Object> attributes = brokerRecord.getAttributes();
if (attributes.containsKey(VIRTUALHOSTS) && attributes.get(VIRTUALHOSTS) instanceof Collection) {
Collection<?> virtualHosts = (Collection<?>) attributes.get(VIRTUALHOSTS);
for (Object virtualHost : virtualHosts) {
if (virtualHost instanceof Map) {
Map<String, Object> virtualHostAttributes = (Map) virtualHost;
if (virtualHostAttributes.containsKey("configPath")) {
throw new IllegalConfigurationException("Auto-upgrade of virtual host " + attributes.get("name") + " having XML configuration is not supported. Virtual host configuration file is " + attributes.get("configPath"));
}
virtualHostAttributes = new HashMap<>(virtualHostAttributes);
Object nameAttribute = virtualHostAttributes.get("name");
Object idAttribute = virtualHostAttributes.remove("id");
UUID id;
if (idAttribute == null) {
id = UUID.randomUUID();
} else {
if (idAttribute instanceof String) {
id = UUID.fromString((String) idAttribute);
} else if (idAttribute instanceof UUID) {
id = (UUID) idAttribute;
} else {
throw new IllegalConfigurationException("Illegal ID value '" + idAttribute + "' for virtual host " + nameAttribute);
}
}
ConfiguredObjectRecord nodeRecord = new ConfiguredObjectRecordImpl(id, "VirtualHost", virtualHostAttributes, Collections.singletonMap("Broker", brokerRecord.getId()));
upgrader.getUpdateMap().put(nodeRecord.getId(), nodeRecord);
upgrader.configuredObject(nodeRecord);
}
}
attributes = new HashMap<>(attributes);
attributes.remove(VIRTUALHOSTS);
brokerRecord = new ConfiguredObjectRecordImpl(brokerRecord.getId(), brokerRecord.getType(), attributes, brokerRecord.getParents());
upgrader.getUpdateMap().put(brokerRecord.getId(), brokerRecord);
}
return brokerRecord;
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class FileKeyStoreTest method testEmptyKeystoreRejected.
public void testEmptyKeystoreRejected() throws Exception {
final URL emptyKeystore = getClass().getResource(EMPTY_KEYSTORE_RESOURCE);
assertNotNull("Empty keystore not found", emptyKeystore);
Map<String, Object> attributes = new HashMap<>();
attributes.put(FileKeyStore.NAME, "myFileKeyStore");
attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD);
attributes.put(FileKeyStore.STORE_URL, emptyKeystore);
try {
_factory.create(KeyStore.class, attributes, _broker);
fail("Exception not thrown");
} catch (IllegalConfigurationException ice) {
String message = ice.getMessage();
assertTrue("Exception text not as unexpected:" + message, message.contains("Keystore must contain at least one private key."));
}
}
Aggregations