Spring Custom User Context
If you’re doing OAuth2/OIDC + JWT with Spring, you might be using the ThreadLocal SecurityContextHandler to get Data about the authorized user. This code extracts the “JWT Subject” which can be used as a unique identifier for users: SecurityContextHolder.getContext().getAuthentication().getName() Your User data model might look Something like this: @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(unique = true) private String sub; ... } If we now want to get The User Object of the authenticated User, we would have to do something like this:...