It seems it is impossible to nest authorized directives in spray due to this line: https://github.com/spray/spray/blob/76ab89c25ce6d4ff2c4b286efcc92ee02ced6eff/spray-routing/src/main/scala/spray/routing/directives/SecurityDirectives.scala#L55
I'm referring to doing things like this:
val route = {
...
authorize(userIsAdmin) {
path("generic" / "admin" / "stuff") { ... } ~
path("users" / Segment) { u =>
authorize(canModifyUser) {
...
}
} ~
path("quotas") {
authorize(canModifyQuotas) {
...
}
}
}
}
One could of course refactor this to include userIsAdmin into the canModifyUser and canModifyQuota checks, but with orthogonal access rights, that could get out of hand fast.
What is the reason for that line? It doesn't seem logical to me why we are cancelling any further authorization failures.
Full disclosure: The route will actually get rejected if one of the nested checks fail, but it will give a 404 error (EmptyRejection) instead of the expected AuthorizationFailedRejection.