Spring Boot. How to provide access to logged-in user over regexMatchers?

I have many users in DB with unique {id} for everyone. Each user should have the permission to edit only his own page (it should be logged-in user). How can I do it in "configure" method?

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().regexMatchers("/people/(\\d+)/edit").....

So, this {id} in the path should be equivalent to id of logged-in user. how to organise this rule? Or may be some kind of another way used to fix such tasks?

UPD. Answer:

Thank you a lot unknown mate! Your link provided to me - the start point for understanding. I will leave over here some explanations for further newbies like me:

  1. This problem does not fixed in Config class. In Config we are requesting authorized access for all folders:

.mvcMatchers("/people/{id}/**").authenticated() and mention annotation @EnableGlobalMethodSecurity(prePostEnabled=true)

  1. Access is limited than in Controller by annotation:

@PreAuthorize("#id == authentication.principal.id")

and method arguments should consist id variable:

public String edit2(@PathVariable("id") int id)

This one says, that only authenticated users with id (taken from myUserDetails) equivalent to PathVariable id will have access to this method. Rest of users will receive Error page.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum