cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript - 'run as', authenticate as another user

fx3000se
Champ in-the-making
Champ in-the-making
This topic is somehow linked/related to to this http://forums.alfresco.com/en/viewtopic.php?f=9&t=16666#p55979

Can a Javascript be run as another user, or can I authenticate (getting another authentication context, ticket) as another user within the script?
1 REPLY 1

t_broyer
Champ in-the-making
Champ in-the-making
This topic is somehow linked/related to to this http://forums.alfresco.com/en/viewtopic.php?f=9&t=16666#p55979

Can a Javascript be run as another user, or can I authenticate (getting another authentication context, ticket) as another user within the script?

I wrote an extension that wraps AuthenticationUtil.runAs(…) to allow running a javascript function as "system" (I have no need for specifying a specific user). For obvious security reasons, this is only available for scripts stored on the classpath (most webscripts): you wouldn't want a user to drop a script in Data Dictionary/Scripts that allows him to impersonate and do things on behalf of another user?

Usage:

var result = ubic.utils.runAsSystem(function() {
    // here, the current user used for ACL checking is "system"
  });

I can't contribute the code but it's really easy to write your own (the AuthenticationUtil.RunAsWork implementation is no more than 2 lines long!)