@Test public void testAuthTypeNone() throws Exception { final String nifiUrl = "http: Map<String,String> configs = new HashMap<>(); configs.put(NiFiConfigs.NIFI_URL, nifiUrl); configs.put(NiFiConfigs.NIFI_AUTHENTICATION_TYPE, NiFiAuthType.NONE.name()); NiFiClient client = NiFiConnectionMgr.getNiFiClient("nifi", configs); Assert.assertNotNull(client); Assert.assertEquals(nifiUrl, client.getUrl()); Assert.assertNull(client.getSslContext()); }
static public NiFiClient getNiFiClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiConfigs.NIFI_URL); validateNotBlank(url, "NiFi URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiConfigs.NIFI_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiAuthType authType = NiFiAuthType.valueOf(authTypeStr); LOG.debug("NiFiAuthType is " + authType.name()); SSLContext sslContext = null; if (authType == NiFiAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiConfigs.NIFI_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 connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiClient(url.trim(), sslContext); }
NiFiConnectionMgr { static public NiFiClient getNiFiClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiConfigs.NIFI_URL); validateNotBlank(url, "NiFi URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiConfigs.NIFI_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiAuthType authType = NiFiAuthType.valueOf(authTypeStr); LOG.debug("NiFiAuthType is " + authType.name()); SSLContext sslContext = null; if (authType == NiFiAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiConfigs.NIFI_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 connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiClient(url.trim(), sslContext); } }
NiFiConnectionMgr { static public NiFiClient getNiFiClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiConfigs.NIFI_URL); validateNotBlank(url, "NiFi URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiConfigs.NIFI_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiAuthType authType = NiFiAuthType.valueOf(authTypeStr); LOG.debug("NiFiAuthType is " + authType.name()); SSLContext sslContext = null; if (authType == NiFiAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiConfigs.NIFI_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 connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiClient(url.trim(), sslContext); }  }
NiFiConnectionMgr { static public NiFiClient getNiFiClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiConfigs.NIFI_URL); validateNotBlank(url, "NiFi URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiConfigs.NIFI_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiAuthType authType = NiFiAuthType.valueOf(authTypeStr); LOG.debug("NiFiAuthType is " + authType.name()); SSLContext sslContext = null; if (authType == NiFiAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiConfigs.NIFI_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 connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiClient(url.trim(), sslContext); }  static NiFiClient getNiFiClient(String serviceName, Map<String, String> configs); static HashMap<String, Object> connectionTest(String serviceName, Map<String, String> configs); }
NiFiConnectionMgr { static public NiFiClient getNiFiClient(String serviceName, Map<String, String> configs) throws Exception { final String url = configs.get(NiFiConfigs.NIFI_URL); validateNotBlank(url, "NiFi URL is required for " + serviceName); validateUrl(url); final String authTypeStr = configs.get(NiFiConfigs.NIFI_AUTHENTICATION_TYPE); validateNotBlank(authTypeStr, "Authentication Type is required for " + serviceName); final NiFiAuthType authType = NiFiAuthType.valueOf(authTypeStr); LOG.debug("NiFiAuthType is " + authType.name()); SSLContext sslContext = null; if (authType == NiFiAuthType.SSL) { if (!url.startsWith("https")) { throw new IllegalArgumentException("Authentication Type of SSL requires an https URL"); } final String keystore = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE); final String keystoreType = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_TYPE); final String keystorePassword = configs.get(NiFiConfigs.NIFI_SSL_KEYSTORE_PASSWORD); final String truststore = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE); final String truststoreType = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_TYPE); final String truststorePassword = configs.get(NiFiConfigs.NIFI_SSL_TRUSTSTORE_PASSWORD); final String useDefaultSSLContext = configs.get(NiFiConfigs.NIFI_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 connection"); sslContext = createSslContext( keystore.trim(), keystorePassword.trim().toCharArray(), keystoreType.trim(), truststore.trim(), truststorePassword.trim().toCharArray(), truststoreType.trim(), "TLS"); } } return new NiFiClient(url.trim(), sslContext); }  static NiFiClient getNiFiClient(String serviceName, Map<String, String> configs); static HashMap<String, Object> connectionTest(String serviceName, Map<String, String> configs);  }