I have a Managed Package where I have Custom Object called Transaction and Apex Rest Resource for creating this object.
The Resource Code:
@RestResource(urlMapping='/v1/transaction/*')
global with sharing class TransactionRestResource{
@HttpPost
global static void createTransaction() {
Transaction__c tran = new Transaction__c();
// mapping some fields
insert tran;
}
}
And I have Apex Method which calls this API from my Dev Org
Code:
public class TransactionRestResource{
@AuraEnabled
public static void createTransactionRecord(String json){
System.RestContext.request = new RestRequest();
RestContext.request.requestURI = '/v1/transaction/';
RestContext.request.requestBody = Blob.valueOf(json);
PackageName.TransactionRestResource.createTransaction();
}
}
And I call this method on button click from the simplest LWC in DEV org.
----- The Problem: ------
If a user does NOT have create access to Transaction__c
object, and presses the button the record is created without any errors. And this user marked as Created By.
From my understanding:
When we use with sharing
keyword it should run in a user mode and throw an error here that a user does not have the access to create record.
I checked Object Permission
records and this user does not have any access to the Custom Object.
I reviewed next docs:
------ Question: -----
So I want to know why it works in this way ?
I don't want a solution, but rather understand the cause of such behavior.
What can cause such behavior ? Is it something from sharing, Rest Resource or Managed Package ?
Any help will be appreciated