title: How to configure Spring Boot Security so that a user is only allowed to update their own profile
body: <p>I have implemented the basic Spring Boot Security stuff in order to secure my web services. I know that you can grant access to some services only to some user Roles, but is it also possible to grant access to a specified user (user can be dynamic)?</p>
  
  <p>Let's say we have a social app, where every user has their own profile. With the  following rest-service, they should be the only one able to edit the profile:</p>
  
  <pre><code>@RestController
  public class UserController {
      @RequestMapping(method = RequestMethod.PUT, path = "/user/{userId}", ...)
      public UserDetails updateUserDetails(@PathVariable("userId") String userId) {
          // code for updating the description for the specified user
      }}
  }
  </code></pre>
  
  <p>How can i ensure with spring security, that only the user itself can update his personal profile? Any other user should be rejected. Is there an elegant way, how you can configure this behaviour?</p>
  
  <p>I have tried to find a method for that inside my WebSecurityConfig, but with no success.</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      @Override
          protected void configure(HttpSecurity http) throws Exception {
              http
                      // configure authorization for urls
                      .authorizeRequests()
                      // grant access to all users for root path and /home
                      //.antMatchers("/", "/home").permitAll()
                      // here i would like to grant access in the way, that only the user is allowed to perform this request by calling url with his userId
                      .antMatchers(HttpMethod.PUT,"/user/&lt;userId&gt;").and().httpBasic();
        }
  </code></pre>
  
  <p>What is a good approach to implement this behaviour?</p>