cancel
Showing results for 
Search instead for 
Did you mean: 

Getting username of the user who executed a repository tier web script

mando_alvarado_
Champ in-the-making
Champ in-the-making
Title pretty much sums it up.

I need to obtain the current user's username within a repo-tier webscript's javascript code. By "current user", i mean the authenticated user that triggered the execution of said script.

I have tried to obtain this information using the now famous (to me anyway) root scope objects…namely the "person" object. According to this page:

http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPI-JS-ro...

…the "person" object should be available in my javascript code. It isn't clear, however, if it should be present on repository webscripts or share webscripts. In either case, whenever i try to use the "person" object, i get a 500 response with a wrapped exception message that says "ReferenceError: \"person\" is not defined.".

The javascript code responsible for this exception is trivial:

model.userName = person.properties.userName;

That's it. This isn't just the line where the error occurs…this is the WHOLE .js file.

I have been trying to resolve this issue for weeks now without any luck. The "person" object just isn't there, and for that matter, neither is "companyhome" or "userhome". I get the same error message when i try to use them.

There must be a reason why these objects aren't included/generated in my js context, but i have no idea why.

I would appreciate any help i can get on this matter. I hope i'm not the only one with this issue.
6 REPLIES 6

abarisone
Star Contributor
Star Contributor
Hi,
that sounds strange since
person.properties.userName
gives you the name of the currently authenticated user.
Is your web script configured to have
<authentication>user</authentication>
in its desc file?
You may also use the debugger to check the content of the parameter…

Regards,
Andrea

mando_alvarado_
Champ in-the-making
Champ in-the-making
Yes, the authentication type is set to "user" in the xml desc file.

Also, when trying to enable the debugger, i get the following error:


The Web Script /alfresco/service/api/javascript/debugger has responded with a status of 500 - Internal Error.

500 Description:    An error inside the HTTP server which prevented it from fulfilling the request.

Message:   01060011 Wrapped Exception (with status template): null

Exception:   org.springframework.extensions.webscripts.WebScriptException - 01060011 Wrapped Exception (with status template): null

org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1067)

Server:   Community v4.2.0 (4480) schema 6,020
Time:   Feb 6, 2013 1:56:05 PM

Diagnostics:   Inspect Web Script (org/springframework/extensions/webscripts/jsdebugger.post)

I am hitting wall after wall here.

lista
Star Contributor
Star Contributor
JavaScript debugger won't work on headless servers and if you're starting Alfresco as a service, at least in my experience. Do you fall in these categories?

I'm not sure I understand what you mean by repo-tier, can you explain that to me?

By repo-tier webscripts, I mean webscripts that are in alfresco, not share. I.E they reside in the following path: /tomcat/webapps/alfresco/WEB-INF/clases/alfresco/templates/webscripts/. I don't know if that is the right way to call these webscripts, but I seem to have picked up the term "repo-tier" from all the online reading I have done.

As for your other question, I have no idea what a headless server is. I AM running it as a service though. I looked up a solution to this problem and found a forum thread where someone apparently found a way around this. His solution was creating a set of .bat files and starting up alfresco with those. Unfortunately, it didn't work for me.

lista
Star Contributor
Star Contributor
That is strange, I never encountered root objects not being available in web script. You're on your own on that one.
I'm not sure as to why starting Alfresco through a .bat file does not work for you, do you get a concrete error? There's a setenv.bat file too, maybe it's setting environment variables to something that's not correct (had this issue once)?

mando_alvarado_
Champ in-the-making
Champ in-the-making
So, after a few months, I stumbled upon a solution to this. I have no idea why this works, or what is going on under the hood, and frankly I don't care anymore. This was a stupid problem to have.

The problem is that apparently you can't use <javascript><transaction>none</transaction></javascript> in your webscript desc file. If you do, you won't have access to certain root scope objects. I fixed it by using <javascript><transaction>required</transaction></javascript>.

I think this should be mentioned somewhere.