[
https://issues.apache.org/jira/browse/SLING-2708?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13551357#comment-13551357
]
Tyson Norris commented on SLING-2708:
-------------------------------------
How about making it more clean in ResourceUtil that type testing needs special
handling?
Some new methods:
{code}
public static Resource decorateForTypeTesting(final Resource resource,
final ResourceResolver resolver){
return new ResourceWrapper(resource) {
@Override
public boolean isResourceType(final String type) {
return ResourceUtil.isA(new AbstractResource() {
public String getResourceType() {
return resource.getResourceType();
}
public String getResourceSuperType() {
return resource.getResourceSuperType();
}
public ResourceResolver getResourceResolver() {
return resolver;
}
public ResourceMetadata getResourceMetadata() {
return resource.getResourceMetadata();
}
public String getPath() {
return resource.getPath();
}
}, type);
}
};
}
public static boolean isA(final Resource resource, final ResourceResolver
resolver, final String resourceType) {
if (resource == null || resourceType == null) {
return false;
}
return decorateForTypeTesting(resource,
resolver).isResourceType(resourceType);
}
{code}
The decorateForTypeTesting() method could be used within
SlingServletResolver.decorate()
> 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
>
> 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