1

i have this controller with Spring @PreAuthorize annotation:

@PreAuthorize("hasRole('ROLE_USER') and #id == authentication.name")
public ResponseEntity<UserProfileDTO> updateProfile(@PathVariable(name = "id") final UUID id) {
//service call
}

but the problem is, that principal is String, and equals return false. How i can call java.util.UUID.fromString(authentication.name) ?

Igor
  • 478
  • 9
  • 22

1 Answers1

1

this is the solution:

    @PreAuthorize("hasRole('ROLE_USER') and #id == T(java.util.UUID).fromString(authentication.name)")
Igor
  • 478
  • 9
  • 22
  • 5
    Thank you for this code snippet, which might provide some limited short-term help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its long-term value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – Toby Speight Jan 24 '18 at 13:52
  • Also you could do some more research (first link on Google with `spring el method call` on SO), before asking a question, which is already answered. – dur Jan 24 '18 at 14:00