-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exception metadata for disabled features (#52811)
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: #52311, #47759
- Loading branch information
Showing
5 changed files
with
80 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ty/src/main/java/org/elasticsearch/xpack/security/support/FeatureNotEnabledException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.security.support; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.rest.RestStatus; | ||
|
||
public class FeatureNotEnabledException extends ElasticsearchException { | ||
|
||
public static final String DISABLED_FEATURE_METADATA = "es.disabled.feature"; | ||
|
||
/** | ||
* The features names here are constants that form part of our API contract. | ||
* Callers (e.g. Kibana) may be dependent on these strings. Do not change them without consideration of BWC. | ||
*/ | ||
public enum Feature { | ||
TOKEN_SERVICE("security_tokens"), | ||
API_KEY_SERVICE("api_keys"); | ||
|
||
private final String featureName; | ||
|
||
Feature(String featureName) { | ||
this.featureName = featureName; | ||
} | ||
} | ||
|
||
public FeatureNotEnabledException(Feature feature, String message, Object... args) { | ||
super(message, args); | ||
addMetadata(DISABLED_FEATURE_METADATA, feature.featureName); | ||
} | ||
|
||
@Override | ||
public RestStatus status() { | ||
return RestStatus.BAD_REQUEST; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters