Hi,

On Fri, May 31, 2013 at 10:03 AM, Christian Eugster
<[email protected]> wrote:
> ...I have created an osgi service that should have write permissions to the 
> sling repository. How can I achieve this?...

If your service is processing a request, the Resource that you get in
the request gives you access. There's various ways, for example
resource.adaptTo(Node.class).getSession() provides a JCR session.

If you don't have a request you can use an @Reference annotation to
get a SlingRepository, and SlingRepository.loginAdministrative(...) to
get a Session. Impersonating the Session to a different user is
preferred then, to avoid working as admin. Or get a ResourceResolver
service via ResourceResolverFactory if you want to work with Resources
as opposed to JCR Nodes.

There's tons of examples in the Sling codebase, if you search for the
above code patterns.

-Bertrand

Reply via email to