Skip to content

Commit 4b53bb6

Browse files
committed
Add interface and models for synchronizing ACL policies
1 parent 4953195 commit 4b53bb6

15 files changed

+888
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
import java.time.Instant;
22+
import java.util.Collections;
23+
import java.util.Map;
24+
25+
import lombok.Builder;
26+
import lombok.Value;
27+
28+
/** A snapshot of all access control data at a given point in time. */
29+
@Value
30+
@Builder
31+
public class InternalAccessControlPolicySnapshot {
32+
/**
33+
* A unique identifier representing this snapshot's version.
34+
*
35+
* <p>This could be a UUID, timestamp string, or any value that guarantees uniqueness across
36+
* snapshots.
37+
*/
38+
String versionId;
39+
40+
/**
41+
* The moment in time when this snapshot was created.
42+
*
43+
* <p>Useful for maintaining an audit trail or comparing how policies have changed over time.
44+
*/
45+
Instant timestamp;
46+
47+
/**
48+
* A map of user names to {@link InternalUser} objects, capturing individual users' details such
49+
* as assigned roles, auditing metadata, etc.
50+
*/
51+
@Builder.Default Map<String, InternalUser> usersByName = Collections.emptyMap();
52+
53+
/**
54+
* A map of group names to {@link InternalUserGroup} objects, representing logical groupings of
55+
* users for easier role management.
56+
*/
57+
@Builder.Default Map<String, InternalUserGroup> groupsByName = Collections.emptyMap();
58+
59+
/**
60+
* A map of role names to {@link InternalRole} objects, defining the privileges and security rules
61+
* each role entails.
62+
*/
63+
@Builder.Default Map<String, InternalRole> rolesByName = Collections.emptyMap();
64+
65+
/**
66+
* A map of additional properties or metadata related to this snapshot. This map provides
67+
* flexibility for storing information without modifying the main schema of the snapshot.
68+
*/
69+
@Builder.Default Map<String, String> properties = Collections.emptyMap();
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
import java.time.Instant;
22+
23+
import lombok.Builder;
24+
import lombok.Value;
25+
26+
/**
27+
* Contains change-log information for roles, users, or user groups, enabling traceability of who
28+
* created or last modified them.
29+
*
30+
* <p>This class is useful for governance and compliance scenarios, where an audit trail is
31+
* necessary. It can be extended to include additional fields such as reasonForChange or
32+
* changeDescription.
33+
*/
34+
@Value
35+
@Builder
36+
public class InternalChangeLogInfo {
37+
/** The username or identifier of the entity that created this record. */
38+
String createdBy;
39+
40+
/** The username or identifier of the entity that last modified this record. */
41+
String lastModifiedBy;
42+
43+
/** The timestamp when this record was created. */
44+
Instant createdAt;
45+
46+
/** The timestamp when this record was last modified. */
47+
Instant lastModifiedAt;
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
import lombok.Builder;
22+
import lombok.Value;
23+
24+
/**
25+
* Represents a single privilege assignment for a securable object.
26+
*
27+
* <p>This defines the kind of operation (e.g., SELECT, CREATE, MODIFY) and whether it is allowed or
28+
* denied. Some catalogs may only accept ALLOW rules and treat all other operations as denied by
29+
* default.
30+
*/
31+
@Value
32+
@Builder
33+
public class InternalPrivilege {
34+
/**
35+
* The type of privilege, such as SELECT, CREATE, or MODIFY. Each implementation can define its
36+
* own set of enums.
37+
*/
38+
InternalPrivilegeType privilegeType;
39+
40+
/**
41+
* The decision, typically ALLOW or DENY. Some catalogs may not support DENY explicitly,
42+
* defaulting to ALLOW.
43+
*/
44+
String privilegeDecision;
45+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
import java.util.List;
22+
import java.util.Map;
23+
24+
import lombok.Builder;
25+
import lombok.Value;
26+
27+
/**
28+
* Represents a role within the catalog.
29+
*
30+
* <p>A role can be granted access to multiple securable objects, each with its own set of
31+
* privileges. Audit info is stored to track the role's creation and modifications, and a properties
32+
* map can hold additional metadata.
33+
*/
34+
@Value
35+
@Builder
36+
public class InternalRole {
37+
/** The unique name or identifier for the role. */
38+
String name;
39+
40+
/** The list of securable objects this role can access. */
41+
List<InternalSecurableObject> securableObjects;
42+
43+
/** Contains information about how and when this role was created and last modified. */
44+
InternalChangeLogInfo changeLogInfo;
45+
46+
/**
47+
* A map to store additional metadata or properties related to this role. For example, this might
48+
* include a description, usage instructions, or any catalog-specific fields.
49+
*/
50+
Map<String, String> properties;
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
import java.util.List;
22+
23+
import lombok.Builder;
24+
import lombok.Value;
25+
26+
/**
27+
* Represents a securable object in the catalog, which can be managed by access control.
28+
*
29+
* <p>Examples of securable objects include catalogs, schemas, tables, views, or any other data
30+
* objects that require fine-grained privilege management. Each securable object can have one or
31+
* more privileges assigned to it.
32+
*/
33+
@Value
34+
@Builder
35+
public class InternalSecurableObject {
36+
/** The identifier of the securable object. */
37+
InternalSecurableObjectIdentifier securableObjectIdentifier;
38+
/**
39+
* The type of securable object, such as TABLE, VIEW, FUNCTION, etc. Each implementation can
40+
* define its own set of enums.
41+
*/
42+
InternalSecurableObjectType securableObjectType;
43+
/** The set of privileges assigned to this object. */
44+
List<InternalPrivilege> privileges;
45+
}
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+
}

0 commit comments

Comments
 (0)