yuqi1129 commented on code in PR #4651:
URL: https://github.com/apache/gravitino/pull/4651#discussion_r1730555588
##########
core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java:
##########
@@ -181,53 +182,59 @@ public CatalogOperations ops() {
public AuthorizationPlugin getAuthorizationPlugin() {
if (authorization == null) {
- synchronized (this) {
- if (authorization == null) {
- BaseAuthorization<?> baseAuthorization =
createAuthorizationPluginInstance();
- if (baseAuthorization == null) {
- return null;
- }
- authorization = baseAuthorization;
- }
- }
+ return null;
}
return authorization.plugin(provider(), this.conf);
}
- private BaseAuthorization<?> createAuthorizationPluginInstance() {
+ public void initAuthorizationPluginInstance(IsolatedClassLoader classLoader)
{
+ if (authorization != null) {
+ return;
+ }
+
String authorizationProvider =
catalogPropertiesMetadata().containsProperty(AUTHORIZATION_PROVIDER)
? (String) catalogPropertiesMetadata().getOrDefault(conf,
AUTHORIZATION_PROVIDER)
: null;
if (authorizationProvider == null) {
LOG.info("Authorization provider is not set!");
- return null;
+ return;
}
- ServiceLoader<AuthorizationProvider> loader =
- ServiceLoader.load(
- AuthorizationProvider.class,
Thread.currentThread().getContextClassLoader());
-
- List<Class<? extends AuthorizationProvider>> providers =
- Streams.stream(loader.iterator())
- .filter(p -> p.shortName().equalsIgnoreCase(authorizationProvider))
- .map(AuthorizationProvider::getClass)
- .collect(Collectors.toList());
- if (providers.isEmpty()) {
- throw new IllegalArgumentException(
- "No authorization provider found for: " + authorizationProvider);
- } else if (providers.size() > 1) {
- throw new IllegalArgumentException(
- "Multiple authorization providers found for: " +
authorizationProvider);
- }
+ BaseAuthorization<?> baseAuthorization;
try {
- return (BaseAuthorization<?>)
-
Iterables.getOnlyElement(providers).getDeclaredConstructor().newInstance();
+ baseAuthorization =
Review Comment:
Why not assign it directly to authorization?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]