Communote / communote-server

Communote server with core plugins
http://communote.github.io/
Apache License 2.0
22 stars 4 forks source link

request.getRemoteUser() returns different results #49

Closed datenwort closed 6 years ago

datenwort commented 6 years ago

I am facing a very weird issue.

@Component
@Provides
@Instantiate
@UrlMapping(value = "/*/plugin/profile/extension")
public class ExtensionController implements Controller {

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
}
}

The call request.getRemoteUser() sometimes returns the id of the user and sometimes the alias. I cannot reproduce the environment, but it changes from time to time.

Any clue on this?

rwi commented 6 years ago

That's simple, we don't set the remote user explicitly :wink:

To get the currently authenticated user please use the SecurityHelper. Especially the getCurrentUserId() method is a good starting point. It gives you the ID of the currently logged in user, which in your case is the one who did the request to your controller, or null if no one is logged in. The ID can be used to get further information about the user from the UserManagement by invoking UserManagement.getUserById(Long userId, Converter<User, T> converter). The UserManagement is accessible via the ServiceLocator's findService method.

datenwort commented 6 years ago

Thanks.