diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/main/java/org/apache/nifi/ssl/StandardSSLContextService.java b/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/main/java/org/apache/nifi/ssl/StandardSSLContextService.java index 9817532333..d10c840b26 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/main/java/org/apache/nifi/ssl/StandardSSLContextService.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/main/java/org/apache/nifi/ssl/StandardSSLContextService.java @@ -118,6 +118,7 @@ public class StandardSSLContextService extends AbstractControllerService impleme private static final List properties; private ConfigurationContext configContext; + private boolean isValidated; static { List props = new ArrayList<>(); @@ -161,6 +162,12 @@ public class StandardSSLContextService extends AbstractControllerService impleme createSSLContext(ClientAuth.REQUIRED); } + @Override + public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue) { + super.onPropertyModified(descriptor, oldValue, newValue); + isValidated = false; + } + private static Validator createFileExistsAndReadableValidator() { return new Validator() { // Not using the FILE_EXISTS_VALIDATOR because the default is to @@ -200,6 +207,11 @@ public class StandardSSLContextService extends AbstractControllerService impleme @Override protected Collection customValidate(ValidationContext validationContext) { final Collection results = new ArrayList<>(); + + if(isValidated) { + return results; + } + results.addAll(validateStore(validationContext.getProperties(), KeystoreValidationGroup.KEYSTORE)); results.addAll(validateStore(validationContext.getProperties(), KeystoreValidationGroup.TRUSTSTORE)); @@ -228,6 +240,9 @@ public class StandardSSLContextService extends AbstractControllerService impleme .build()); } } + + isValidated = results.isEmpty(); + return results; } diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java b/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java index a7719148f4..03aacc0801 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java @@ -115,6 +115,35 @@ public class SSLContextServiceTest { sslService.createSSLContext(ClientAuth.NONE); } + @Test + public void testWithChanges() throws InitializationException { + final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); + SSLContextService service = new StandardSSLContextService(); + runner.addControllerService("test-good1", service); + runner.setProperty(service, StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks"); + runner.setProperty(service, StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest"); + runner.setProperty(service, StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS"); + runner.setProperty(service, StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks"); + runner.setProperty(service, StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest"); + runner.setProperty(service, StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS"); + runner.enableControllerService(service); + + runner.setProperty("SSL Context Svc ID", "test-good1"); + runner.assertValid(service); + + runner.disableControllerService(service); + runner.setProperty(service,StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/DOES-NOT-EXIST.jks"); + runner.assertNotValid(service); + + runner.setProperty(service, StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks"); + runner.setProperty(service, StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "badpassword"); + runner.assertNotValid(service); + + runner.setProperty(service, StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest"); + runner.enableControllerService(service); + runner.assertValid(service); + } + @Test public void testGoodTrustOnly() { try {