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?
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.
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.
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();
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.