This use case cannot be done using the default role based access control (RBAC) functionality, as the user permissions are changing dynamically at runtime depending on some data associated to the user.
This is actually the use case for which Access Control Lists (ACLs) where designed for.
Spring security has support for ACLs by adding the spring-acl jar. This is a quote from the spring security manual Acl section:
Complex applications often will find the need to define access permissions not simply at a web request or
method invocation level. Instead, security decisions need to comprise both who (Authentication),
where (MethodInvocation) and what (SomeDomainObject). In other words, authorization
decisions also need to consider the actual domain object instance subject of a method invocation.
See the spring security manual section 16.1 for the details on how Spring security ACLs work. This is a tutorial on how to use Spring security ACLs.
But Spring ACLs imply 4 extra database tables, etc. so if this is a one only case in your application, it is probably better be to create a custom decision manager with some harcoded rules.
But if this use case is frequent in your application you should consider switching to ACLs instead of RBAC, hope this helps.