cancel
Showing results for 
Search instead for 
Did you mean: 

authenticationComponent.setSystemUserAsCurrentUser()

turgayz
Champ in-the-making
Champ in-the-making
Hi,
I was trying to create a node, but not from the web app - from within a scheduled job. So there is no "current user" where I am trying to create the node.

I had the trouble of authentication, and used the following first:

AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
authenticationService.authenticate("admin", "admin".toCharArray());
But obviously this is not a good idea as the admin password should have been changed.
I noticed that (in BaseAlfrescoSpringTest class for example), the following is used:

AuthenticationComponent authenticationComponent = (AuthenticationComponent) this.applicationContext
                .getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
And I decided to use this in my class. But is a good idea to use this other than within a TestCase?
2 REPLIES 2

andy
Champ on-the-rise
Champ on-the-rise
Hi

Internally you can set a user as authenticated.
This should certainly be used with caution.

You can use the authentication component to set the current authentication to be a given user name.

So if you want your sceduled job to run as the user "bobbins"
use authenticationComponent.setCurrentUser("bobbins") will do this.

Regards

Andy

turgayz
Champ in-the-making
Champ in-the-making
Thank you, Andy,
Are there any side effects when using this?

As I said, I want to run a scheduled job as a given user name. When I use this method, only the job's thread will be authenticated with the given user name, is that correct?
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.