[
https://issues.apache.org/jira/browse/SLING-2708?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Julian Sedding updated SLING-2708:
----------------------------------
Attachment: SLING-2708-using-adaptTo.patch
I have implemented a possible solution based on the adapter functionality, see
attached patch. In a nutshell, the resource can be adapted to an immutable
EffectiveResourceType object, which internally holds a list of all
resource-types in the inheritance chain of the resource.
As Carsten suggested, this functionality is used in AbstractResource via
adaptTo(EffectiveResourceType.class).
This moves the implementation to a dedicated service, like Alex said, namely
the AdapterFactory.
Furthermore, I decided that resource-types are mostly related to script
resolution and it would probably be sensible to (re)use the script-user
configured for the SlingServletResolver. I believe that having a consistent
view on the resource-types and scripts is beneficial. Also, the
ResourceDecorator approach seems to follow the same rationale. In order not to
overload the SlingServletResolver, this functionality mostly resides in the
EffectiveResourceTypeFactory, which is created by the SlingServletResolver.
I'm not sure if the addition of the EffectiveResourceType interface to
o.a.sling.api is desirable, however, adding it to another package would create
a dependency. Maybe the EffectiveResourceType could also be made more useful.
At the moment it is very simple and only solves the "isA" use-case.
> ResourceUtil.isA() fails for adapted Resources unless user is admin
> -------------------------------------------------------------------
>
> Key: SLING-2708
> URL: https://issues.apache.org/jira/browse/SLING-2708
> Project: Sling
> Issue Type: Bug
> Components: ResourceResolver
> Reporter: Tyson Norris
> Attachments: SLING-2708-using-adaptTo.patch
>
>
> Summary - adapting a Resource to a specified type, loses the ability to test
> the Resources super types using ResourceUtil.isA(), UNLESS user is admin
> 1. TypeA is defined as:
> class TypeA {
> private Resource res;
> public boolean isTypeB(){
> return ResourceUtil.isA(res, "some/type");
> }
> }
> 2. TypeA adapter is an AdapterFactory to adapt Resource -> TypeA
> 3. /some/res/path is a resource whose sling:resourceSuperType 2 levels up is
> "/apps/some/type"
> 4. In a JSP, we use code like:
> TypeA typeA = resource.adaptTo(TypeA)
> if (!typeA.isTypeB()){
> //FAIL: typeA.isTypeB() is actually true
> }
> Note that:
> ResourceUtil.isA(resource, "some/type") == true
> but
> ResourceUtil.isA(typeA.resource, "some/type") == false
> (unless user is admin)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira