-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport to branch(3) : Add admin interface and operation attributes …
…things for Attribute-Based Access Control (#2441) Co-authored-by: Toshihiro Suzuki <[email protected]>
- Loading branch information
1 parent
87e3747
commit 3fd8bb7
Showing
17 changed files
with
2,082 additions
and
105 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
core/src/main/java/com/scalar/db/api/AbacOperationAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.scalar.db.api; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** A utility class to manipulate the operation attributes for attribute-based access control. */ | ||
public final class AbacOperationAttributes { | ||
|
||
private static final String OPERATION_ATTRIBUTE_PREFIX = "abac-"; | ||
public static final String READ_TAG_PREFIX = OPERATION_ATTRIBUTE_PREFIX + "read-tag-"; | ||
public static final String WRITE_TAG_PREFIX = OPERATION_ATTRIBUTE_PREFIX + "write-tag-"; | ||
|
||
private AbacOperationAttributes() {} | ||
|
||
public static void setReadTag(Map<String, String> attributes, String policyName, String readTag) { | ||
attributes.put(READ_TAG_PREFIX + policyName, readTag); | ||
} | ||
|
||
public static void clearReadTag(Map<String, String> attributes, String policyName) { | ||
attributes.remove(READ_TAG_PREFIX + policyName); | ||
} | ||
|
||
public static void clearReadTags(Map<String, String> attributes) { | ||
attributes.entrySet().removeIf(e -> e.getKey().startsWith(READ_TAG_PREFIX)); | ||
} | ||
|
||
public static void setWriteTag( | ||
Map<String, String> attributes, String policyName, String writeTag) { | ||
attributes.put(WRITE_TAG_PREFIX + policyName, writeTag); | ||
} | ||
|
||
public static void clearWriteTag(Map<String, String> attributes, String policyName) { | ||
attributes.remove(WRITE_TAG_PREFIX + policyName); | ||
} | ||
|
||
public static void clearWriteTags(Map<String, String> attributes) { | ||
attributes.entrySet().removeIf(e -> e.getKey().startsWith(WRITE_TAG_PREFIX)); | ||
} | ||
|
||
public static Optional<String> getReadTag(Operation operation, String policyName) { | ||
return operation.getAttribute(READ_TAG_PREFIX + policyName); | ||
} | ||
|
||
public static Optional<String> getWriteTag(Operation operation, String policyName) { | ||
return operation.getAttribute(WRITE_TAG_PREFIX + policyName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.