Package dev.openfga
Class OpenFga
java.lang.Object
dev.openfga.OpenFga
A bean that can be used to perform common FGA tasks, such as execute a check request.
Can be used in
@PreAuthorize or PostAuthorize to provide method-level FGA
protection for a requested resource. For example:
@PreAuthorize("@openFga.check('document', #id, 'reader', 'user', 'authentication?.name')")
public Document getDocument(String id) {
repository.findById(id);
}
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
OpenFga
public OpenFga(dev.openfga.sdk.api.client.OpenFgaClient fgaClient)
-
-
Method Details
-
check
Perform an FGA check. Returnstrueif the user has the specified relationship with the object,falseotherwise. The user ID will be obtained from the authentication name in theSecurityContext- Parameters:
objectType- The object type of the checkobjectId- The ID of the object to checkrelation- The required relation between the user and the objectuserType- The type of the user- Returns:
- true if the user has the required relation to the object, false otherwise
- See Also:
-
check
public boolean check(String objectType, String objectId, String relation, String userType, String userId) Perform an FGA check. Returnstrueif the user has the specified relationship with the object,falseotherwise. The user ID will be obtained from the authentication name in theSecurityContext- Parameters:
objectType- The object type of the checkobjectId- The ID of the object to checkrelation- The required relation between the user and the objectuserType- The type of the useruserId- The ID of the user- Returns:
- true if the user has the required relation to the object, false otherwise
- See Also:
-