Skip to content

Commit 77bdebe

Browse files
committed
Add exception metadata for disabled features
This change adds a new exception with consistent metadata for when security features are not enabled. This allows clients to be able to tell that an API failed due to a configuration option, and respond accordingly. Relates: kibana#55255 Resolves: elastic#52311
1 parent 7bd9f55 commit 77bdebe

File tree

5 files changed

+309
-238
lines changed

5 files changed

+309
-238
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
import org.elasticsearch.xpack.core.security.authc.support.Hasher;
7070
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
7171
import org.elasticsearch.xpack.core.security.user.User;
72+
import org.elasticsearch.xpack.security.support.FeatureNotEnabledException;
73+
import org.elasticsearch.xpack.security.support.FeatureNotEnabledException.Feature;
7274
import org.elasticsearch.xpack.security.support.SecurityIndexManager;
7375

7476
import javax.crypto.SecretKeyFactory;
@@ -577,7 +579,7 @@ private void ensureEnabled() {
577579
throw LicenseUtils.newComplianceException("api keys");
578580
}
579581
if (enabled == false) {
580-
throw new IllegalStateException("api keys are not enabled");
582+
throw new FeatureNotEnabledException(Feature.API_KEY_SERVICE, "api keys are not enabled");
581583
}
582584
}
583585

0 commit comments

Comments
 (0)