cancel
Showing results for 
Search instead for 
Did you mean: 

Acquire alfresco ticket in dashlet

msaffer
Champ on-the-rise
Champ on-the-rise
I am attempting to retrieve the current alfresco ticket inside of a dashlet for use in an external system.

My configuration:
Alfresco 4.0.0 Community (3979) schema 5025 / Surf and Webscripts v1.0.0 (Release 957).
I have broken out share into its' own tomcat instance, which communicates with the Alfresco server, both on localhost.

I have an Alfresco Share Dashlet which has the following set in addition to the standard properties in my .desc.xml (shortname, description, and url omitted):

   <family>dashlet</family>
   <transaction>required</transaction>
   <authentication>user</authentication>

Based on the documentation in http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Session_API my understanding is that I should be able to execute the following in my .get.js file:

model.sessionticket = session.ticket

Which I would later reference in my .get.html file via:
${sessionticket}
However, this always returns a value of org.mozilla.javascript.Undefined@{some_memory_address}.

Is there something special I must do in order to get the ticket? Attempting to run the following in my .get.js file results in an exception being thrown
session.getTicket()
. Note that the session variable is in fact instantiated as an org.springframework.extensions.webscripts.AbstractRuntime$RuntimeSession@{some_memory_location}.

Is there a recommended way of getting at the session ticket other than through these variables? My gut instinct is that something must be misconfigured, however I have been able to other portions of the javascript API without issue.

Thanks,
-M
4 REPLIES 4

jpotts
World-Class Innovator
World-Class Innovator
I believe getTicket() may only work when you are in repository tier JavaScript, not Share-tier JavaScript. To test this, on Alfresco 4.0.d I created a little dashlet and did a session.getTicket() call in my controller. I saw the same result that you did. Then, I created a repository tier web script and used the same call to get the ticket successfully.

So, one way to get the ticket to your dashlet would be to create a repository tier web script that returns the ticket as JSON:
function main()
{
   model.sessionTicket = session.getTicket();
}
main();
The view would look like:
<#escape x as jsonUtils.encodeJSONString(x)>
{
   "ticket": "${sessionTicket}"
}
</#escape>
Then, you could call the repo tier web script from your share tier web script, like this:
function main()
{
    var json = remote.call("/example/get-ticket");

    if (json.status == 200)
    {
        obj = eval('(' + json + ')');
        model.result = obj;
    }
}
main();
And the view could then snag the ticket like this:
<span>TICKET</span>: <span>${result.ticket}</span>
Hope that helps,

Jeff

wkazmierczak
Champ in-the-making
Champ in-the-making
Hi Jeff, can you explain a bit more, please, where to put the "repository tier web script" (exact location), and make it callable from share tier web script?


remote.call("/example/get-ticket")


Thanks
Wojciech

I've created new directory "example" in:


/opt/alfresco-4.2.e/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository


and 3 new files:

get-ticket.get.desc.xml  get-ticket.get.js  get-ticket.get.json.ftl


my web script is available at:

http://localhost/alfresco/s/example/get-ticket


and I can make a call from share tier web script:

var json = remote.call("/example/get-ticket");

msaffer
Champ on-the-rise
Champ on-the-rise
Jeff,
Thank you for your prompt and enlightening response.

I have confirmed that session.getTicket() does in fact work in a repo tier webscript.

Again, thank you for your quick and accurate response.

-M