Guarded screens
With this package, @PreAuthorize on a screen of spring_boot_starter_flutter_navigation (which it brings) takes the expressions of method security. Nobody logged in goes to spring.flutter.navigation.login, and back to the screen after the login, however it happens. A logged-in user without the right gets the error screen.
Why
Which screens a user may open is one rule, wherever the navigation comes from: a tap, the browser's address bar, a deep link. The routeSecurity bean checks it for every navigation, with the application's MethodSecurityExpressionHandler, so the role hierarchy and custom expressions apply as on beans.
Example
@ScreenRoute('/admin', title: 'Admin')
@PreAuthorize("hasRole('ADMIN')")
class AdminPage extends StatelessWidget { ... }
@ScreenRoute('/login', title: 'Log in')
class LoginPage extends StatelessWidget {
const LoginPage({super.key});
// After the login, the navigation returns to the guarded screen by itself.
@override
Widget build(BuildContext context) => const LoginForm();
}
spring:
flutter:
navigation:
login: /login
The rules
- Nobody logged in goes to
spring.flutter.navigation.login, and after the next login (a form, a provider's button,restore()) back to the address that was asked for. - Without
login, such a navigation shows the error screen. - A logged-in user without the right gets the error screen.
- After a logout, the screen on top is opened again through the guards.
- In Dart configuration:
.filter(RouteSecurity.preAuthorize("hasRole('ADMIN')"))on the routes of anest. - The guard is the
routeSecuritybean, aRouteAuthorizationFilter. Without one (the navigation starter alone), a guarded route stops the start rather than open the route to everyone.
A guard hides screens on the device; the server still checks every request.