For question #1, I figured it out. However, I notice that ServiceUserMapper
defaults to the bundle mapping if the mapping for the more specific subservice
doesn’t exist in the mappings. It may be expected behavior but I don’t see
anything in JavaDoc (ServiceUserMapper or in ResourceResolverFactory).
In my code, I’m asking for a more specific service based on subservice which
isn’t defined in the mappings and instead I get back the mapping for the more
general bundle mapping which is defined in the mappings.
If I use the optional authentication info like:
Map<String, Object> props = new HashMap<String,Object>();
props.put(ResourceResolverFactory.SUBSERVICE,
this.getClass().getName());
resolver =
resourceResolverFactory.getServiceResourceResolver(props);
If I have a mapping in Service User Mapper Service:
astra-utility:com.astracorp.foundation.utility.services.impl.DatastoreGCServiceImpl=admin
It works as expected.
If I have the mapping:
astra-utility:test=admin
It fails as expected with InvalidAuthorizableName.
If I have the mapping:
astra-utility=admin
It works. Is this expected? I can see arguments for returning the general
mapping just as strong as arguments for returning null.
Robert A. Decker
[email protected]
http://robdecker.com/about
On 15 May 2014, at 17:54, Robert A. Decker <[email protected]> wrote:
> Hello,
>
> I’m successfully using ServiceUserMapper but I’m not sure if I’m using it
> quite right.
>
> I have a bundle, "astra-utility" and in it a service “DatastoreGCService".
>
> In my configurations, in "Apache Sling Service User Mapper Service", I have a
> user.mapping of "astra-utility=admin”
>
> In my code I have:
> ResourceResolver rr =
> resourceResolverFactory.getServiceResourceResolver(null);
>
> This all works - I’m able to get the ResourceResolver. However, here are my
> questions:
>
>
> 1) How do I define a subservice-name for my service? I would like the
> user.mapping to be “astra-utility:DatastoreGCService=admin”.
>
> 2) Is it possible to add user.mappings to the user mapper service with
> sling-initial-content from multiple bundles without each bundle interfering
> with the other bundles' mappings? If two bundles define that configuration
> will the default be the last bundle installed?
>
> I don’t think that I can do it programmatically - ServiceUserMapper only
> exposes one method, getServiceUserID.
>
> If #2 isn’t possible, then should I create a service in a foundation bundle
> that all of my projects use that provides a resourceResolver based on a
> passed in user name? This would mean though that I’m using the
> ServiceUserMapper in a way that I don’t think it was intended for - more
> user-centric than service-centric.
>
> Robert A. Decker
> [email protected]
> http://robdecker.com/about
>
>
>