@Test public void clientKeyStorePasswordInConfigAndGlobalAndPrefixedEnvVarThenValid() { final SslConfig sslConfig = new SslConfig(); sslConfig.setTls(SslAuthenticationMode.STRICT); sslConfig.setGenerateKeyStoreIfNotExisted(false); sslConfig.setServerKeyStore(tmpFile); sslConfig.setServerKeyStorePassword("pwd".toCharArray()); sslConfig.setEnvironmentVariablePrefix("PREFIX"); sslConfig.setClientKeyStore(tmpFile); sslConfig.setClientKeyStorePassword("password".toCharArray()); when(envVarProvider.hasEnv(EnvironmentVariables.CLIENT_KEYSTORE_PWD)).thenReturn(true); when(envVarProvider.hasEnv( sslConfig.getEnvironmentVariablePrefix() + "_" + EnvironmentVariables.CLIENT_KEYSTORE_PWD)) .thenReturn(true); final boolean result = validator.isValid(sslConfig, context); final String msg = "Client keystore configuration not valid. " + "Please ensure keystore file exists or keystore password not null, " + "otherwise please set keystore generation flag to true to have keystore created"; verify(context, never()).buildConstraintViolationWithTemplate(msg); verify(context).buildConstraintViolationWithTemplate(anyString()); assertThat(result).isFalse(); }
@Override public boolean isValid(SslConfig sslConfig, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (Objects.isNull(sslConfig)) { return true; } if (sslConfig.getTls() == SslAuthenticationMode.STRICT) { if (!sslConfig.isGenerateKeyStoreIfNotExisted()) { if (!isServerKeyStoreConfigValid(sslConfig, context) || !isClientKeyStoreConfigValid(sslConfig, context)) { return false; } } if (!isTrustModeConfigValid(sslConfig, context)) { return false; } if (!isServerConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isServerConfigValidForCAMode(sslConfig, context)) { return false; } if (!isClientConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isClientConfigValidForCAMode(sslConfig, context)) { return false; } } return true; }
SslConfigValidator implements ConstraintValidator<ValidSsl, SslConfig> { @Override public boolean isValid(SslConfig sslConfig, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (Objects.isNull(sslConfig)) { return true; } if (sslConfig.getTls() == SslAuthenticationMode.STRICT) { if (!sslConfig.isGenerateKeyStoreIfNotExisted()) { if (!isServerKeyStoreConfigValid(sslConfig, context) || !isClientKeyStoreConfigValid(sslConfig, context)) { return false; } } if (!isTrustModeConfigValid(sslConfig, context)) { return false; } if (!isServerConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isServerConfigValidForCAMode(sslConfig, context)) { return false; } if (!isClientConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isClientConfigValidForCAMode(sslConfig, context)) { return false; } } return true; } }
SslConfigValidator implements ConstraintValidator<ValidSsl, SslConfig> { @Override public boolean isValid(SslConfig sslConfig, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (Objects.isNull(sslConfig)) { return true; } if (sslConfig.getTls() == SslAuthenticationMode.STRICT) { if (!sslConfig.isGenerateKeyStoreIfNotExisted()) { if (!isServerKeyStoreConfigValid(sslConfig, context) || !isClientKeyStoreConfigValid(sslConfig, context)) { return false; } } if (!isTrustModeConfigValid(sslConfig, context)) { return false; } if (!isServerConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isServerConfigValidForCAMode(sslConfig, context)) { return false; } if (!isClientConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isClientConfigValidForCAMode(sslConfig, context)) { return false; } } return true; }  }
SslConfigValidator implements ConstraintValidator<ValidSsl, SslConfig> { @Override public boolean isValid(SslConfig sslConfig, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (Objects.isNull(sslConfig)) { return true; } if (sslConfig.getTls() == SslAuthenticationMode.STRICT) { if (!sslConfig.isGenerateKeyStoreIfNotExisted()) { if (!isServerKeyStoreConfigValid(sslConfig, context) || !isClientKeyStoreConfigValid(sslConfig, context)) { return false; } } if (!isTrustModeConfigValid(sslConfig, context)) { return false; } if (!isServerConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isServerConfigValidForCAMode(sslConfig, context)) { return false; } if (!isClientConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isClientConfigValidForCAMode(sslConfig, context)) { return false; } } return true; }  @Override boolean isValid(SslConfig sslConfig, ConstraintValidatorContext context); }
SslConfigValidator implements ConstraintValidator<ValidSsl, SslConfig> { @Override public boolean isValid(SslConfig sslConfig, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (Objects.isNull(sslConfig)) { return true; } if (sslConfig.getTls() == SslAuthenticationMode.STRICT) { if (!sslConfig.isGenerateKeyStoreIfNotExisted()) { if (!isServerKeyStoreConfigValid(sslConfig, context) || !isClientKeyStoreConfigValid(sslConfig, context)) { return false; } } if (!isTrustModeConfigValid(sslConfig, context)) { return false; } if (!isServerConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isServerConfigValidForCAMode(sslConfig, context)) { return false; } if (!isClientConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isClientConfigValidForCAMode(sslConfig, context)) { return false; } } return true; }  @Override boolean isValid(SslConfig sslConfig, ConstraintValidatorContext context);  }