Access denied for the instance of entity "pay element"

Hello Team,

I am facing this access denied error when i try removing a pay element from a group table reading it’s data from a custom data source extending CustomGroupDatasource, note that i have identified the source of the problem as the custom data source, when i remove the custom data source, remove operation works fine, my data source code is below:

public class PayElementDatasource extends CustomGroupDatasource<PayElement, UUID> {

    @Override
    protected Collection<PayElement> getEntities(Map<String, Object> params) {
        PayElementService payElementService = AppBeans.get(PayElementService.class);

        if(params.containsKey("employeesGroup")) {
            return payElementService.getAllPayElements((EmployeesGroup) params.get("employeesGroup"));
        }
        else{
            return null;
        }
    }
}

not sure it’s a bug in the custom data source or i am missing something.

Hi Tarek,

Could you post the exception stack trace?

Hi Konstantin,

please find the stack below:

2018-07-31 22:05:54.614 ERROR [http-nio-8080-exec-27/app-core/admin] com.haulmont.cuba.core.sys.ServiceInterceptor - Exception in DataService.commit(..): com.haulmont.cuba.core.global.RowLevelSecurityException: Could not read security token from entity com.company.vp.entity.PayElement-12ad43a2-2c53-604c-4d17-2e825c7e2b2a [detached], even though there are active attribute access for the entity.
2018-07-31 22:05:54.750 ERROR [http-nio-8080-exec-27/app/admin] com.haulmont.cuba.web.log.AppLog - Exception in com.haulmont.cuba.web.toolkit.ui.CubaButton: com.haulmont.cuba.core.global.RowLevelSecurityException: Could not read security token from entity com.company.vp.entity.PayElement-12ad43a2-2c53-604c-4d17-2e825c7e2b2a [detached], even though there are active attribute access for the entity.

I have managed to work around this issue by calling a middleware service that calls persistence.getEntityManager().remove(payElement)

This exception is thrown if you set up Entity Attribute Access Control for the entity and trying to save instance which has no __securityState field value. Normally, this field is set by the framework when the entity is loaded.