#1 2015-05-06 15:02:56

awilcox
Member
Registered: 2015-03-02

Problem using AuthenticatorService.setAuthenticated in a script

Hello,

I am trying to implement a script that calls a second nested script to create a User, the User object is returned to the calling script, and then the script calls AuthenticatorService.setAuthenticated(userId from the newly created User).

The script throws an exception when calling setAuthenticated(), as follows.

May 06, 2015 10:35:13 AM net.datenwerke.security.service.authenticator.AuthenticatorServiceImpl setAuthenticated
WARNING: Something went terribly wrong. UserId (320919) does not point at user.
net.datenwerke.security.service.authenticator.exceptions.AuthenticatorRuntimeException: Something went terribly wrong. UserId (320919) does not point at user.

My assumption is that the second nested script isn't actually committed when it completes and returns the User object back to the calling script. Is this the case? If so, is there any other way I can force the nested script to commit so that the calling script can successfully call setAuthenticated with the newly created user? Or any other suggestions how to accomplish this?



Snippet of code in the main script:

User userFromAD = GLOBALS.exec("/fileserver/bin/cbn_scripts/authorize.groovy", username);

if(null != userFromAD)
{
     logger.info("Authenticate success (user=" + userFromAD.getUsername() + ")");
    authenticatorService.setAuthenticated(userFromAD.getId());
}

Snippet of code in the second nested script:

User node = new User();
node.setFirstname(givenName);
node.setLastname(sn);
node.setUsername(sAMAccountName);
node.setEmail(mail);

parent.addChild(node);
userManagerService.persist(parent);
        
return node;

Offline

#2 2015-05-06 20:30:02

awilcox
Member
Registered: 2015-03-02

Re: Problem using AuthenticatorService.setAuthenticated in a script

More information that may be relevant:

- My main script is a script under a folder with "share folder for web access" enabled
- I am calling it directly in a browser: https://hostname/reportserver/reportserver/scriptAccess?path=/bin/scripts_webAccess/windowsAuthentication.groovy&username=myname
- I did not make any change in the httpauthexecute.cf file (although I'm now wondering if maybe I need to do something in here such that the script will execute / commit things properly?) --> Nevermind this line, I realized this is for reports, not scripts
- Even if I remove the line of code in the main script that is failing (authenticatorService.setAuthenticated(userFromAD.getId() ), the User object is still not being created in the database

Thanks,
Alana

Last edited by awilcox (2015-05-07 12:44:39)

Offline

#3 2015-05-08 12:46:44

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: Problem using AuthenticatorService.setAuthenticated in a script

Hi Alana,
scripts executed via scriptAccess are per default executed in uncommitting mode (ie similar to using exec without the -c modifier). In order to have this in committing mode you need to add the url parameter "commit=true".

Could you check if that helps?

Arno

Offline

#4 2015-05-08 13:14:07

awilcox
Member
Registered: 2015-03-02

Re: Problem using AuthenticatorService.setAuthenticated in a script

Hi Arno,

Thanks very much! Once I added "commit=true" to my URL it worked properly - the user was created/committed in my nested script, and the setAuthenticated(new user) in the main script was successful.

Alana

Offline

#5 2019-05-28 14:14:53

efedorov1
Member
Registered: 2019-05-23

Re: Problem using AuthenticatorService.setAuthenticated in a script

Arno Mittelbach wrote:

Hi Alana,
scripts executed via scriptAccess are per default executed in uncommitting mode (ie similar to using exec without the -c modifier). In order to have this in committing mode you need to add the url parameter "commit=true".

Could you check if that helps?

Arno

Hello,

I have a problem with 'commit' url parameter on reportserver 3.0.3. Actually it doesn't have any effect.
In the script I create new user and then save it with persist(). On my local machine 3.0.7 it does work as expected, but when I run the same script on the dev server it doesn't.
The user is created, after persist the script returns user.getId(), but after script execution there is no such user anywhere in the system.

Offline

#6 2019-06-03 06:22:31

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Problem using AuthenticatorService.setAuthenticated in a script

efedorov1 wrote:

I have a problem with 'commit' url parameter on reportserver 3.0.3. Actually it doesn't have any effect.
In the script I create new user and then save it with persist(). On my local machine 3.0.7 it does work as expected, but when I run the same script on the dev server it doesn't.
The user is created, after persist the script returns user.getId(), but after script execution there is no such user anywhere in the system.

Hi efedorov1,

if I understand correctly, this works in 3.0.7 but does not work in 3.0.3, correct ?

Regards,
Eduardo

Offline

Board footer

Powered by FluxBB