|
@@ -11,6 +11,7 @@ import org.elasticsearch.common.settings.SecureString;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
|
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
|
|
+import org.elasticsearch.env.Environment;
|
|
|
import org.elasticsearch.env.TestEnvironment;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.test.SecuritySettingsSourceField;
|
|
@@ -62,7 +63,7 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testSettings() throws Exception {
|
|
|
+ public void testCacheSettings() throws Exception {
|
|
|
String cachingHashAlgo = Hasher.values()[randomIntBetween(0, Hasher.values().length - 1)].name().toLowerCase(Locale.ROOT);
|
|
|
int maxUsers = randomIntBetween(10, 100);
|
|
|
TimeValue ttl = TimeValue.timeValueMinutes(randomIntBetween(10, 20));
|
|
@@ -560,6 +561,33 @@ public class CachingUsernamePasswordRealmTests extends ESTestCase {
|
|
|
assertEquals(1, lookupCounter.get());
|
|
|
}
|
|
|
|
|
|
+ public void testAuthenticateDisabled() throws Exception {
|
|
|
+ final Settings settings = Settings.builder()
|
|
|
+ .put(CachingUsernamePasswordRealmSettings.AUTHC_ENABLED_SETTING.getKey(), false)
|
|
|
+ .build();
|
|
|
+ final Environment env = TestEnvironment.newEnvironment(globalSettings);
|
|
|
+ final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
|
|
+ final RealmConfig config = new RealmConfig("test_authentication_disabled", settings, globalSettings, env, threadContext);
|
|
|
+ final AlwaysAuthenticateCachingRealm realm = new AlwaysAuthenticateCachingRealm(config, threadPool);
|
|
|
+
|
|
|
+ final UsernamePasswordToken token = new UsernamePasswordToken("phil", new SecureString("tahiti"));
|
|
|
+ UsernamePasswordToken.putTokenHeader(threadContext, token);
|
|
|
+ assertThat(realm.token(threadContext), nullValue());
|
|
|
+ assertThat(realm.supports(token), equalTo(false));
|
|
|
+
|
|
|
+ PlainActionFuture<AuthenticationResult> authFuture = new PlainActionFuture<>();
|
|
|
+ realm.authenticate(token, authFuture);
|
|
|
+ final AuthenticationResult authResult = authFuture.get();
|
|
|
+ assertThat(authResult.isAuthenticated(), equalTo(false));
|
|
|
+ assertThat(authResult.getStatus(), equalTo(AuthenticationResult.Status.CONTINUE));
|
|
|
+
|
|
|
+ PlainActionFuture<User> lookupFuture = new PlainActionFuture<>();
|
|
|
+ realm.lookupUser(token.principal(), lookupFuture);
|
|
|
+ final User user = lookupFuture.get();
|
|
|
+ assertThat(user, notNullValue());
|
|
|
+ assertThat(user.principal(), equalTo(token.principal()));
|
|
|
+ }
|
|
|
+
|
|
|
static class FailingAuthenticationRealm extends CachingUsernamePasswordRealm {
|
|
|
|
|
|
FailingAuthenticationRealm(Settings settings, Settings global, ThreadPool threadPool) {
|