Question

I am developing an apache sling WCMS. I want to export security contents (users and groups) to an xml file.

I used the following code but there is an exception:

OutputStream output = new FileOutputStream("d:\\bk.xml");
session.exportSystemView("/rep:security", output, false, false);
output.flush();
output.close();

And the exception here:

javax.jcr.PathNotFoundException: /rep:security
        at org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:545)
        at org.apache.jackrabbit.core.SessionImpl.getItem(SessionImpl.java:876)
        at org.apache.jackrabbit.commons.AbstractSession.export(AbstractSession.
java:541)
        at org.apache.jackrabbit.commons.AbstractSession.exportDocumentView(Abst
ractSession.java:237)
        at org.apache.jackrabbit.commons.AbstractSession.exportDocumentView(Abst
ractSession.java:279)....

Is it a true way to export users and groups?

Any help is appreciated.

Was it helpful?

Solution

I found that I was ignored where rep:security is located. rep:security is in security workspace of the repository so if I want to export it's contents I should log in security workspace before.

I corrected the code as follow and could export rep:security:

Session securitySession = session.getRepository().login(new SimpleCredentials("admin", "XXX".toCharArray()), "security");
OutputStream output = new FileOutputStream("d:\\bk.xml");
securitySession.exportSystemView("/rep:security", output, false, false);
output.flush();
output.close(); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top