Skip to content

Commit 563a7fa

Browse files
committed
Refactor interface and models for PolicySync
1 parent a34a0e4 commit 563a7fa

File tree

6 files changed

+171
-6
lines changed

6 files changed

+171
-6
lines changed

xtable-api/src/main/java/org/apache/xtable/model/catalog/policy/InternalAccessControlPolicySnapshot.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.xtable.model.catalog.policy;
2020

2121
import java.time.Instant;
22+
import java.util.Collections;
2223
import java.util.Map;
2324

2425
import lombok.Builder;
@@ -47,23 +48,23 @@ public class InternalAccessControlPolicySnapshot {
4748
* A map of user names to {@link InternalUser} objects, capturing individual users' details such
4849
* as assigned roles, auditing metadata, etc.
4950
*/
50-
Map<String, InternalUser> usersByName;
51+
@Builder.Default Map<String, InternalUser> usersByName = Collections.emptyMap();
5152

5253
/**
5354
* A map of group names to {@link InternalUserGroup} objects, representing logical groupings of
5455
* users for easier role management.
5556
*/
56-
Map<String, InternalUserGroup> groupsByName;
57+
@Builder.Default Map<String, InternalUserGroup> groupsByName = Collections.emptyMap();
5758

5859
/**
5960
* A map of role names to {@link InternalRole} objects, defining the privileges and security rules
6061
* each role entails.
6162
*/
62-
Map<String, InternalRole> rolesByName;
63+
@Builder.Default Map<String, InternalRole> rolesByName = Collections.emptyMap();
6364

6465
/**
6566
* A map of additional properties or metadata related to this snapshot. This map provides
6667
* flexibility for storing information without modifying the main schema of the snapshot.
6768
*/
68-
Map<String, String> properties;
69+
@Builder.Default Map<String, String> properties = Collections.emptyMap();
6970
}

xtable-api/src/main/java/org/apache/xtable/model/catalog/policy/InternalPrivilege.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class InternalPrivilege {
3535
* The type of privilege, such as SELECT, CREATE, or MODIFY. Each implementation can define its
3636
* own set of enums.
3737
*/
38-
String privilegeType;
38+
InternalPrivilegeType privilegeType;
3939

4040
/**
4141
* The decision, typically ALLOW or DENY. Some catalogs may not support DENY explicitly,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.xtable.model.catalog.policy;
20+
21+
/**
22+
* Specifies a set of privileges that can be granted or revoked for securable objects.
23+
*
24+
* <p>This enum is used to indicate the type of actions that a subject (user, role, group) is
25+
* allowed to perform on a given resource, such as a catalog, database, table, or other securable
26+
* entity.
27+
*/
28+
public enum InternalPrivilegeType {
29+
30+
/** Grants all available privileges on the resource. */
31+
ALL,
32+
33+
/**
34+
* Allows modification of the structure or metadata of the resource. For example, modifying
35+
* schemas or properties.
36+
*/
37+
ALTER,
38+
39+
/**
40+
* Allows describing or viewing the metadata of the resource. Typically applies to viewing schemas
41+
* or properties of the resource.
42+
*/
43+
DESCRIBE,
44+
45+
/**
46+
* Allows reading or selecting data from the resource. Commonly associated with performing SQL
47+
* SELECT statements.
48+
*/
49+
SELECT,
50+
51+
/**
52+
* Allows inserting new data into the resource. Typically granted for operations like SQL INSERT
53+
* statements.
54+
*/
55+
INSERT,
56+
57+
/**
58+
* Allows updating existing data within the resource. Typically granted for operations like SQL
59+
* UPDATE statements.
60+
*/
61+
UPDATE,
62+
63+
/** Allows creating new resources within the catalog. */
64+
CREATE,
65+
66+
/** Allows deleting or dropping a resource, such as a database or a table. */
67+
DROP,
68+
69+
/** Allows removing data from the resource, for example using SQL DELETE statements. */
70+
DELETE
71+
}

xtable-api/src/main/java/org/apache/xtable/model/catalog/policy/InternalSecurableObject.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
@Value
3434
@Builder
3535
public class InternalSecurableObject {
36+
/** The identifier of the securable object. */
37+
InternalSecurableObjectIdentifier securableObjectIdentifier;
3638
/**
3739
* The type of securable object, such as TABLE, VIEW, FUNCTION, etc. Each implementation can
3840
* define its own set of enums.
3941
*/
40-
String securableObjectType;
42+
InternalSecurableObjectType securableObjectType;
4143
/** The set of privileges assigned to this object. */
4244
List<InternalPrivilege> privileges;
4345
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.xtable.model.catalog.policy;
20+
21+
/**
22+
* Defines a structure for obtaining a unique, canonical identifier for a securable object within
23+
* the catalog.
24+
*
25+
* <p>Implementations of this interface may represent entities such as catalogs, databases, tables,
26+
* or any other resource that can be protected or controlled via security policies.
27+
*/
28+
public interface InternalSecurableObjectIdentifier {
29+
30+
/**
31+
* Returns the unique identifier of the securable object in a canonical form.
32+
*
33+
* @return a non-null {@link String} representing the unique identifier of this securable object
34+
*/
35+
String getId();
36+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.xtable.model.catalog.policy;
20+
21+
/**
22+
* Identifies the type of securable object within the catalog.
23+
*
24+
* <p>Each attribute in this enum represents a different kind of resource for which permissions may
25+
* be managed or enforced.
26+
*/
27+
public enum InternalSecurableObjectType {
28+
29+
/** Represents the root container in which databases and other objects reside. */
30+
CATALOG,
31+
32+
/** Represents a logical grouping of tables and other related objects. */
33+
DATABASE,
34+
35+
/** Represents a table, typically containing rows and columns of data. */
36+
TABLE,
37+
38+
/** Represents a view, which is often a virtual table defined by a query. */
39+
VIEW,
40+
41+
/**
42+
* Represents a partition, commonly used to segment table data for performance or organizational
43+
* reasons.
44+
*/
45+
PARTITION,
46+
47+
/** Represents a column, generally a single field within a table or partition. */
48+
COLUMN,
49+
50+
/** Represents a function, such as a user-defined function (UDF) within the database system. */
51+
FUNCTION,
52+
53+
/** Represents an unsupported object type for error handling. */
54+
UNSUPPORTED
55+
}

0 commit comments

Comments
 (0)