5 Replies Latest reply on Nov 29, 2008 12:23 AM by Ben Giddins

    How to get access to javax.jcr.Repository

    Ben Giddins Newbie

      I've been writing some portlets using the CMS interface to access Jackrabbit. I've been using the following to date to get access to the CMS:

      MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
      
       cms = (CMS) MBeanProxy.get(CMS.class, new ObjectName("portal:service=CMS"), mbeanServer);


      This works fine, and I can retrieve content etc using code like:

      Command getContentCMD = cms.getCommandFactory().createContentGetCommand(dirPath, version, locale);
      
       ContentImpl contentImpl = (ContentImpl) cms.execute(getContentCMD);


      I've run into some limitations of what I can achieve through the CMS interface - I would like to start using the JCRCMS implementation, or even get avax.jcr.Repository - which looks like it can be done from JCRCMS. Has anyone got some code to show me how to get either of these objects?

      I'm using JBoss Portal 2.7.0.

        • 1. Re: How to get access to javax.jcr.Repository
          John Gerevich Newbie

          I was looking for the same thing, luckily I found it via the JMX console:

          InitialContext ctx = new InitialContext();
           org.jboss.portal.cms.impl.jcr.JCRCMS jack = (org.jboss.portal.cms.impl.jcr.JCRCMS)ctx.lookup("java:portal/CMS");
          
           Repository repository = jack.getRepository();
          
           Session session = repository.login();
          


          My only problem is, that with the above mentioned login usage I always get a
          javax.jcr.AccessDeniedException: /default: not allowed to modify item
          if I try to modify either the root or the "default" node.

          Can anyone help me on that?

          • 2. Re: How to get access to javax.jcr.Repository
            Dan Krieger Newbie

            trouble is your login() statement is more than likely logging in with anonymous access (read-only only). You'll need to pass credentials to the login statement:

            Repository repository = jack.getRepository();
            //Anonymous login
            //Session session = repository.login();
            
            //User authenticated login
            Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));
            


            I'm not familiar with the Jackrabbit configuration for JBoss Portal CMS so I'm not sure what the username and password should be for you to get write access on the repository. But this should at least get you closer.

            • 3. Re: How to get access to javax.jcr.Repository
              Ben Giddins Newbie

              Thanks guys - I will try a combination of that code. I believe that you can use any JBoss Portal user to access the CMS, so I will look at setting up a "cmsadmin" type user for my code.

              cheers

              • 4. Re: How to get access to javax.jcr.Repository
                Sohil Shah Master

                Actually the SimpleCredential way will not work since the fine grained CMS Security is performed via the Portal CMS Security Engine and not by the JackRabbit Engine.

                To achieve what you want to do, you can disable this interceptor when making a CMS Request. This approach is used in the Workflow components as well:

                Check this sample code from the workflow components for some ideas:

                ACLInterceptor.turnOff();
                
                //create this content in the CMS and make it live
                Command command = cms.getCommandFactory().createContentGetVersionsCommand(content.getPath());
                List versions = (List)cms.execute(command);
                
                ACLInterceptor.turnOn();
                


                Thanks

                • 5. Re: How to get access to javax.jcr.Repository
                  Ben Giddins Newbie

                  I've been able to access the repository using the code supplied - thanks all. That was using login() - I can check the user and it is indeed the anonymous user. I haven't tried creating content in my repository using the anonymous user though.