How to get the admin session
7. März 2009 von stejan
I now work since 3 months with cq5 and I realy like it. But there are so many new things to learn!!
For example the thing: How do I have to get the admin session?
Thanks Julian for your help. I would never get it myself.
final SlingRepository repo = sling.getService(SlingRepository.class);
final JcrResourceResolverFactory resolverFactory =
sling.getService(JcrResourceResolverFactory.class);
final Session admin;
try {
admin = repo.loginAdministrative(null);
} catch (RepositoryException e) {
// If we can't get the admin session it's safer to assume no CUG
sling.getResponse().getWriter().println("Admin session not available...");
return false;
}
//Access to the Sling API
final ResourceResolver adminResourceResolver =
resolverFactory.getResourceResolver(admin);
//Access to the CQ5 Page-API
PageManager adminPageManager = adminResourceResolver.adaptTo(PageManager.class);
final Resource adminResource = adminResourceResolver.resolve(resource.getPath());
//To get to the resource or page the following should give you a pointer:
final Page page = adminPageManager.getContainingPage(adminResource);
Ähnliche Artikel
1 Reaktion zu “How to get the admin session”
Das ist mal echtes API-Hopping