Class SecuredVisibility
java.lang.Object
com.svenruppert.jsentinel.components.SecuredVisibility
Shared decision point for the Phase-8b secured Vaadin components
(
SecuredButton, SecuredRouterLink,
SecuredMenuItem).
The component declares a SecuredVisibility.Requirement (zero or more
required roles + zero or more required permissions) and a
SecuredVisibilityMode. On every apply(...)
call this helper:
- Resolves the current typed subject via
SubjectStores.subjectStore()and the registeredAuthenticationService.subjectType(). - Asks the registered
AuthorizationServicefor the subject's roles + permissions (the AuthorizationService is the authoritative source — the SubjectStore alone may carry a typed user without the role view). - Computes admission via
isAllowed(Requirement, HasRoles, HasPermissions). - Toggles
visible/enabledon the supplied component target.
Admission semantics — a request is admitted when:
- All required permissions are present (AND across permissions), AND
- All required roles are present (AND across roles).
SecuredVisibility.Requirement is always admitted — apps that need
"any of these roles" semantics compose the affordance with a
narrower wrapper or use one of the dedicated
@RequiresAnyPermission-style annotations on a
higher-level guard.
If no subject is bound or the security SPIs are not wired, the helper denies the affordance. UI components must never grant by default when authentication is unknown.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe slice of the current subject the components consult.static final recordWhat a secured component requires to be enabled / visible.static interfaceTarget a SecuredVisibility helper toggles. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapply(SecuredVisibility.Target target, SecuredVisibility.Requirement requirement, SecuredVisibilityMode mode) Resolves the current subject and applies the requirement totargetaccording tomode.static voidapply(SecuredVisibility.Target target, SecuredVisibility.Requirement requirement, SecuredVisibilityMode mode, Supplier<Optional<SecuredVisibility.JSentinelView>> viewSupplier) Test-friendly variant: the caller supplies the security view directly rather than going through the SPI lookup.SPI lookup: typed user via SubjectStore → roles + permissions via the registeredAuthorizationService.static booleanisAllowed(SecuredVisibility.Requirement requirement, com.svenruppert.jsentinel.authorization.api.roles.HasRoles roles, com.svenruppert.jsentinel.authorization.api.permissions.HasPermissions permissions) Computes admission from the requirement against the supplied role and permission views.
-
Method Details
-
isAllowed
public static boolean isAllowed(SecuredVisibility.Requirement requirement, com.svenruppert.jsentinel.authorization.api.roles.HasRoles roles, com.svenruppert.jsentinel.authorization.api.permissions.HasPermissions permissions) Computes admission from the requirement against the supplied role and permission views. Both arguments may benull(treated as empty).- Parameters:
requirement- non-nullroles- caller's role view; may benullpermissions- caller's permission view; may benull- Returns:
truewhen every required role and permission is present
-
apply
public static void apply(SecuredVisibility.Target target, SecuredVisibility.Requirement requirement, SecuredVisibilityMode mode) Resolves the current subject and applies the requirement totargetaccording tomode.- Parameters:
target- Vaadin component to toggle; non-nullrequirement- what the component requires; non-nullmode- hide-vs-disable on denial; non-null
-
apply
public static void apply(SecuredVisibility.Target target, SecuredVisibility.Requirement requirement, SecuredVisibilityMode mode, Supplier<Optional<SecuredVisibility.JSentinelView>> viewSupplier) Test-friendly variant: the caller supplies the security view directly rather than going through the SPI lookup.- Parameters:
target- non-nullrequirement- non-nullmode- non-nullviewSupplier- supplies the current (roles, permissions) tuple; non-null
-
currentJSentinelView
SPI lookup: typed user via SubjectStore → roles + permissions via the registeredAuthorizationService. Returns empty when any prerequisite is missing (no SPI wiring, no current subject, …) — the caller treats absence as denial.- Returns:
- current security view, if resolvable
-