cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed in getting a Username in Alfresco provided the login ticket.

umamaheswari
Champ in-the-making
Champ in-the-making
Hello All,

I have just started development with Alfresco. I want to know if I will be able to get the username, provided the ticket after login is available with me. I am developing Java Backed Webscripts.
Pardon me if I have posted it under wrong content.


the authenticationService.getCurrentUsername() method always returns "admin" as user.


Also how can i validate a person with the Ticket(acquired after login) he passes to me.

The authenticationService.getCurrentTicket() method and AuthenticationUtils.getTicket() methods return two different tickets all the time. What does this infer??

ANy help would be really helpful,,


Uma


9 REPLIES 9

mitpatoliya
Star Collaborator
Star Collaborator
Once you establish the session with generated ticket you can have access to the services
authenticationService is one of those services.
Now authenticationService.getCurrentUsername()  should return you the correct user name.It is returning the name which you have used for generating the Ticket.

How you are generating the ticket?
authenticationService.getCurrentTicket() should return you existing ticket and
authenticationService.getTicket() should return you new ticket AFAIK

actually if you see in latest version 4.2 AuthenticationService getTicket() is no longer available So I guess it is replaced by getNewTicket()

Hi Mits,

Thanks for the reply. Can u help with the following issue?? I have two web scripts (java-backed), one is CustomLogin webscript where i retrieve the ticket for the session and the other one is a FileUpload webscript. Now I want to use the "ticket" as a parameter for FileUpload. So I want to validate the session using the ticket I have retrieved earlier(Authenticating the session using the ticket I have). Could you pls suggest a way to do this.

Hi Uma,

Actually alfresco support the authentication via ticket out of the box.
Just pass the ticket in an alf_ticket parameter and your second webscript will automatically pick up the authentication:
http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Ftasks%2Fws-specify-use...

Regards,

umamaheswari
Champ in-the-making
Champ in-the-making
Hello,

Thanks for the reply. I was able to resolve the Ticket validation. Now I would like to know how to get the user name of the currently logged in user. I tried retrieving it with authenticationService.getCurrentUserName() which always returns "admin" instead of the logged in user.

Also how does this work when multiple users are logged in?? Any Help would be grateful.

Thanks

Hello,

Strange, authenticationService.getCurrentUserName() should work correctly.
What version of Alfresco are you using?
Also, please make sure that both your webscript descriptions don't specify "run as admin" with something like:
<authentication runas="admin">user</authentication>


Regards,

umamaheswari
Champ in-the-making
Champ in-the-making
hello Scouil,

I have specified the authentication element in the webscript descriptions as :

<authentication>user</authentication>

But still, the authenticationService.getCurrentUserName() returns "admin" always. Could you suggest what could be the reason for this ??

scouil
Star Contributor
Star Contributor
So just to make sure:

You have 2 webscripts.
You log in normally in the first one.
here, does authenticationService.getCurrentUserName() already returns admin?
then you do a request to your second webscript, authenticating with the ticket
here, does authenticationService.getCurrentUserName() returns admin

Is that it?

And you have no <authentication runas="admin">user</authentication> in any of your 2 webscripts
and no AuthenticationUtil.runAs in any of your java files?

umamaheswari
Champ in-the-making
Champ in-the-making
Hi Scouil,

Yes I have two webscripts. The authenticationService.getCurrentUserName()returns null when called in the login webscript. And I have not written a AuthenticationUtil.runAs method in any of these scripts. Could you pls tell if I have to describe any bean attribute in a descriptor file for AuthenticationService.

My custom login webscript extends LoginPost and i call login like :


Map<String, Object> loginInfo = login(username, password);


this loginInfo returns me a ticket.

I have been trying for long to resolve this. Any help would be grateful.

Thanks,

Hi,

It will of course be null if you call it before you call the line:
Map<String, Object> loginInfo = login(username, password);

What if you call it after?

About you design it also puzzles me that have have to call a webscript on the same server.
How about instead of having:
- Your LoginPost extension
- Your webscript doing all the work
You reformatted your code to have
- One independant class that does the actual work
- Your LoginPost extension that calls the first class (you can inject it with spring)
- Your webscript which is just there to retrieve the request and also call the first class to get the job done (you can also inject it with spring)

Regards,