title: Get logged in userId from a 'me' relative id in /users/me spring boot api
body: <p>We have a bunch of secured web services (using spring security) defined like this:</p>
  
  <pre><code>@GetMapping("/users/{userId}")
  public User getUserInfo(@PathVariable String userId) {
  ...
  @GetMapping("/users/{userId}/addresses")
  public User getUserInfo(@PathVariable String userId) {
  </code></pre>
  
  <p>If I want to get the logged in user, I can add the <code>Principal principal</code> or <code>HttpServletRequest request</code> to the method and spring will support the data for the logged in user, or also I can use <code>SecurityContextHolder.getContext().getAuthentication()</code>.</p>
  
  <p>So far so good, if we want to get the logged in user for the api <code>/users/1234</code> we have no problem. However we got a requirement to support a relative userId value being <code>me</code> where the api would be <code>/users/me</code>.</p>
  
  <p>We could resolve this by adding in each api just an <code>if</code> statement and replacing the userId <code>me</code> with the real logged in userId. We don't like this implementation since we have a boilerplate code in 20 apis. So, another solution we tried was by just adding an aspect to replace the <code>me</code> by the real userId but I don't like using reflection for solving this problem.</p>
  
  <p>So, i was wondering if there is a "spring boot" way of doing this? I haven't found any feature supporting this behavior.</p>