Ensure that security client is used in x-pack

This commit is fixing an issue with the build. Currently we have a
scenario where a call to build a transport client is not using the
security client. This modifies the settings source to ensure that the
security client is used.

Original commit: elastic/x-pack-elasticsearch@2d6ea1f4e4
This commit is contained in:
Tim Brooks 2017-07-26 13:36:20 -05:00
parent d09fc8ceca
commit 1603823f2c
2 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.analysis.common.CommonAnalysisPlugin;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.common.settings.SecureSettings;
import org.elasticsearch.common.settings.SecureString;
@ -138,8 +139,13 @@ public class SecuritySettingsSource extends ClusterDiscoveryConfiguration.Unicas
@Override
public Settings transportClientSettings() {
Settings.Builder builder = Settings.builder().put(super.transportClientSettings());
Settings superSettings = super.transportClientSettings();
Settings.Builder builder = Settings.builder().put(superSettings);
addClientSSLSettings(builder, "");
if (NetworkModule.TRANSPORT_TYPE_SETTING.exists(superSettings) == false) {
builder.put(NetworkModule.TRANSPORT_TYPE_SETTING.getKey(), Security.NAME4);
}
if (randomBoolean()) {
builder.put(Security.USER_SETTING.getKey(),
transportClientUsername() + ":" + new String(transportClientPassword().getChars()));

View File

@ -56,7 +56,7 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase {
ObjectPath objectPath = ObjectPath.createFromResponse(response);
assertThat(objectPath.evaluate("username").toString(), equalTo(SecuritySettingsSource.TEST_USER_NAME));
@SuppressWarnings("unchecked")
List<String> roles = (List<String>) objectPath.evaluate("roles");
List<String> roles = objectPath.evaluate("roles");
assertThat(roles.size(), is(1));
assertThat(roles, contains(SecuritySettingsSource.TEST_ROLE));
}