use of org.elasticsearch.common.settings.SecureString in project elasticsearch by elastic.
the class S3RepositoryTests method testSettingsResolution.
public void testSettingsResolution() throws Exception {
Settings localSettings = Settings.builder().put(Repository.KEY_SETTING.getKey(), "key1").build();
Settings globalSettings = Settings.builder().put(Repositories.KEY_SETTING.getKey(), "key2").build();
assertEquals(new SecureString("key1".toCharArray()), getValue(localSettings, globalSettings, Repository.KEY_SETTING, Repositories.KEY_SETTING));
assertEquals(new SecureString("key1".toCharArray()), getValue(localSettings, Settings.EMPTY, Repository.KEY_SETTING, Repositories.KEY_SETTING));
assertEquals(new SecureString("key2".toCharArray()), getValue(Settings.EMPTY, globalSettings, Repository.KEY_SETTING, Repositories.KEY_SETTING));
assertEquals(new SecureString("".toCharArray()), getValue(Settings.EMPTY, Settings.EMPTY, Repository.KEY_SETTING, Repositories.KEY_SETTING));
assertSettingDeprecationsAndWarnings(new Setting<?>[] { Repository.KEY_SETTING, Repositories.KEY_SETTING });
}
use of org.elasticsearch.common.settings.SecureString in project elasticsearch by elastic.
the class InternalAwsS3Service method buildConfiguration.
// pkg private for tests
static ClientConfiguration buildConfiguration(Logger logger, Settings repositorySettings, Settings settings, String clientName, Integer maxRetries, String endpoint, boolean useThrottleRetries) {
ClientConfiguration clientConfiguration = new ClientConfiguration();
// the response metadata cache is only there for diagnostics purposes,
// but can force objects from every response to the old generation.
clientConfiguration.setResponseMetadataCacheSize(0);
Protocol protocol = getConfigValue(repositorySettings, settings, clientName, S3Repository.PROTOCOL_SETTING, S3Repository.Repository.PROTOCOL_SETTING, S3Repository.Repositories.PROTOCOL_SETTING);
clientConfiguration.setProtocol(protocol);
String proxyHost = getConfigValue(null, settings, clientName, S3Repository.PROXY_HOST_SETTING, null, CLOUD_S3.PROXY_HOST_SETTING);
if (Strings.hasText(proxyHost)) {
Integer proxyPort = getConfigValue(null, settings, clientName, S3Repository.PROXY_PORT_SETTING, null, CLOUD_S3.PROXY_PORT_SETTING);
try (SecureString proxyUsername = getConfigValue(null, settings, clientName, S3Repository.PROXY_USERNAME_SETTING, null, CLOUD_S3.PROXY_USERNAME_SETTING);
SecureString proxyPassword = getConfigValue(null, settings, clientName, S3Repository.PROXY_PASSWORD_SETTING, null, CLOUD_S3.PROXY_PASSWORD_SETTING)) {
clientConfiguration.withProxyHost(proxyHost).withProxyPort(proxyPort).withProxyUsername(proxyUsername.toString()).withProxyPassword(proxyPassword.toString());
}
}
if (maxRetries != null) {
// If not explicitly set, default to 3 with exponential backoff policy
clientConfiguration.setMaxErrorRetry(maxRetries);
}
clientConfiguration.setUseThrottleRetries(useThrottleRetries);
// #155: we might have 3rd party users using older S3 API version
String awsSigner = CLOUD_S3.SIGNER_SETTING.get(settings);
if (Strings.hasText(awsSigner)) {
logger.debug("using AWS API signer [{}]", awsSigner);
AwsSigner.configureSigner(awsSigner, clientConfiguration, endpoint);
}
TimeValue readTimeout = getConfigValue(null, settings, clientName, S3Repository.READ_TIMEOUT_SETTING, null, CLOUD_S3.READ_TIMEOUT);
clientConfiguration.setSocketTimeout((int) readTimeout.millis());
return clientConfiguration;
}
use of org.elasticsearch.common.settings.SecureString in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testSecureSettings.
public void testSecureSettings() {
MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString("foo", "secret");
Settings input = Settings.builder().put(baseEnvSettings).setSecureSettings(secureSettings).build();
Environment env = InternalSettingsPreparer.prepareEnvironment(input, null);
Setting<SecureString> fakeSetting = SecureSetting.secureString("foo", null, false);
assertEquals("secret", fakeSetting.get(env.settings()).toString());
}
use of org.elasticsearch.common.settings.SecureString in project crate by crate.
the class HttpAuthUpstreamHandler method credentialsFromRequest.
@VisibleForTesting
static Tuple<String, SecureString> credentialsFromRequest(HttpRequest request, @Nullable SSLSession session, Settings settings) {
String username = null;
if (request.headers().contains(HttpHeaderNames.AUTHORIZATION.toString())) {
// Prefer Http Basic Auth
return Headers.extractCredentialsFromHttpBasicAuthHeader(request.headers().get(HttpHeaderNames.AUTHORIZATION.toString()));
} else {
// prefer commonName as userName over AUTH_TRUST_HTTP_DEFAULT_HEADER user
if (session != null) {
try {
Certificate certificate = session.getPeerCertificates()[0];
username = SSL.extractCN(certificate);
} catch (ArrayIndexOutOfBoundsException | SSLPeerUnverifiedException ignored) {
// client cert is optional
}
}
if (username == null) {
username = AuthSettings.AUTH_TRUST_HTTP_DEFAULT_HEADER.get(settings);
}
}
return new Tuple<>(username, null);
}
use of org.elasticsearch.common.settings.SecureString in project crate by crate.
the class UserActions method getUserPasswordProperty.
@VisibleForTesting
@Nullable
static SecureString getUserPasswordProperty(GenericProperties<Symbol> userStmtProperties, Row parameters, TransactionContext txnCtx, NodeContext nodeCtx) throws IllegalArgumentException {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, parameters, SubQueryResults.EMPTY);
Map<String, Object> properties = userStmtProperties.map(eval).properties();
final String PASSWORD_PROPERTY = "password";
for (String key : properties.keySet()) {
if (PASSWORD_PROPERTY.equals(key)) {
String value = DataTypes.STRING.sanitizeValue(properties.get(key));
if (value != null) {
return new SecureString(value.toCharArray());
}
// Password will be reset
return null;
} else {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "\"%s\" is not a valid user property", key));
}
}
return null;
}
Aggregations