Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqi1129 committed Dec 25, 2024
1 parent dd58aba commit 67ec16a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*
*/

package org.apache.gravitino.authorization;
package org.apache.gravitino.authorization.common;

import java.util.Map;

/**
* The AuthorizationUserGroupMappingProvider interface defines the public API for mapping Gravitino
* users and groups to the underlying data source.
* users and groups to the that in underlying data source system.
*
* <p>Typically, the users and group names in Gravitino are the same as the underlying data source.
* However, in some cases, the user and group names in Gravitino may be different from the
Expand All @@ -42,14 +42,23 @@ public interface AuthorizationUserGroupMappingProvider {
default void initialize(Map<String, String> config) {}

/**
* Get the username or group name from the underlying data source based on the Gravitino username
* or group name. For instance, in GCP IAM, the username is the email address or the service
* account.
* Get the username from the underlying data source based on the Gravitino username For instance,
* in GCP IAM, the username is the email address or the service account.
*
* @param gravitinoUserGroup The Gravitino username.
* @param gravitinoUserName The Gravitino username.
* @return The username from the underlying data source.
*/
default String getUserGroupMapping(String gravitinoUserGroup) {
return gravitinoUserGroup;
default String getUserName(String gravitinoUserName) {
return gravitinoUserName;
}

/**
* Get the group name from the underlying data source based on the Gravitino group name.
*
* @param gravitinoGroupName The Gravitino group name.
* @return The group name from the underlying data source.
*/
default String getGroupName(String gravitinoGroupName) {
return gravitinoGroupName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public class PathBasedMetadataObject implements AuthorizationMetadataObject {
*/
public enum Type implements AuthorizationMetadataObject.Type {
/** A path is mapped the path of storages like HDFS, S3 etc. */
PATH(MetadataObject.Type.FILESET);
FILESET_PATH(MetadataObject.Type.FILESET),
TABLE_PATH(MetadataObject.Type.TABLE),
SCHEMA_PATH(MetadataObject.Type.SCHEMA),
CATALOG_PATH(MetadataObject.Type.CATALOG);

private final MetadataObject.Type metadataType;

Type(MetadataObject.Type type) {
Expand Down Expand Up @@ -87,7 +91,7 @@ public void validateAuthorizationMetadataObject() throws IllegalArgumentExceptio
type != null, "Cannot create a path based metadata object with no type");

Preconditions.checkArgument(
type == PathBasedMetadataObject.Type.PATH, "it must be the PATH type");
type == PathBasedMetadataObject.Type.FILESET_PATH, "it must be the PATH type");

for (String name : names) {
Preconditions.checkArgument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ public List<AuthorizationSecurableObject> translatePrivilege(SecurableObject sec
if (locationPath != null && !locationPath.isEmpty()) {
PathBasedMetadataObject rangerPathBaseMetadataObject =
new PathBasedMetadataObject(
locationPath, PathBasedMetadataObject.Type.PATH);
locationPath, PathBasedMetadataObject.Type.FILESET_PATH);
rangerSecurableObjects.add(
generateAuthorizationSecurableObject(
rangerPathBaseMetadataObject.names(),
PathBasedMetadataObject.Type.PATH,
PathBasedMetadataObject.Type.FILESET_PATH,
rangerPrivileges));
}
}
Expand All @@ -206,7 +206,7 @@ public List<AuthorizationSecurableObject> translatePrivilege(SecurableObject sec
rangerSecurableObjects.add(
generateAuthorizationSecurableObject(
translateMetadataObject(securableObject).names(),
PathBasedMetadataObject.Type.PATH,
PathBasedMetadataObject.Type.FILESET_PATH,
rangerPrivileges));
break;
default:
Expand Down Expand Up @@ -234,7 +234,7 @@ public List<AuthorizationSecurableObject> translatePrivilege(SecurableObject sec
rangerSecurableObjects.add(
generateAuthorizationSecurableObject(
translateMetadataObject(securableObject).names(),
PathBasedMetadataObject.Type.PATH,
PathBasedMetadataObject.Type.FILESET_PATH,
rangerPrivileges));
break;
default:
Expand Down Expand Up @@ -265,7 +265,7 @@ public List<AuthorizationSecurableObject> translateOwner(MetadataObject gravitin
rangerSecurableObjects.add(
generateAuthorizationSecurableObject(
translateMetadataObject(gravitinoMetadataObject).names(),
PathBasedMetadataObject.Type.PATH,
PathBasedMetadataObject.Type.FILESET_PATH,
ownerMappingRule()));
break;
default:
Expand Down Expand Up @@ -294,17 +294,17 @@ public AuthorizationMetadataObject translateMetadataObject(MetadataObject metada
case METALAKE:
case CATALOG:
rangerPathBaseMetadataObject =
new PathBasedMetadataObject("", PathBasedMetadataObject.Type.PATH);
new PathBasedMetadataObject("", PathBasedMetadataObject.Type.FILESET_PATH);
break;
case SCHEMA:
rangerPathBaseMetadataObject =
new PathBasedMetadataObject(
metadataObject.fullName(), PathBasedMetadataObject.Type.PATH);
metadataObject.fullName(), PathBasedMetadataObject.Type.FILESET_PATH);
break;
case FILESET:
rangerPathBaseMetadataObject =
new PathBasedMetadataObject(
getLocationPath(metadataObject), PathBasedMetadataObject.Type.PATH);
getLocationPath(metadataObject), PathBasedMetadataObject.Type.FILESET_PATH);
break;
default:
throw new AuthorizationPluginException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ public void testTranslateMetadataObject() {
MetadataObject metalake =
MetadataObjects.parse(String.format("metalake1"), MetadataObject.Type.METALAKE);
Assertions.assertEquals(
PathBasedMetadataObject.Type.PATH,
PathBasedMetadataObject.Type.FILESET_PATH,
rangerAuthPlugin.translateMetadataObject(metalake).type());

MetadataObject catalog =
MetadataObjects.parse(String.format("catalog1"), MetadataObject.Type.CATALOG);
Assertions.assertEquals(
PathBasedMetadataObject.Type.PATH,
PathBasedMetadataObject.Type.FILESET_PATH,
rangerAuthPlugin.translateMetadataObject(catalog).type());

MetadataObject schema =
MetadataObjects.parse(String.format("catalog1.schema1"), MetadataObject.Type.SCHEMA);
Assertions.assertEquals(
PathBasedMetadataObject.Type.PATH, rangerAuthPlugin.translateMetadataObject(schema).type());
PathBasedMetadataObject.Type.FILESET_PATH,
rangerAuthPlugin.translateMetadataObject(schema).type());

MetadataObject table =
MetadataObjects.parse(String.format("catalog1.schema1.tab1"), MetadataObject.Type.TABLE);
Expand All @@ -81,7 +82,7 @@ public void testTranslateMetadataObject() {
AuthorizationMetadataObject rangerFileset = rangerAuthPlugin.translateMetadataObject(fileset);
Assertions.assertEquals(1, rangerFileset.names().size());
Assertions.assertEquals("/test", rangerFileset.fullName());
Assertions.assertEquals(PathBasedMetadataObject.Type.PATH, rangerFileset.type());
Assertions.assertEquals(PathBasedMetadataObject.Type.FILESET_PATH, rangerFileset.type());
}

@Test
Expand Down Expand Up @@ -136,7 +137,8 @@ public void testTranslatePrivilege() {

filesetInFileset1.forEach(
securableObject -> {
Assertions.assertEquals(PathBasedMetadataObject.Type.PATH, securableObject.type());
Assertions.assertEquals(
PathBasedMetadataObject.Type.FILESET_PATH, securableObject.type());
Assertions.assertEquals("/test", securableObject.fullName());
Assertions.assertEquals(2, securableObject.privileges().size());
});
Expand Down Expand Up @@ -165,7 +167,7 @@ public void testTranslateOwner() {
List<AuthorizationSecurableObject> filesetOwner = rangerAuthPlugin.translateOwner(fileset);
Assertions.assertEquals(1, filesetOwner.size());
Assertions.assertEquals("/test", filesetOwner.get(0).fullName());
Assertions.assertEquals(PathBasedMetadataObject.Type.PATH, filesetOwner.get(0).type());
Assertions.assertEquals(PathBasedMetadataObject.Type.FILESET_PATH, filesetOwner.get(0).type());
Assertions.assertEquals(3, filesetOwner.get(0).privileges().size());
}
}

This file was deleted.

This file was deleted.

0 comments on commit 67ec16a

Please sign in to comment.