Running custom code without access control
Using the AuthorizationContext.runWithoutAuthorization method
AuthorizationContext.runWithoutAuthorization methodclass SomeDocumentService(
private val documentService: JsonSchemaDocumentService,
private val authorizationService: AuthorizationService
) {
fun updateName(name: String, documentId: String) {
// We wrap authorized code in a runWithoutAuthorization call to prevent access control checks
val document = runWithoutAuthorization {
// calling this method would normally require the JsonSchemaDocument VIEW permission
documentService.get(documentId)
}
// update the document
...
// Do a permission check to protect this method from unauthorized access
// In this case we're checking for the custom JsonSchemaDocument UPDATE-NAME permission
authorizationService.requirePermission(
EntityAuthorizationRequest(
JsonSchemaDocument::class.java,
Action("UPDATE-NAME"),
document
)
)
}
}Using the @RunWithoutAuthorization annotation
@RunWithoutAuthorization annotationLast updated