Class DefaultUiComponentPolicyApplier

java.lang.Object
io.jmix.uiconstraints.security.impl.DefaultUiComponentPolicyApplier
All Implemented Interfaces:
UiComponentPolicyApplier

@NullMarked @Component("uicns_DefaultUiComponentPolicyApplier") public class DefaultUiComponentPolicyApplier extends Object implements UiComponentPolicyApplier
  • Field Details

    • POLICIES_APPLIED_KEY

      protected static final String POLICIES_APPLIED_KEY
      Key of the component data that marks a tab content the policies have already been applied to.
      See Also:
    • accessManager

      @Autowired protected AccessManager accessManager
    • uiConstraintsProperties

      @Autowired protected UiConstraintsProperties uiConstraintsProperties
  • Constructor Details

  • Method Details

    • applyUiComponentPolicies

      public void applyUiComponentPolicies(View<?> view)
      Description copied from interface: UiComponentPolicyApplier
      Applies UI component policies assigned to the current user to the given view.
      Specified by:
      applyUiComponentPolicies in interface UiComponentPolicyApplier
      Parameters:
      view - view the view to which the security policies should be applied
    • applyUiComponentPolicies

      public void applyUiComponentPolicies(com.vaadin.flow.component.Component component)
      Description copied from interface: UiComponentPolicyApplier
      Applies UI component policies assigned to the current user to the given component and its children. Intended for content created after the view has been opened, for example the content of a lazy tab or components added programmatically.

      The component must be reachable from its view through the component tree: the policies address components by a path relative to the view, so an owner has to be found for it. Nothing is applied otherwise.

      The content of a tab is the notable exception, because a JmixTabSheet keeps only the content of the selected tab in the tree, and attaches even that before the client response rather than when it is added. Use UiComponentPolicyApplier.applyUiComponentPolicies(View, Component) for content installed into a tab.

      Specified by:
      applyUiComponentPolicies in interface UiComponentPolicyApplier
      Parameters:
      component - the component to apply the policies to
    • applyUiComponentPolicies

      public void applyUiComponentPolicies(View<?> view, com.vaadin.flow.component.Component component)
      Description copied from interface: UiComponentPolicyApplier
      Applies UI component policies assigned to the current user to the given component and its children within the given view.

      Unlike UiComponentPolicyApplier.applyUiComponentPolicies(Component), the component does not have to be reachable from the view through the component tree. That matters for the content of a tab: a JmixTabSheet keeps only the content of the selected tab in the tree, so content installed into a tab that is not open can only be handed over this way. The default implementation applies the policies to the whole view, which is correct but wider than asked: an implementation that supports subtrees is expected to override it.

      Specified by:
      applyUiComponentPolicies in interface UiComponentPolicyApplier
      Parameters:
      view - the view the component belongs to
      component - the component to apply the policies to
    • applyUiComponentPoliciesToSubtree

      protected void applyUiComponentPoliciesToSubtree(View<?> view, com.vaadin.flow.component.Component subtree)
      Applies the policies of the given view to the components of the given subtree only. A policy whose component is not a part of the subtree is skipped: the subtree is only a part of the view, so most policies of the view do not belong to it.
    • isActionHolderWithin

      protected boolean isActionHolderWithin(View<?> view, String componentId, Set<com.vaadin.flow.component.Component> subtreeComponents)
      An action is considered a part of the subtree when the component holding it is. For an action of the view itself the holder is the view.
    • registerTabSelectionListeners

      protected void registerTabSelectionListeners(View<?> view, com.vaadin.flow.component.Component root)
      The content of a lazy tab is created by the tabSheet loader when the tab is selected for the first time, so the policies cannot be applied to it at view opening. The listener registered here applies them as soon as the content exists. The loader registers its own listener while the view is being loaded, hence this one is notified after the content has been created.
    • markExistingTabContentsApplied

      protected void markExistingTabContentsApplied(JmixTabSheet tabSheet)
      The contents that already exist are covered by the pass this registration belongs to, so selecting their tabs later must not apply the policies over them a second time. A lazy tab holds a placeholder until it is selected, and its real content is a different component, so marking the placeholder costs nothing.
    • onTabSelected

      protected void onTabSelected(View<?> view, JmixTabSheet.SelectedChangeEvent event)
    • isPoliciesApplied

      protected boolean isPoliciesApplied(com.vaadin.flow.component.Component content)
    • markPoliciesApplied

      protected void markPoliciesApplied(com.vaadin.flow.component.Component content)
    • collectSubtreeComponents

      protected Set<com.vaadin.flow.component.Component> collectSubtreeComponents(com.vaadin.flow.component.Component subtree)
    • reselectTabSheetIfSelectedTabHidden

      protected void reselectTabSheetIfSelectedTabHidden(com.vaadin.flow.component.Component component)
      When a Tab is hidden by a policy, and it is the currently selected tab of its JmixTabSheet, the tabSheet would keep the hidden tab selected and stay in a loading state on the client (the next tab is never activated). This selects the next accessible tab instead.

      The currently selected tab is only reselected when it is actually hidden: a visible selected tab (which may have been selected by the user or programmatically in advance) is left untouched, even if some other tab of the same tabSheet is hidden by the policy.

      Parameters:
      component - the component the VISIBLE/DENY policy has just been applied to
    • findEnclosingTabSheet

      protected @Nullable JmixTabSheet findEnclosingTabSheet(com.vaadin.flow.component.tabs.Tab tab)
      Returns the JmixTabSheet the given tab belongs to, or null if the tab is not inside a JmixTabSheet. The runtime component hierarchy is Tab -> Tabs -> JmixTabSheet.
    • selectNextVisibleTab

      protected void selectNextVisibleTab(JmixTabSheet tabSheet, com.vaadin.flow.component.tabs.Tab hiddenTab)
      Selects the next visible tab relative to the hidden tab: the closest visible tab after it, or, if there is none, the closest visible tab before it. If there are no visible tabs at all, clears the selection so that the tabSheet does not stay on a hidden tab.
      Parameters:
      tabSheet - the tabSheet whose selection must be updated
      hiddenTab - the currently selected but hidden tab that must be replaced