Joost Klitsie
11/11/2021, 3:52 PMJoost Klitsie
11/11/2021, 3:54 PMrouteWithRules("path", Role.Admin) { // <-- only accessible for admins
routeWithRules("sub-path", Role.User) { // <-- accessible for all users
get("/") {
respondText("All users can see this, even if it is within another route with higher restrictions")
}
}
get("something") {
respondText("Only admins can see this")
}
}
Any nested routeWithRules
added a phase to the pipeline, making sure the most inner phase would be first in the list of phases.
Then I set a flag to the context of the call, that the access rules have been overriden, so the outer routeWithRules
would skip applying their rules.
So looks like this:
At the outer routeWithRules("path", Role.Admin) {..}
We add phase "route_rules_0" to the pipeline and intercept it. We only apply the rules if the flag hasInterceptedAccessRules
is still false.
At the inner routeWithRules("sub-path", Role.User) {..}
We add phases "route_rules_1, route_rules_0" in this order. We intercept here "route_rules_1" (if hasInterceptedAccessRules
is false) and then set the flag hasInterceptedAccessRules
to true.
Any nested routeWithRules
will add a new phase in reverse order, as to override the parent rules.
In earlier ktor, if I add a phase within the routeWithRules
to the pipeline, any parent routeWithRules
would inherit the phases of the children within.
In ktor 2.0 eap 256, if I add a phase, the phase isn't added to the parents in the pipeline.
I can of course find the parent routes and add the phase manually, but did something change here? Or am I holding it wrong? 🙂Rustam Siniukov
11/11/2021, 4:00 PMinsertPhaseAfter
. can it be related?
https://github.com/ktorio/ktor/pull/2618Joost Klitsie
11/16/2021, 3:24 PM