Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

username using client context

khalidMomin
Level 4
Level 4

How to get the logged in username using client context. I tried following code, but got admin as output, where as i want output as user logged in the geometrixx website.

 Session session = resourceResolver.adaptTo(Session.class);
 String userName=session.getUserID();

i guess this can be done using client context. Can anyone help me out getting username from client context.

Thanks in advance.

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
Level 10

To get a session in AEM 6 - use 


Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;

try {
           
//Invoke the adaptTo method to create a Session used to create a QueryManager
resolver = resolverFactory.getServiceResourceResolver(param);
session = resolver.adaptTo(Session.class);

View solution in original post

2 Replies
smacdonald2008
Correct answer by
Level 10
Level 10

To get a session in AEM 6 - use 


Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;

try {
           
//Invoke the adaptTo method to create a Session used to create a QueryManager
resolver = resolverFactory.getServiceResourceResolver(param);
session = resolver.adaptTo(Session.class);

View solution in original post

Anonymous
Not applicable

have you use admintrator code help?