Expand my Community achievements bar.

SOLVED

How to get logged session in servlet

Avatar

Level 4

Hi,

I'm trying to activate user account in servlet but if I open the page and I'm not logged, the UserManager#getAuthorizable(String) returns null. I think it's because of some security features so I tried to create logged javax.jcr.Session but I wasn't able to create javax.jcr.Repository(and I couldn't use it's method login(Credentials, String)). This is my code so far

org.apache.jackrabbit.api.security.user.UserManager um = request.getResourceResolver().adaptTo(org.apache.jackrabbit.api.security.user.UserManager.class); try{ javax.jcr.Repository repo = org.apache.jackrabbit.commons.JcrUtils.getRepository("http://localhost:4502/crx/server"); try{ javax.jcr.Session session = repo.login(new SimpleCredentials("admin", "password".toCharArray()), "crx.default"); }catch(Exception e){ log.error("Exception "+e.getClass().getName()+": "+e.getMessage()); } User user = (User)um.getAuthorizable(userId); if(user == null){ log.info("User == null!"); }else{ log.info("user != null!"); } user.disable(null); }catch(Exception e){ log.error("Exception "+e.getClass().getName()+": "+e.getMessage()); }

but i get this exception

Exception javax.jcr.RepositoryException: Unable to access a repository with the following settings: org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server The following RepositoryFactory classes were consulted: Perhaps the repository you are trying to access is not available at the moment.

So my question is - How to get logged session in servlet? Or how can I activate user from servlet?

Thanks for any help.

1 Accepted Solution

Avatar

Correct answer by
Level 10

When working with Jackrabbit UserManager APIs in AEM - you need to get a session. However -- you cannot use Repository.login method  to get a session however.  Please read this new AEM article (published yesterday) that talks about using the Jackrabbit UserManager APIs within AEM. This shows you how to successfully get a UserManager instance:

http://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

When working with Jackrabbit UserManager APIs in AEM - you need to get a session. However -- you cannot use Repository.login method  to get a session however.  Please read this new AEM article (published yesterday) that talks about using the Jackrabbit UserManager APIs within AEM. This shows you how to successfully get a UserManager instance:

http://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html