AnsweredAssumed Answered

get session ticket on share

Question asked by michaelp on Aug 1, 2014
Latest reply on Aug 5, 2014 by michaelp
Hello,

I want to get the session ticket of the currently logged in user to copy it to the clipboard (Internet Explorer).
Afterwards a java web start application should load this ticket from the clipboard to log in into the Alfresco Repository using CMIS and download a document (copying the nodeRef to the clipboard works).

Got it working:

The repo tier webscript to get the ticket:

### get-ticket.get.desc.xml
<webscript>
    <shortname>Get current ticket</shortname>
    <description>Returns a valid ticket for the currently logged in user</description>
    <url>/auth/get-ticket.js</url>
    <url>/auth/get-ticket.json.ftl</url>
    <format default="js">extension</format>
    <authentication>user</authentication>
    <transaction>none</transaction>
</webscript>

### get-ticket.get.js
function main() {
   model.sessionTicket = session.getTicket();
}
main();

### get-ticket.get.json.ftl
<#escape x as jsonUtils.encodeJSONString(x)>
{
   "ticket": "${sessionTicket}"
}
</#escape>


Client side javascript ajax call: ajax call to share tier webscript -> share tier calls repo tier webscript -> repo ws return the ticket -> share ws parses the ticket as response to the client side javascript.


                  Alfresco.util.Ajax.jsonGet(
               {
                  url: Alfresco.constants.PROXY_URI + "/auth/getTicket.json",
                  successCallback:
                  {
                     fn: function(response)
                     {
                        try {
                           var json = JSON.parse(response.serverResponse.responseText);
                           var ticket = json["ticket"];
                           if (ticket.substring(0, 6) == "TICKET") {
                              clipboardData.setData("Text", ticket);
                           } else {
                           }
                        } catch (e) {
                        }
                        
                     },
                     scope: this
                  },
                  
                  failureCallback:
                  {
                     fn: function(response)
                     {
                        
                     },
                     scope: this
                  }
               });


NOTE: you also need the share tier webscript (here "/auth/getTicket.json") which parses the ticket from the repo tier webscript!

Outcomes