@Test(expected = FileNotFoundException.class) public void testAuthTypeSSL() throws Exception { final String nifiRegistryUrl = "https: Map<String,String> configs = new HashMap<>(); configs.put(NiFiRegistryConfigs.NIFI_REG_URL, nifiRegistryUrl); configs.put(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE, NiFiRegistryAuthType.SSL.name()); configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE, "src/test/resources/missing.jks"); configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_PASSWORD, "password"); configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_TYPE, "JKS"); configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE, "src/test/resources/missing.jks"); configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_PASSWORD, "password"); configs.put(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_TYPE, "JKS"); NiFiRegistryConnectionMgr.getNiFiRegistryClient("nifi-registry", configs); }
static public NiFiRegistryClient getNiFiRegistryClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiRegistryConfigs.NIFI_REG_URL); validateNotBlank(url, "NiFi Registry URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiRegistryAuthType authType = NiFiRegistryAuthType.valueOf(authTypeStr); if (LOG.isDebugEnabled()) { LOG.debug("NiFiRegistryAuthType is " + authType.name()); } SSLContext sslContext = null; if (authType == NiFiRegistryAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_USER_DEFAULT_CONTEXT); if (!StringUtils.isBlank(useDefaultSSLContext) && "true".equalsIgnoreCase(useDefaultSSLContext)) { if (!StringUtils.isBlank(keystore) || !StringUtils.isBlank(keystoreType) || !StringUtils.isBlank(keystorePassword) || !StringUtils.isBlank(truststore) || !StringUtils.isBlank(truststoreType) || !StringUtils.isBlank(truststorePassword)) { throw new IllegalArgumentException("Keystore and Truststore configuration cannot be provided when using default SSL context"); } sslContext = SSLContext.getDefault(); } else { validateNotBlank(keystore, "Keystore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystoreType, "Keystore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystorePassword, "Keystore Password is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststore, "Truststore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststoreType, "Truststore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststorePassword, "Truststore Password is required for " + serviceName + " with Authentication Type of SSL"); LOG.debug("Creating SSLContext for NiFi Registry connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiRegistryClient(url.trim(), sslContext); }
NiFiRegistryConnectionMgr { static public NiFiRegistryClient getNiFiRegistryClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiRegistryConfigs.NIFI_REG_URL); validateNotBlank(url, "NiFi Registry URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiRegistryAuthType authType = NiFiRegistryAuthType.valueOf(authTypeStr); if (LOG.isDebugEnabled()) { LOG.debug("NiFiRegistryAuthType is " + authType.name()); } SSLContext sslContext = null; if (authType == NiFiRegistryAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_USER_DEFAULT_CONTEXT); if (!StringUtils.isBlank(useDefaultSSLContext) && "true".equalsIgnoreCase(useDefaultSSLContext)) { if (!StringUtils.isBlank(keystore) || !StringUtils.isBlank(keystoreType) || !StringUtils.isBlank(keystorePassword) || !StringUtils.isBlank(truststore) || !StringUtils.isBlank(truststoreType) || !StringUtils.isBlank(truststorePassword)) { throw new IllegalArgumentException("Keystore and Truststore configuration cannot be provided when using default SSL context"); } sslContext = SSLContext.getDefault(); } else { validateNotBlank(keystore, "Keystore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystoreType, "Keystore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystorePassword, "Keystore Password is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststore, "Truststore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststoreType, "Truststore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststorePassword, "Truststore Password is required for " + serviceName + " with Authentication Type of SSL"); LOG.debug("Creating SSLContext for NiFi Registry connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiRegistryClient(url.trim(), sslContext); } }
NiFiRegistryConnectionMgr { static public NiFiRegistryClient getNiFiRegistryClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiRegistryConfigs.NIFI_REG_URL); validateNotBlank(url, "NiFi Registry URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiRegistryAuthType authType = NiFiRegistryAuthType.valueOf(authTypeStr); if (LOG.isDebugEnabled()) { LOG.debug("NiFiRegistryAuthType is " + authType.name()); } SSLContext sslContext = null; if (authType == NiFiRegistryAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_USER_DEFAULT_CONTEXT); if (!StringUtils.isBlank(useDefaultSSLContext) && "true".equalsIgnoreCase(useDefaultSSLContext)) { if (!StringUtils.isBlank(keystore) || !StringUtils.isBlank(keystoreType) || !StringUtils.isBlank(keystorePassword) || !StringUtils.isBlank(truststore) || !StringUtils.isBlank(truststoreType) || !StringUtils.isBlank(truststorePassword)) { throw new IllegalArgumentException("Keystore and Truststore configuration cannot be provided when using default SSL context"); } sslContext = SSLContext.getDefault(); } else { validateNotBlank(keystore, "Keystore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystoreType, "Keystore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystorePassword, "Keystore Password is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststore, "Truststore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststoreType, "Truststore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststorePassword, "Truststore Password is required for " + serviceName + " with Authentication Type of SSL"); LOG.debug("Creating SSLContext for NiFi Registry connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiRegistryClient(url.trim(), sslContext); }  }
NiFiRegistryConnectionMgr { static public NiFiRegistryClient getNiFiRegistryClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiRegistryConfigs.NIFI_REG_URL); validateNotBlank(url, "NiFi Registry URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiRegistryAuthType authType = NiFiRegistryAuthType.valueOf(authTypeStr); if (LOG.isDebugEnabled()) { LOG.debug("NiFiRegistryAuthType is " + authType.name()); } SSLContext sslContext = null; if (authType == NiFiRegistryAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_USER_DEFAULT_CONTEXT); if (!StringUtils.isBlank(useDefaultSSLContext) && "true".equalsIgnoreCase(useDefaultSSLContext)) { if (!StringUtils.isBlank(keystore) || !StringUtils.isBlank(keystoreType) || !StringUtils.isBlank(keystorePassword) || !StringUtils.isBlank(truststore) || !StringUtils.isBlank(truststoreType) || !StringUtils.isBlank(truststorePassword)) { throw new IllegalArgumentException("Keystore and Truststore configuration cannot be provided when using default SSL context"); } sslContext = SSLContext.getDefault(); } else { validateNotBlank(keystore, "Keystore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystoreType, "Keystore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystorePassword, "Keystore Password is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststore, "Truststore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststoreType, "Truststore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststorePassword, "Truststore Password is required for " + serviceName + " with Authentication Type of SSL"); LOG.debug("Creating SSLContext for NiFi Registry connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiRegistryClient(url.trim(), sslContext); }  static NiFiRegistryClient getNiFiRegistryClient(String serviceName, Map<String, String> configs); static HashMap<String, Object> connectionTest(String serviceName, Map<String, String> configs); }
NiFiRegistryConnectionMgr { static public NiFiRegistryClient getNiFiRegistryClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiRegistryConfigs.NIFI_REG_URL); validateNotBlank(url, "NiFi Registry URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiRegistryConfigs.NIFI_REG_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiRegistryAuthType authType = NiFiRegistryAuthType.valueOf(authTypeStr); if (LOG.isDebugEnabled()) { LOG.debug("NiFiRegistryAuthType is " + authType.name()); } SSLContext sslContext = null; if (authType == NiFiRegistryAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiRegistryConfigs.NIFI_REG_SSL_USER_DEFAULT_CONTEXT); if (!StringUtils.isBlank(useDefaultSSLContext) && "true".equalsIgnoreCase(useDefaultSSLContext)) { if (!StringUtils.isBlank(keystore) || !StringUtils.isBlank(keystoreType) || !StringUtils.isBlank(keystorePassword) || !StringUtils.isBlank(truststore) || !StringUtils.isBlank(truststoreType) || !StringUtils.isBlank(truststorePassword)) { throw new IllegalArgumentException("Keystore and Truststore configuration cannot be provided when using default SSL context"); } sslContext = SSLContext.getDefault(); } else { validateNotBlank(keystore, "Keystore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystoreType, "Keystore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(keystorePassword, "Keystore Password is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststore, "Truststore is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststoreType, "Truststore Type is required for " + serviceName + " with Authentication Type of SSL"); validateNotBlank(truststorePassword, "Truststore Password is required for " + serviceName + " with Authentication Type of SSL"); LOG.debug("Creating SSLContext for NiFi Registry connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiRegistryClient(url.trim(), sslContext); }  static NiFiRegistryClient getNiFiRegistryClient(String serviceName, Map<String, String> configs); static HashMap<String, Object> connectionTest(String serviceName, Map<String, String> configs);  }