Search code examples
alfresco

Alfresco AuthenticationService.getCurrentUserName() always returns admin?


I am trying to get user name for logged in user in alfresco using

String name = serviceRegistry.getAuthenticationService().getCurrentUser();

But it always return admin regardless of which user is logged in.

Then i tried

String name = AuthenticationUtil.getFullyAuthenticatedUser();

It also returns admin for all users.

I googled it without any success. Is it a bug in alfresco or do i need to take care of something else also to get appropriate user name?

Or is there any other way to get currently logged user name?


Solution

  • String name = AuthenticationUtil.getFullyAuthenticatedUser();
    

    is the correct way to get the userName of your current user.

    Every webscript has an descriptor where you can configure the authentication that is required to execute the webscript: http://docs.alfresco.com/4.2/references/api-wsdl-authentication.html

    Typically, you will use <authentication>user</authentication>

    There are two different 'runtimes' in the alfresco repo that can be used to execute a webscript:

    1. /alfresco/s/... (long version /alfresco/service) that uses HTTP Basic Authentication
    2. /alfresco/wcs/... (long version /alfresco/wcservice) that uses Alfresco's WebClient (Alfresco Explorer) authentication.