Usage
This domain service is useful both for integration testing and while running fixture scripts.
For example, to integration test a workflow system, whereby objects are moved from one user to another, it is helpful to switch the effective user to verify that the task was assigned correctly.
Or, this fixture script uses the SudoService to set up ToDoItem objects:
protected void execute(final ExecutionContext ec) {
...
sudoService.call(
InteractionContext.switchUser(UserMemento.ofName("joe")),
() -> wrap(toDoItem).completed()
);
...
}
Disabling permission checks
Sometimes it’s useful to be able to "switch off" security checks, for example when running in initial seed scripts or fixtures that use the WrapperFactory. This can be done using any user that has the special ACCESS_ALL_ROLE role.
For example:
protected void execute(final ExecutionContext ec) {
...
sudoService.call(InteractionContext.switchUser(
UserMemento.ofNameAndRoles("seed-user", SudoService.ACCESS_ALL_ROLE),
() -> { /* ... */ }
);
...
}