cancel
Showing results for 
Search instead for 
Did you mean: 

behaviour context problem

scouil
Star Contributor
Star Contributor
Hello everyone,

I'm trying to get a control over the users added to alfresco.
When a user is added to alfresco, I want to check the domain of the email adress and if it's one of ours, automatically enable the user account and add him to the appropriate group depending on this domain.

In order to do so, I added a custom behavior onCreateNode for cmSmiley Tongueerson.
Since I already have quite a lot of webscripts written in javascript running on top of Alfresco with externalized constants and so on, I chose to write that custom behaviour in javascript too.

When the user is created with the site "external invitation" feature, it works.
When the user is created from share user interface (http://localhost:8080/share/page/console/admin-console/users#state=panel%3Dcreate) it works.
When the user is created via the script console (http://code.google.com/p/share-extras/wiki/JavascriptConsole) it works.

However, for the users whose account is created on ldap login (haven't tested with ldap synchronization), the script is started in an unusual way (not by a user).
This cause
behaviour.args[0].getChild()
to evaluate to "A valid SecureContext was not provided in the RequestContext" instead of the user node.

I'll create a Jira since this is clearly a bug. The script should probably be called by the "System" user.
However, I was thinking that maybe I could force the behavior to execute with specific user rights (like the runas="admin" for the webscripts) for the time being. How can I add such a property to my spring bean?

TLDR: Can a custom behavior be forced to execute as if started by the admin or system user?
4 REPLIES 4

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Use the AuthenticationUtil in the Java code when running the script (you'll have to wrap the code in onCreateNode and set the user to System. This is a sample code using the AuthenticationUtil and the System user to run code:


Object result = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
                  {
               public Object doWork() throws Exception
               {
                  ….

               }
                  }, AuthenticationUtil.SYSTEM_USER_NAME);

Regards,
Adei

scouil
Star Contributor
Star Contributor
Hello amandaluniz_z and thanks for taking the time to answer me.

Your solution would work but would require me to switch to java for the behavior.
However, as I said, I'd really like to stick with javascript and stay coherent with the existing work and share its configuration.

Thanks anyway,

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Then what I guess you can do is extend ScriptBehaviour class and configure your javascript behaviour to match your needs.

scouil
Star Contributor
Star Contributor
Yes, I like this idea better.
But if I'm to modify/extend alfresco source code, maybe I'd better directly fix the bug itself instead of coding around it.

But that requires quite some time to get familiar with alfresco source code architecture and philosophy.
I'll post here if I find the time to make this work. Or maybe I'll directly POST in the jira (https://issues.alfresco.com/jira/browse/ALF-14030)

Thanks for your help.