cancel
Showing results for 
Search instead for 
Did you mean: 

Login using Alfresco Ticket

riju4alf
Champ in-the-making
Champ in-the-making
Hi all
i have been using this amazing Content managemnt system for few mnths now ..
So my query is
if theres a Possibility of log in to my alfresco without typing username/password :
a) is there any URL with uname/pwd as parameters to login ?
b) is there any URL with only alfresco ticket as parameters to login ?
c)Please mention if any other way is there apart from the ones above .

Thanks in Advance
6 REPLIES 6

openpj
Elite Collaborator
Elite Collaborator
a) is there any URL with uname/pwd as parameters to login ?
There is a Login WebScript for this at the following URL that you can execute with a GET HTTP:
/alfresco/service/api/login?u={username}&pw={password?}
The u parameter is the username and the pw parameter is the password.
b) is there any URL with only alfresco ticket as parameters to login ?
It is not possible to do this. You have to authenticate against Alfresco using username and password for the first time usgin for example the login WebScript.
The previous URL will return you the Alfresco Ticket in the HTTP response. The ticket can be used to invoke other WebScripts adding the alf_ticket parameter in the query string, for example:
/alfresco/service/ui/myspaces?alf_ticket=ALF_TICKET_VALUE
For all the next requests using the alf_ticket, the user can access to all the services without executing the login process.
Hope this helps.

mrogers
Star Contributor
Star Contributor
Just a quick addition.

Although the web script above will work there's another version of the script that acceps the username and password Posted in the body.  For security reasons its probably best to use the POST rather than the GET.   Either way both scripts do the same.

riju4alf
Champ in-the-making
Champ in-the-making
Thanks to Both of you for the prompt Reply .

But the following is not serving my purpose :
/alfresco/service/ui/myspaces?alf_ticket=ALF_TICKET_VALUE
i tried the above , but i found that i am only loging in as GUEST and not as ADMIN (even if am fetching ADMIN ticket here using the URL /alfresco/service/api/login?u=<uname>&pw=<pwd> )

This is exactly what i did :
Fetched the ticket by
[ALFRESCO_URL]/alfresco/service/api/login?u=<uname>&pw=<password>
got the XML file in browser . Copied the ticket value .
Used the same ticket in the following
<ALFRESCO_URL>/alfresco/service/ui/myspaces?alf_ticket=<ALF_TICKET_VALUE>
What am getting is : a dialogues box asking for Alfresco username/pwd .Now if i give admin credentials , still its opening a guest view of "Space"-s

What is wrong in the whole process ,that m doing  ?

berenicestr69
Champ in-the-making
Champ in-the-making
a) is there any URL with uname/pwd as parameters to login ?
There is a Login WebScript for this at the following URL that you can execute with a GET HTTP:
/alfresco/service/api/login?u={username}&pw={password?}
The u parameter is the username and the pw parameter is the password.
b) is there any URL with only alfresco ticket as parameters to login ?
It is not possible to do this. You have to authenticate against Alfresco using username and password for the first time usgin for example the login WebScript.
The previous URL will return you the Alfresco Ticket in the HTTP response. The ticket can be used to invoke other WebScripts adding the alf_ticket parameter in the query string, for example:
/alfresco/service/ui/myspaces?alf_ticket=ALF_TICKET_VALUE
For all the next requests using the alf_ticket, the user can access to all the services without executing the login process.
Hope this helps.


Is any posible to autenticate against Alfreso whithout using username and password for the first time???? please help me!!!!!

Thanks a lot

mrogers
Star Contributor
Star Contributor
Yes, SSO via NTLM, Kerberos etc …. the usual suspects.

tejaskanani2920
Champ in-the-making
Champ in-the-making
HI,

Below is the code which will give you the alf_ticket using POST webscript. First it will call the http://localhost:8080/alfresco/service/api/login
via POST call and when web script return the ticket in JSON format it will parse it and return you the ticket in simply string format.

For that you need to add one jar to your CLASSPATH for json parsing.


public String getAlfTicket(String _userName, String _password)
   {
      String _ticket = "";

      URL url;
      HttpURLConnection connection = null;
      try
      {
         String urlParameters = "{ \"username\" : \"" + _userName +"\", \"password\" : \"" + _password +"\" }";
         
         // Create connection
         url = new URL("http://localhost:8080/alfresco/service/api/login");
         connection = (HttpURLConnection) url.openConnection();

         connection.setRequestMethod("POST");
         connection.setRequestProperty("Content-Type", "application/json");
         connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
         connection.setRequestProperty("Content-Language", "en-US");
         connection.setUseCaches(false);
         connection.setDoInput(true);
         connection.setDoOutput(true);

         // Send request
         DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
         wr.writeBytes(urlParameters);
         wr.flush();
         wr.close();

         // Get Response
         InputStream is = connection.getInputStream();
         BufferedReader rd = new BufferedReader(new InputStreamReader(is));
         String line;
         StringBuffer response = new StringBuffer();
         while ((line = rd.readLine()) != null)
         {
            response.append(line);
            response.append('\r');
         }
         rd.close();
         String _jsonResponse = response.toString();
         
         JSONObject _jsonResponseObject = (JSONObject)new JSONParser().parse(_jsonResponse);
          JSONObject jsonDataObject = (JSONObject)new JSONParser().parse(_jsonResponseObject.get("data").toString());
          _ticket = jsonDataObject.get("ticket").toString();

      }
      catch (Exception e)
      {

         e.printStackTrace();
         return null;

      }
      finally
      {

         if (connection != null)
         {
            connection.disconnect();
         }
      }
      return _ticket;
   }