hdygxsj commented on code in PR #7258:
URL: https://github.com/apache/gravitino/pull/7258#discussion_r2115227643


##########
server/src/main/java/org/apache/gravitino/server/web/filter/GravitinoInterceptionService.java:
##########
@@ -66,7 +81,89 @@ private static class MetadataAuthorizationMethodInterceptor 
implements MethodInt
      */
     @Override
     public Object invoke(MethodInvocation methodInvocation) throws Throwable {
-      throw new UnsupportedOperationException();
+      Method method = methodInvocation.getMethod();
+      Parameter[] parameters = method.getParameters();
+      AuthorizationExpression expressionAnnotation =
+          method.getAnnotation(AuthorizationExpression.class);
+      if (expressionAnnotation != null) {
+        String expression = expressionAnnotation.expression();
+        Object[] args = methodInvocation.getArguments();
+        Map<MetadataObject.Type, NameIdentifier> metadataContext =
+            getMetadataContext(parameters, args);
+        AuthorizationExpressionEvaluator authorizationExpressionEvaluator =
+            new AuthorizationExpressionEvaluator(expression);
+        boolean authorizeResult = 
authorizationExpressionEvaluator.evaluate(metadataContext);
+        if (!authorizeResult) {
+          return Utils.internalError("Can not access metadata.");
+        }
+      }
+      return methodInvocation.proceed();
+    }
+
+    private Map<MetadataObject.Type, NameIdentifier> getMetadataContext(

Review Comment:
   This method is used to extract metadata at all levels from the parameters 
and is only intended for use within interceptors. The splitMetadataNames 
function is used to split a complete NameIdentifier into all of its 
parent-level metadata components.



-- 
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]

Reply via email to