acciente / oacc-core

OACC (Object ACcess Control) is an advanced Java Application Security Framework
http://oaccframework.org/
Apache License 2.0
107 stars 23 forks source link

Resources.getInstance(LONG) returns resource, but no externalId #46

Closed WerVbn closed 6 years ago

WerVbn commented 6 years ago

Resource resource = Resources.getInstance(91L); returns the desired resource, but not the externalId of the resource. This happens only, when a long parameter is passed to the method.

resouce.getExternalId() returns null

fspinnenhirn commented 6 years ago

Hello Tesfel,

what you are observing will make sense when you think of the Resource as a really lightweight data transfer object. The only purpose of the Resources.getInstance() methods is to provide a uniform way to tell an OACC access control context which resource(s) you're operating on, instead of overloading each OACC method with long parameters for resource ids and String parameters for external ids.

The getInstance() methods don't perform any lookups to fully resolve a resource with both resourceId and externalId; they just set whatever parameter you specified on the returned resource instance. If you, for example, use the other factory method Resources.getInstance("myExternalId"), you would get a resource instance that only has the externalId set and its resourceId would be null.

The access control context is the one that will actually resolve each Resource instance and lookup the corresponding resource id for a given external id, and vice versa. Any resources you get back from an access control context call will of course also be fully resolved.

Let me know if you have any other questions, Tesfel. Regards, -Fabian