*
* @throws InvalidPluginConfigurationException if settings are incorrect
*/
public void validate() {
if (getPort() == null || getPort() <= 0) {
throw new InvalidPluginConfigurationException(
"Unable to detect management port. Please enable management HTTP interface on and then set correct port number in Connection Settings of this resource");
}
if (isSecure()) {
String truststore = getTruststore();
if (truststore != null) {
if (!new File(truststore).isFile()) {
throw new InvalidPluginConfigurationException("Truststore file does not exist");
}
String truststoreType = getTruststoreType();
if (truststoreType == null) {
throw new InvalidPluginConfigurationException(
"Truststore type is required when using a custom truststore file");
}
try {
KeyStore.getInstance(truststoreType);
} catch (KeyStoreException e) {
throw new InvalidPluginConfigurationException("Truststore type not supported: " + e.getMessage());
}
try {
loadKeystore(truststoreType, truststore, getTruststorePassword());
} catch (Exception e) {
throw new InvalidPluginConfigurationException("Cannot read the truststore: " + e.getMessage());
}
}
if (isClientcertAuthentication()) {
String keystore = getKeystore();
if (keystore == null) {
throw new InvalidPluginConfigurationException(
"Keystore is required when using client certificate authentication");
}
if (!new File(keystore).isFile()) {
throw new InvalidPluginConfigurationException("Keystore file does not exist");
}
String keystoreType = getKeystoreType();
if (keystoreType == null) {
throw new InvalidPluginConfigurationException(
"Keystore type is required when using a custom keystore file");
}
try {
KeyStore.getInstance(keystoreType);
} catch (KeyStoreException e) {
throw new InvalidPluginConfigurationException("Keystore type not supported: " + e.getMessage());
}
try {
loadKeystore(keystoreType, keystore, getKeystorePassword());
} catch (Exception e) {
throw new InvalidPluginConfigurationException("Cannot read the keystore: " + e.getMessage());
}
}
}
}