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


##########
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:
   It's a little weird to use `MetadataObject.Type` and `NameIdentifier`.
   Because we usually don't mix entity and metadata object. Is it necessary?



##########
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:
   Do we need to put the method to other places? MetadataFilterHelper has 
similar method `spiltMetadataNames`



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