Basically I want to implement a filter after the JWT token is parsed and before the method is called with the ability to modify the authentication object based on an http header
Context
In our application we have (among others) three entities related to authentication/authorization: Users, Permissions and Groups. Permissions can be directly assigned to an user or could be assigned to one of the groups a user belongs to.
Given this a JWT token looks like this:
{
"username": "duck",
"groups": [
{
"name": "swimmer",
"permissions": [
"swim"
]
},
{
"name": "walker",
"permissions": [
"walk"
]
}
],
"permissions": [
"quack"
]
}
The JWT flow is setup extending AuthorizationServerConfigurerAdapter and ResourceServerConfigurerAdapter, and the permissions are extracted from the map of JWT claims by extending DefaultUserAuthenticationConverter
By using @EnableGlobalMethodSecurity(prePostEnabled = true) in the configuration I am able to annotate methods with @PreAuthorize
For example:
@PreAuthorize("hasPermission('quack')")
public void quack();
This works with permissions directly assigned to the user.
However I want to receive an http header e.g: 'x-group' and add permissions from that group (if any) to the authentication object
Then, given the above 'jwt' with the http header set to swimmer I want to be able to invoke the following method:
@PreAuthorize("hasPermission('swim')")
public void