1
votes

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?

2
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
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
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
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

2 Answers

2
votes

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

0
votes

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.