You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Tobias Bocanegra <tr...@apache.org> on 2014/04/10 07:42:56 UTC

How to get ContentRepository ?

Hi,

for [0] I need to "login" to the content repository - but I don't know
how to acquire it. it seems that it is neither registered as OSGi
service, nor in the global whiteboard (if there would be one).

so basically I need to do:

  ContentSession session = contentRepository.login(...);
  Root root = session.getLatestRoot();
  UserManager userManager =
securityProvider.getConfiguration(UserConfiguration.class)
                    .getUserManager(root, NamePathMapper.DEFAULT);

in a service. I think that we probably should register the
ContentRepository in the global whiteboard:

in Oak.createContentRepository(...):

@@ -548,13 +548,15 @@ public class Oak {

-        return new ContentRepositoryImpl(
+        ContentRepositoryImpl repository =  new ContentRepositoryImpl(
                 store,
                 CompositeHook.compose(commitHooks),
                 defaultWorkspaceName,
                 queryEngineSettings,
                 indexProvider,
                 securityProvider);
+        whiteboard.register(ContentRepository.class, repository,
Collections.emptyMap());
+        return repository;
     }

WDYT?

Regards, Toby


[0] https://issues.apache.org/jira/browse/OAK-1711

Re: How to get ContentRepository ?

Posted by Tobias Bocanegra <tr...@apache.org>.
fyi: https://issues.apache.org/jira/browse/OAK-1721

On Wed, Apr 9, 2014 at 10:42 PM, Tobias Bocanegra <tr...@apache.org> wrote:
> Hi,
>
> for [0] I need to "login" to the content repository - but I don't know
> how to acquire it. it seems that it is neither registered as OSGi
> service, nor in the global whiteboard (if there would be one).
>
> so basically I need to do:
>
>   ContentSession session = contentRepository.login(...);
>   Root root = session.getLatestRoot();
>   UserManager userManager =
> securityProvider.getConfiguration(UserConfiguration.class)
>                     .getUserManager(root, NamePathMapper.DEFAULT);
>
> in a service. I think that we probably should register the
> ContentRepository in the global whiteboard:
>
> in Oak.createContentRepository(...):
>
> @@ -548,13 +548,15 @@ public class Oak {
>
> -        return new ContentRepositoryImpl(
> +        ContentRepositoryImpl repository =  new ContentRepositoryImpl(
>                  store,
>                  CompositeHook.compose(commitHooks),
>                  defaultWorkspaceName,
>                  queryEngineSettings,
>                  indexProvider,
>                  securityProvider);
> +        whiteboard.register(ContentRepository.class, repository,
> Collections.emptyMap());
> +        return repository;
>      }
>
> WDYT?
>
> Regards, Toby
>
>
> [0] https://issues.apache.org/jira/browse/OAK-1711

Re: How to get ContentRepository ?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Thu, Apr 10, 2014 at 2:13 PM, Tobias Bocanegra <tr...@apache.org> wrote:
> On Thu, Apr 10, 2014 at 11:01 AM, Jukka Zitting <ju...@gmail.com> wrote:
>> Hmm, it should be available by default in a Sling environment:
>
> yes, in sling. but what if we run oak w/o sling?

It's up to the deployment to make all required dependencies available
to the components that need them. In a plain java deployment you'd
just pass the dependency as a constructor or setter argument.

>> There's no major functional difference between the two types of
>> repositories, so unless you specifically need one over the other, it's
>> easiest to use the one that's already available.
> the difference is, that the login context is setup by oak-core and so
> the callback handler can only provide oak API classes right now.

Callbacks should not be used like this, see
http://markmail.org/message/nb2j324ppfdop34f.

BR,

Jukka Zitting

Re: How to get ContentRepository ?

Posted by Tobias Bocanegra <tr...@apache.org>.
Hi,

On Thu, Apr 10, 2014 at 11:01 AM, Jukka Zitting <ju...@gmail.com> wrote:
> Hi,
>
> On Thu, Apr 10, 2014 at 1:27 PM, Tobias Bocanegra <tr...@apache.org> wrote:
>> On Thu, Apr 10, 2014 at 10:15 AM, Jukka Zitting <ju...@gmail.com> wrote:
>>> @Reference
>>> private Repository repository;
>>
>> which repository is that? javax.jcr.Repository?
>
> javax.jcr.Repository.
>
>> that one is not registered neither.
>
> Hmm, it should be available by default in a Sling environment:
> https://github.com/apache/sling/blob/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java#L210
yes, in sling. but what if we run oak w/o sling?

>>> Is there a particular reason why you'd need the Oak ContentRepository instead?
>> The current the logic in the external login module uses a
>> ContentSession to sync the content and not a jcr session. I can try to
>> change that, but then I need a way to obtain a JCR session from within
>> the login modules.
>
> There's no major functional difference between the two types of
> repositories, so unless you specifically need one over the other, it's
> easiest to use the one that's already available.
the difference is, that the login context is setup by oak-core and so
the callback handler can only provide oak API classes right now.

> Also, it sounds like it would be useful to have your code work
> smoothly also with Jackrabbit Classic, which would be easier to
> achieve if you only used the JCR API.
true - I think I can work around it....somehow...for now....

regards, toby

>
> BR,
>
> Jukka Zitting

Re: How to get ContentRepository ?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Thu, Apr 10, 2014 at 1:27 PM, Tobias Bocanegra <tr...@apache.org> wrote:
> On Thu, Apr 10, 2014 at 10:15 AM, Jukka Zitting <ju...@gmail.com> wrote:
>> @Reference
>> private Repository repository;
>
> which repository is that? javax.jcr.Repository?

javax.jcr.Repository.

> that one is not registered neither.

Hmm, it should be available by default in a Sling environment:
https://github.com/apache/sling/blob/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java#L210

>> Is there a particular reason why you'd need the Oak ContentRepository instead?
> The current the logic in the external login module uses a
> ContentSession to sync the content and not a jcr session. I can try to
> change that, but then I need a way to obtain a JCR session from within
> the login modules.

There's no major functional difference between the two types of
repositories, so unless you specifically need one over the other, it's
easiest to use the one that's already available.

Also, it sounds like it would be useful to have your code work
smoothly also with Jackrabbit Classic, which would be easier to
achieve if you only used the JCR API.

BR,

Jukka Zitting

Re: How to get ContentRepository ?

Posted by Tobias Bocanegra <tr...@apache.org>.
Hi,

On Thu, Apr 10, 2014 at 10:15 AM, Jukka Zitting <ju...@gmail.com> wrote:
> Hi,
>
> On Thu, Apr 10, 2014 at 1:42 AM, Tobias Bocanegra <tr...@apache.org> wrote:
>> for [0] I need to "login" to the content repository - but I don't know
>> how to acquire it.
>
> @Reference
> private Repository repository;

which repository is that? javax.jcr.Repository? that one is not
registered neither.

> Is there a particular reason why you'd need the Oak ContentRepository instead?
The current the logic in the external login module uses a
ContentSession to sync the content and not a jcr session. I can try to
change that, but then I need a way to obtain a JCR session from within
the login modules.

regards, toby

Re: How to get ContentRepository ?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Thu, Apr 10, 2014 at 1:42 AM, Tobias Bocanegra <tr...@apache.org> wrote:
> for [0] I need to "login" to the content repository - but I don't know
> how to acquire it.

@Reference
private Repository repository;

Is there a particular reason why you'd need the Oak ContentRepository instead?

BR,

Jukka Zitting