Automatically insert authenticator/authorizer names into config properties (#5071)

This commit is contained in:
Jonathan Wei 2017-11-13 13:12:31 -08:00 committed by Gian Merlino
parent 1c64f02574
commit 819700cbc5
3 changed files with 29 additions and 2 deletions

View File

@ -100,3 +100,15 @@ Authenticators must implement three methods related to the internal system user:
`createEscalatedJettyClient` is similar to `createEscalatedClient`, except that it operates on a Jetty HttpClient.
`createEscalatedAuthenticationResult` returns an AuthenticationResult containing the identity of the "internal system user".
## Reserved Name Configuration Property
For extension implementers, please note that the following configuration properties are reserved for the names of Authenticators and Authorizers:
```
druid.auth.authenticator.<authenticator-name>.name=<authenticator-name>
druid.auth.authorizer.<authorizer-name>.name=<authorizer-name>
```
These properties provide the authenticator and authorizer names to the implementations as @JsonProperty parameters, potentially useful when multiple authenticators or authorizers of the same type are configured.

View File

@ -108,7 +108,14 @@ public class AuthenticatorMapperModule implements DruidModule
Authenticator.class
);
authenticatorProvider.inject(props, configurator);
String nameProperty = StringUtils.format("druid.auth.authenticator.%s.name", authenticatorName);
Properties adjustedProps = new Properties(props);
if (adjustedProps.containsKey(nameProperty)) {
throw new IAE("Name property [%s] is reserved.", nameProperty);
} else {
adjustedProps.put(nameProperty, authenticatorName);
}
authenticatorProvider.inject(adjustedProps, configurator);
Supplier<Authenticator> authenticatorSupplier = authenticatorProvider.get();
if (authenticatorSupplier == null) {

View File

@ -111,7 +111,15 @@ public class AuthorizerMapperModule implements DruidModule
Authorizer.class
);
authorizerProvider.inject(props, configurator);
String nameProperty = StringUtils.format("druid.auth.authorizer.%s.name", authorizerName);
Properties adjustedProps = new Properties(props);
if (adjustedProps.containsKey(nameProperty)) {
throw new IAE("Name property [%s] is reserved.", nameProperty);
} else {
adjustedProps.put(nameProperty, authorizerName);
}
authorizerProvider.inject(adjustedProps, configurator);
Supplier<Authorizer> authorizerSupplier = authorizerProvider.get();
if (authorizerSupplier == null) {