cancel
Showing results for 
Search instead for 
Did you mean: 

extended login webscript

luisg
Champ in-the-making
Champ in-the-making
Hi all…
I'm developing a Java application that communicates with Alfresco. I'm trying to do my own login webscript:

login.get.desc.xml

<webscript>
  <shortname>Extended Login</shortname>
  <description>Establish a ticket</description>
  <url>/api/login?u={username}&amp;pw={password?}</url>
  <format default="json"/>
  <authentication>none</authentication>
  <transaction allow="readonly">required</transaction>
  <lifecycle>public_api</lifecycle>
  <family>Authentication</family>
</webscript>

login.get.json.ftl

{
   <#if ticket?exists && ticket!="">
      "success":"yes",
      "data": {
         "ticket":"${ticket}"
      }
   <#else>
      "success":"no",
      "errors": {
         "reason":"Invalid username/password!"
      }
   </#if>
}

The thing is, I always get the 'else' result.
What I'm doing wrong?

Thanks

Luis
1 REPLY 1

luisg
Champ in-the-making
Champ in-the-making
Hi again…
I can get it work like this:

{
   "data":
   {
   <#if ticket?exists>
      "success":"yes"
      "ticket":"${jsonUtils.encodeJSONString(ticket)}"
   <#else>
      "success":"no"
      "ticket":"empty"
   </#if>
   }
}

If the login succeeds I get the message:

{
   "data":
   {
      "success":"yes"
      "ticket":"${jsonUtils.encodeJSONString(ticket)}"
   }
}

And that is good. But if the login fails I get the error:

{ "status" : { "code" : 403, "name" : "Forbidden", "description" : "Server understood the request but refused to fulfill it." }, "message" : "07070020 Login failed", "exception" : "org.alfresco.web.scripts.WebScriptException - 07070020 Login failed", "callstack" : [ "" ,"org.alfresco.web.scripts.WebScriptException: 07070020 Login failed" ,"org.alfresco.repo.web.scripts.bean.AbstractLoginBean.login(AbstractLoginBean.java:81)" ,"org.alfresco.repo.web.scripts.bean.Login.executeImpl(Login.java:64)" ,"org.alfresco.web.scripts.DeclarativeWebScript.executeImpl(DeclarativeWebScript.java:223)" ,"org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:70)" ,"org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:357)" ,"org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:326)" ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:407)" ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:424)" ,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:253)" ,"org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:262)" ,"org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139)" ,"org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:122)" ,"javax.servlet.http.HttpServlet.service(HttpServlet.java:717)" ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)" ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)" ,"org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)" ,"org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)" ,"org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)" ,"org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)" ,"org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)" ,"org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)" ,"org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)" ,"org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)" ,"org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)" ,"java.lang.Thread.run(Thread.java:619)" ], "server" : "Alfresco Community v3.2.0 (2039) schema 2.019", "time" : "7/Ago/2009 17:16:40" }

but I should receive:

{
   "data":
   {
      "success":"no"
      "ticket":"empty"
   }
}
as it's define in my code…
The thing I notice is that, Alfresco returns it's default error (defined in json.status.ftl)
How can I do to return my own response?

Please help

Luis

PS: I'm using Alfresco 3.2