You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Robert A. Decker" <de...@robdecker.com> on 2014/05/15 17:54:13 UTC

proper way to use ServiceUserMapper?

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
decker@robdecker.com
http://robdecker.com/about



Re: proper way to use ServiceUserMapper?

Posted by Carsten Ziegeler <cz...@apache.org>.
Perfect, thanks - yeah I was missinterpreting this a little bit and thought
its ment that the bundle itself provides the mapping - I think we go with
factory configurations we're fine.

Carsten


2014-05-19 15:20 GMT+02:00 Antonio Sanso <as...@adobe.com>:

> Thanks Carsten,
>
> in any case I have opened https://issues.apache.org/jira/browse/SLING-3578so we can continue the discussion there.
>
> regards
>
> antonio
>
> On May 19, 2014, at 2:27 PM, Carsten Ziegeler <cz...@apache.org>
> wrote:
>
> > I don't think that a bundle by itself should add the mapping - if the
> > bundle simply inserts a mapping to admin you end up in the same situation
> > as before. That's why we went with the central configuraiton so far
> >
> >
> > 2014-05-19 9:47 GMT+02:00 Antonio Sanso <as...@adobe.com>:
> >
> >> hi Robert
> >> On May 15, 2014, at 5:54 PM, Robert A. Decker <de...@robdecker.com>
> >> 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?
> >>
> >>
> >> this is not possible at the moment. May you please log a new JIRA
> >> improvement for that? IMHO this would be the way to go for improve the
> user
> >> service mapper
> >>
> >> regards
> >>
> >> antonio
> >>
> >>> 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
> >>> decker@robdecker.com
> >>> http://robdecker.com/about
> >>>
> >>>
> >>
> >>
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
>
>


-- 
Carsten Ziegeler
cziegeler@apache.org

Re: proper way to use ServiceUserMapper?

Posted by Antonio Sanso <as...@adobe.com>.
Thanks Carsten,

in any case I have opened https://issues.apache.org/jira/browse/SLING-3578 so we can continue the discussion there.

regards

antonio

On May 19, 2014, at 2:27 PM, Carsten Ziegeler <cz...@apache.org> wrote:

> I don't think that a bundle by itself should add the mapping - if the
> bundle simply inserts a mapping to admin you end up in the same situation
> as before. That's why we went with the central configuraiton so far
> 
> 
> 2014-05-19 9:47 GMT+02:00 Antonio Sanso <as...@adobe.com>:
> 
>> hi Robert
>> On May 15, 2014, at 5:54 PM, Robert A. Decker <de...@robdecker.com>
>> 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?
>> 
>> 
>> this is not possible at the moment. May you please log a new JIRA
>> improvement for that? IMHO this would be the way to go for improve the user
>> service mapper
>> 
>> regards
>> 
>> antonio
>> 
>>> 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
>>> decker@robdecker.com
>>> http://robdecker.com/about
>>> 
>>> 
>> 
>> 
> 
> 
> -- 
> Carsten Ziegeler
> cziegeler@apache.org


Re: proper way to use ServiceUserMapper?

Posted by Carsten Ziegeler <cz...@apache.org>.
I don't think that a bundle by itself should add the mapping - if the
bundle simply inserts a mapping to admin you end up in the same situation
as before. That's why we went with the central configuraiton so far


2014-05-19 9:47 GMT+02:00 Antonio Sanso <as...@adobe.com>:

> hi Robert
> On May 15, 2014, at 5:54 PM, Robert A. Decker <de...@robdecker.com>
> 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?
>
>
> this is not possible at the moment. May you please log a new JIRA
> improvement for that? IMHO this would be the way to go for improve the user
> service mapper
>
> regards
>
> antonio
>
> > 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
> > decker@robdecker.com
> > http://robdecker.com/about
> >
> >
>
>


-- 
Carsten Ziegeler
cziegeler@apache.org

Re: proper way to use ServiceUserMapper?

Posted by Antonio Sanso <as...@adobe.com>.
hi Robert
On May 15, 2014, at 5:54 PM, Robert A. Decker <de...@robdecker.com> 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?


this is not possible at the moment. May you please log a new JIRA improvement for that? IMHO this would be the way to go for improve the user service mapper

regards

antonio

> 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
> decker@robdecker.com
> http://robdecker.com/about
> 
> 


Re: proper way to use ServiceUserMapper?

Posted by "Robert A. Decker" <de...@robdecker.com>.
I just did an svn up and build and noticed the new 'Apache Sling Service User Mapper Service Amendment’

I threw together a quick config and tried it out and it works great! Thanks! This feels so much better than the old loginAdministrative method.


Robert A. Decker
decker@robdecker.com
http://robdecker.com/about



<node>
    <name>org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-astra_foundation</name>

    <primaryNodeType>sling:OsgiConfig</primaryNodeType>

    <property>
        <name>service.ranking</name>
        <value>0</value>
        <type>Long</type>
    </property>
    <property>
        <name>user.mapping</name>
        <values>
            <value>astra-utility:com.astracorp.foundation.utility.services.impl.DatastoreGCServiceImpl=admin</value>
        </values>
        <type>String</type>
    </property>

</node>


On 20 May 2014, at 16:54, Robert A. Decker <de...@robdecker.com> wrote:

> 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
> decker@robdecker.com
> http://robdecker.com/about
> 
> 
> On 15 May 2014, at 17:54, Robert A. Decker <de...@robdecker.com> 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
>> decker@robdecker.com
>> http://robdecker.com/about
>> 
>> 
>> 
> 
> 


Re: proper way to use ServiceUserMapper?

Posted by "Robert A. Decker" <de...@robdecker.com>.
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
decker@robdecker.com
http://robdecker.com/about


On 15 May 2014, at 17:54, Robert A. Decker <de...@robdecker.com> 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
> decker@robdecker.com
> http://robdecker.com/about
> 
> 
>