1

I'm using an XPage as an agent (XAgent) which makes an SSJS call into some Java classes stored as Java design elements. I want the processes which are instigated by the XPage to be in the context of the user I'm currently signed into the browser as. However everything seems to be running as me, I guess based on the last signature on the XPage?

For example, in my custom classes the following returns my name when I need it to be returning the user's name:

DominoUtils.getCurrentSession().getEffectiveUserName()

When using old school Domino agents, the effective username is determined by the "Run as Web User" or "Run on behalf of" fields in the agent properties.

Is it possible to achieve the same functionality when using an XPage?

lee_mcmullen
  • 2,801
  • 32
  • 39
  • Can you add your code snippet to your question, because `DominoUtils.getCurrentSession().getEffectiveUserName()` (in Java) and `session.getEffectiveUserName()` (in SSJS) always works for me? – Naveen Feb 12 '13 at 16:21
  • No problem, which snippet would you like to see? The section I've pasted into the description is what is returning my name instead of the web user's name. That code is in the constructor of a class which is getting called in the beforeRenderResponse event. – lee_mcmullen Feb 13 '13 at 08:04
  • Code snippet of `beforeRenderResponse` on how it is calling your custom Java class. And I would recommend looking into options provided by stwissel below. – Naveen Feb 13 '13 at 11:56
  • Hi Naveen, to call the handleRequest() method on the my custom java class from SSJS, I'm doing as follows: var controller:my.package.name.Controller = new my.package.name.Controller(); controller.handleRequest(); – lee_mcmullen Feb 14 '13 at 14:42

2 Answers2

2

To investigate you have a number of moving parts:

  1. Add to the XAgent (not your Java code) a print statement with session.getUserName() and session.getEffectiveUsername()
  2. Check your DominoUtils if there is a sessionAsSigner hidden in it
  3. if 1 works, but not 3, consider dependency injection: instead of getting the session from DominoUtils hand it over as parameter from the XAgent to the Java class

Let us know how it goes

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Thanks, I'm not near a PC at the moment but I'll run through your suggestions as soon as I am and let you know. Based on your comments it sounds like you think DominoUtils is causing my issue. So if I pass the session into java from SSJS, presumably I would expect that session to be automatically in the context of the web user? Not just for EffectiveUsername but also ACL security, reader/author names etc? – lee_mcmullen Feb 13 '13 at 07:56
  • So in the XPage SSJS, session.getUserName() == server's full name | session.getEffectiveUsername() == user's full name. I couldn't find a sessionAsSigner property in DominoUtils. I was going to do what you suggested and pass the session in from the XPage. Then I spotted that you can pass the FacesContext as a param when calling getCurrentSession. Tried that and hey presto, it started working. Makes sense I guess, you want the session to be in the context of the current XPage aka Java Server Faces context. Thanks for the pointers. – lee_mcmullen Feb 14 '13 at 14:40
0

In my scenarios I could solve most of the requirements with either:

session.getEffectiveUserName()

or:

context.getUser().getFullName()

There are situations where you need to encapsulate this with:

session.createName(string):NotesName

to get the NotesName-Object representation.

  • 1
    What I'm saying is that the username returned by EffectiveUserName in Java is not returning the name of the current web user, it's returning my name - presumably because I was the last person to save the XPage. – lee_mcmullen Feb 12 '13 at 15:51