Class SecuredButton
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.button.Button
com.svenruppert.jsentinel.components.SecuredButton
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.ClickNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasSuffix, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.button.ButtonVariant>, com.vaadin.flow.component.shared.HasTooltip, Serializable
@ExperimentalJSentinelApi
public class SecuredButton
extends com.vaadin.flow.component.button.Button
Button subclass that hides or disables itself when the
current subject does not satisfy the supplied
SecuredVisibility.Requirement. Defaults to
SecuredVisibilityMode.DISABLE — primary buttons should
stay visible so the absence of the affordance does not surprise
the user.
The visibility check runs:
- on first attach (so freshly-constructed buttons land in the correct state before the user sees them), and
- whenever the app calls
refresh()— the canonical hook after a permission change.
This is a UI affordance only — the server-side handler
must still call PermissionGuard.require*
(or its annotation-driven equivalent) in the click listener.
A hidden button does not protect against a hand-crafted RPC.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
com.vaadin.flow.component.HasText.WhiteSpace -
Constructor Summary
ConstructorsConstructorDescriptionSecuredButton(String text, SecuredVisibility.Requirement requirement) Builds a secured button with the defaultSecuredVisibilityMode.DISABLEmode and SPI-backed security-view lookup.SecuredButton(String text, SecuredVisibility.Requirement requirement, SecuredVisibilityMode mode) Builds a secured button with a custom mode and SPI-backed security-view lookup.SecuredButton(String text, SecuredVisibility.Requirement requirement, SecuredVisibilityMode mode, Supplier<Optional<SecuredVisibility.JSentinelView>> viewSupplier) Full constructor — useful in tests where the caller supplies the security view directly rather than going through the SPI. -
Method Summary
Modifier and TypeMethodDescriptionfinal SecuredVisibilityModemode()protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) final voidrefresh()Re-runs the visibility check against the current subject.Methods inherited from class com.vaadin.flow.component.button.Button
addBlurListener, addFocusListener, addFocusShortcut, bindEnabled, bindText, click, clickInClient, getIcon, getText, isAutofocus, isDisableOnClick, isIconAfterText, remove, setAutofocus, setDisableOnClick, setEnabled, setIcon, setIconAfterText, setTextMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisibleMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
blur, focus, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabledMethods inherited from interface com.vaadin.flow.component.shared.HasPrefix
getPrefixComponent, setPrefixComponentMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.shared.HasSuffix
getSuffixComponent, setSuffixComponentMethods inherited from interface com.vaadin.flow.component.HasText
getWhiteSpace, setWhiteSpaceMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, bindThemeVariant, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariantsMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipMarkdown, setTooltipText
-
Constructor Details
-
SecuredButton
Builds a secured button with the defaultSecuredVisibilityMode.DISABLEmode and SPI-backed security-view lookup.- Parameters:
text- button label; non-nullrequirement- what the button requires; non-null
-
SecuredButton
public SecuredButton(String text, SecuredVisibility.Requirement requirement, SecuredVisibilityMode mode) Builds a secured button with a custom mode and SPI-backed security-view lookup.- Parameters:
text- non-null button labelrequirement- non-nullmode- non-null
-
SecuredButton
public SecuredButton(String text, SecuredVisibility.Requirement requirement, SecuredVisibilityMode mode, Supplier<Optional<SecuredVisibility.JSentinelView>> viewSupplier) Full constructor — useful in tests where the caller supplies the security view directly rather than going through the SPI.- Parameters:
text- non-null button labelrequirement- non-nullmode- non-nullviewSupplier- non-null
-
-
Method Details
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
refresh
public final void refresh()Re-runs the visibility check against the current subject. Apps call this after a permission change to keep the button's state in sync. -
requirement
- Returns:
- the requirement this button was constructed with
-
mode
- Returns:
- the visibility mode this button uses on denial
-