Rule handling improvements
This MR contains a bunch of changes, in particular to the role handling code. The changes build on each other, but can be reviewed separately. There is only one visible change in behaviour, an invalid role now causes emission of an error message. The goal was mainly to make things easier for the developer and prepare for future changes.
Just for context, I'm working on adding a rule type that checks for an integration.