|
|
@@ -7,6 +7,7 @@ package org.elasticsearch.xpack.security.authc.ldap;
|
|
|
|
|
|
import com.unboundid.ldap.sdk.LDAPException;
|
|
|
import com.unboundid.ldap.sdk.ResultCode;
|
|
|
+import org.apache.lucene.util.LuceneTestCase;
|
|
|
import org.elasticsearch.action.support.PlainActionFuture;
|
|
|
import org.elasticsearch.common.settings.SecureString;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
@@ -42,10 +43,11 @@ import static org.hamcrest.Matchers.hasItem;
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
|
|
|
+@LuceneTestCase.AwaitsFix(bugUrl = "ActiveDirectorySessionFactoryTests")
|
|
|
public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryTestCase {
|
|
|
|
|
|
private static final String REALM_NAME = "ad-test";
|
|
|
- private static final RealmConfig.RealmIdentifier REALM_ID = new RealmConfig.RealmIdentifier("active_directory", REALM_NAME);
|
|
|
+ private static final RealmConfig.RealmIdentifier REALM_ID = new RealmConfig.RealmIdentifier("ad", REALM_NAME);
|
|
|
private final SecureString SECURED_PASSWORD = new SecureString(PASSWORD);
|
|
|
private ThreadPool threadPool;
|
|
|
|
|
|
@@ -65,7 +67,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
}
|
|
|
|
|
|
public void testAdAuth() throws Exception {
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false));
|
|
|
+ RealmConfig config = configureRealm("ad-test", buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false));
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
String userName = "ironman";
|
|
|
@@ -86,21 +88,21 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private RealmConfig configureRealm(String name, String type, Settings settings) {
|
|
|
+ private RealmConfig configureRealm(String name, Settings settings) {
|
|
|
final Environment env = TestEnvironment.newEnvironment(globalSettings);
|
|
|
final Settings mergedSettings = Settings.builder()
|
|
|
.put(settings)
|
|
|
- .normalizePrefix("xpack.security.authc.realms." + type + "." + name + ".")
|
|
|
+ .normalizePrefix("xpack.security.authc.realms." + name + ".")
|
|
|
.put(globalSettings)
|
|
|
.build();
|
|
|
this.sslService = new SSLService(mergedSettings, env);
|
|
|
- final RealmConfig.RealmIdentifier identifier = new RealmConfig.RealmIdentifier(type, name);
|
|
|
+ final RealmConfig.RealmIdentifier identifier = new RealmConfig.RealmIdentifier(LdapRealmSettings.AD_TYPE, name);
|
|
|
return new RealmConfig(identifier, mergedSettings, env, new ThreadContext(globalSettings));
|
|
|
}
|
|
|
|
|
|
public void testNetbiosAuth() throws Exception {
|
|
|
final String adUrl = randomFrom(AD_LDAP_URL, AD_LDAP_GC_URL);
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, buildAdSettings(adUrl, AD_DOMAIN, false));
|
|
|
+ RealmConfig config = configureRealm("ad-test", buildAdSettings(adUrl, AD_DOMAIN, false));
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
String userName = "ades\\ironman";
|
|
|
@@ -122,7 +124,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
}
|
|
|
|
|
|
public void testAdAuthAvengers() throws Exception {
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false));
|
|
|
+ RealmConfig config = configureRealm("ad-test", buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false));
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
String[] users = new String[]{"cap", "hawkeye", "hulk", "ironman", "thor", "blackwidow"};
|
|
|
@@ -138,7 +140,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
public void testAuthenticate() throws Exception {
|
|
|
Settings settings = buildAdSettings(REALM_ID, AD_LDAP_URL, AD_DOMAIN, "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com",
|
|
|
LdapSearchScope.ONE_LEVEL, false);
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, settings);
|
|
|
+ RealmConfig config = configureRealm("ad-test", settings);
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
String userName = "hulk";
|
|
|
@@ -161,7 +163,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
public void testAuthenticateBaseUserSearch() throws Exception {
|
|
|
Settings settings = buildAdSettings(REALM_ID, AD_LDAP_URL, AD_DOMAIN,
|
|
|
"CN=Bruce Banner, CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com", LdapSearchScope.BASE, false);
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, settings);
|
|
|
+ RealmConfig config = configureRealm("ad-test", settings);
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
String userName = "hulk";
|
|
|
@@ -189,7 +191,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
"CN=Avengers,CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com")
|
|
|
.put(ActiveDirectorySessionFactorySettings.AD_GROUP_SEARCH_SCOPE_SETTING, LdapSearchScope.BASE)
|
|
|
.build();
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, settings);
|
|
|
+ RealmConfig config = configureRealm("ad-test", settings);
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
String userName = "hulk";
|
|
|
@@ -205,7 +207,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
public void testAuthenticateWithUserPrincipalName() throws Exception {
|
|
|
Settings settings = buildAdSettings(REALM_ID, AD_LDAP_URL, AD_DOMAIN, "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com",
|
|
|
LdapSearchScope.ONE_LEVEL, false);
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, settings);
|
|
|
+ RealmConfig config = configureRealm("ad-test", settings);
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
//Login with the UserPrincipalName
|
|
|
@@ -225,7 +227,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
public void testAuthenticateWithSAMAccountName() throws Exception {
|
|
|
Settings settings = buildAdSettings(REALM_ID, AD_LDAP_URL, AD_DOMAIN, "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com",
|
|
|
LdapSearchScope.ONE_LEVEL, false);
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, settings);
|
|
|
+ RealmConfig config = configureRealm("ad-test", settings);
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
//login with sAMAccountName
|
|
|
@@ -250,7 +252,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
.put(getFullSettingKey(REALM_ID.getName(), ActiveDirectorySessionFactorySettings.AD_USER_SEARCH_FILTER_SETTING),
|
|
|
"(&(objectclass=user)(userPrincipalName={0}@ad.test.elasticsearch.com))")
|
|
|
.build();
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, settings);
|
|
|
+ RealmConfig config = configureRealm("ad-test", settings);
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
//Login with the UserPrincipalName
|
|
|
@@ -269,14 +271,18 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
public void testStandardLdapConnection() throws Exception {
|
|
|
String groupSearchBase = "DC=ad,DC=test,DC=elasticsearch,DC=com";
|
|
|
String userTemplate = "CN={0},CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com";
|
|
|
- final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier(LdapRealmSettings.LDAP_TYPE, "ad-as-ldap-test");
|
|
|
- final Settings settings = Settings.builder()
|
|
|
- .put(LdapTestCase.buildLdapSettings(realmId, new String[]{AD_LDAP_URL}, new String[]{userTemplate}, groupSearchBase,
|
|
|
- LdapSearchScope.SUB_TREE, null, false))
|
|
|
- .putList(RealmSettings.realmSslPrefix(realmId) + "certificate_authorities", certificatePaths)
|
|
|
- .put(getFullSettingKey(realmId, SessionFactorySettings.FOLLOW_REFERRALS_SETTING), FOLLOW_REFERRALS)
|
|
|
+ Settings settings = Settings.builder()
|
|
|
+ .put(LdapTestCase.buildLdapSettings(
|
|
|
+ new String[]{AD_LDAP_URL},
|
|
|
+ new String[]{userTemplate},
|
|
|
+ groupSearchBase,
|
|
|
+ LdapSearchScope.SUB_TREE,
|
|
|
+ null,
|
|
|
+ true))
|
|
|
+ .put("follow_referrals", FOLLOW_REFERRALS)
|
|
|
+ .putList("ssl.certificate_authorities", certificatePaths)
|
|
|
.build();
|
|
|
- RealmConfig config = configureRealm("ad-as-ldap-test", LdapRealmSettings.LDAP_TYPE, settings);
|
|
|
+ RealmConfig config = configureRealm("ad-as-ldap-test", settings);
|
|
|
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
|
|
|
|
|
String user = "Bruce Banner";
|
|
|
@@ -296,15 +302,21 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
public void testHandlingLdapReferralErrors() throws Exception {
|
|
|
String groupSearchBase = "DC=ad,DC=test,DC=elasticsearch,DC=com";
|
|
|
String userTemplate = "CN={0},CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com";
|
|
|
- final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier(LdapRealmSettings.LDAP_TYPE, "ad-as-ldap-test");
|
|
|
- Settings settings = Settings.builder()
|
|
|
- .put(LdapTestCase.buildLdapSettings(realmId, new String[]{AD_LDAP_URL}, new String[]{userTemplate}, groupSearchBase,
|
|
|
- LdapSearchScope.SUB_TREE, null, false))
|
|
|
- .putList(RealmSettings.realmSslPrefix(realmId) + "certificate_authorities", certificatePaths)
|
|
|
- .put(getFullSettingKey(realmId, SessionFactorySettings.FOLLOW_REFERRALS_SETTING), FOLLOW_REFERRALS)
|
|
|
- .build();
|
|
|
-
|
|
|
- RealmConfig config = configureRealm("ad-as-ldap-test", LdapRealmSettings.LDAP_TYPE, settings);
|
|
|
+ final boolean ignoreReferralErrors = false;
|
|
|
+ final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("ad", "ad-as-ldap-test");
|
|
|
+ Settings settings = LdapTestCase.buildLdapSettings(realmId,
|
|
|
+ new String[]{AD_LDAP_URL},
|
|
|
+ new String[]{userTemplate},
|
|
|
+ groupSearchBase,
|
|
|
+ LdapSearchScope.SUB_TREE,
|
|
|
+ null,
|
|
|
+ ignoreReferralErrors);
|
|
|
+ final Settings.Builder builder = Settings.builder().put(settings).put(globalSettings);
|
|
|
+ builder.putList(RealmSettings.realmSslPrefix(realmId) + "certificate_authorities", certificatePaths);
|
|
|
+ settings = builder.build();
|
|
|
+ RealmConfig config = new RealmConfig(realmId,
|
|
|
+ settings, TestEnvironment.newEnvironment(globalSettings),
|
|
|
+ new ThreadContext(globalSettings));
|
|
|
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
|
|
|
|
|
String user = "Bruce Banner";
|
|
|
@@ -323,16 +335,12 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
|
|
|
public void testStandardLdapWithAttributeGroups() throws Exception {
|
|
|
String userTemplate = "CN={0},CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com";
|
|
|
- String groupSearchBase = "DC=ad,DC=test,DC=elasticsearch,DC=com";
|
|
|
- final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier(LdapRealmSettings.LDAP_TYPE, "ad-as-ldap-test");
|
|
|
- Settings settings = Settings.builder()
|
|
|
- .put(LdapTestCase.buildLdapSettings(realmId, new String[]{AD_LDAP_URL}, new String[]{userTemplate}, groupSearchBase,
|
|
|
- LdapSearchScope.SUB_TREE, null, false))
|
|
|
+ Settings settings = LdapTestCase.buildLdapSettings(new String[]{AD_LDAP_URL}, userTemplate, false);
|
|
|
+ settings = Settings.builder()
|
|
|
+ .put(settings)
|
|
|
.putList("ssl.certificate_authorities", certificatePaths)
|
|
|
- .putList(RealmSettings.realmSslPrefix(realmId) + "certificate_authorities", certificatePaths)
|
|
|
- .put(getFullSettingKey(realmId, SessionFactorySettings.FOLLOW_REFERRALS_SETTING), FOLLOW_REFERRALS)
|
|
|
.build();
|
|
|
- RealmConfig config = configureRealm("ad-as-ldap-test", LdapRealmSettings.LDAP_TYPE, settings);
|
|
|
+ RealmConfig config = configureRealm("ad-as-ldap-test", settings);
|
|
|
LdapSessionFactory sessionFactory = new LdapSessionFactory(config, sslService, threadPool);
|
|
|
|
|
|
String user = "Bruce Banner";
|
|
|
@@ -349,7 +357,7 @@ public class ActiveDirectorySessionFactoryTests extends AbstractActiveDirectoryT
|
|
|
}
|
|
|
|
|
|
public void testADLookup() throws Exception {
|
|
|
- RealmConfig config = configureRealm("ad-test", LdapRealmSettings.AD_TYPE, buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false, true));
|
|
|
+ RealmConfig config = configureRealm("ad-test", buildAdSettings(AD_LDAP_URL, AD_DOMAIN, false, true));
|
|
|
try (ActiveDirectorySessionFactory sessionFactory = getActiveDirectorySessionFactory(config, sslService, threadPool)) {
|
|
|
|
|
|
List<String> users = randomSubsetOf(Arrays.asList("cap", "hawkeye", "hulk", "ironman", "thor", "blackwidow",
|