This is a the classic problem. I've been interested in this for some time now and I'm not aware of any standard model that really solves it out of the box (yet).
RBAC can be adapted to work for your situation by introducing parameters. There are several names that these adaptions go by, the most common is parameterized RBAC (pRBAC). I've also seen names such as Context Aware RBAC, Object Aware RBAC and relational RBAC, which are different incarnations of the same basic idea. Unfortunately, some of these terms, because there is no standardization or consensus, also refer to other access models.
There are several pRBAC concepts floating around, which all differ in detail but are still largely the same idea.
You could take a look at the papers A Design for Parameterized Roles by Mei Ge and Sylvia L. Osborn. A formal model has been described by Ali E. Abdallah and Etienne J. Khayat in their paper A Formal Model for Parameterized Role-Based Access Control.
Just as in standard RBAC, in pRBAC, a subject is assigned a role. The role consists of one or more permissions, each permission consists of an operation, object pair.
In extension to RBAC, pRBAC allows objects to have parameters and users to be initialized for a certain role with parameter values for an object they have a permission on in that role.
So, for example, the object studentCourseResult
would be assigned the parameter studentId
. Instead of have a role named Teacher
you would define the role TeacherOf
with parameter values studentId = {1, 2, 7, 9, 11}
.
If the parameter value for the object is within the set of parameter values assigned to a subject for this role, access is granted.
Note that it is an easy step from here to not only allow the =
operator for parameter constraints, but also allow >
, <
, <=
, etc.
Other than pRBAC you could take a look at Attribute Based Access Control (ABAC), which is quite fashionable at the moment (but it is solving a different problem and creating new ones) and authoriZation Based Access Control (ZBAC) which is definitely a very interesting concept, but likely an overkill for the use case you describe, as it mostly (and very neatly) solves the problem of cross domain authorization.