Search in sources :

Example 1 with UiPermissionValue

use of com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue in project cuba by cuba-platform.

the class WindowCreationHelper method applyCompositeComponentPermission.

private static void applyCompositeComponentPermission(Window window, String screenId, Integer permissionValue, String componentId) {
    final Matcher matcher = INNER_COMPONENT_PATTERN.matcher(componentId);
    if (matcher.find()) {
        final String customComponentId = matcher.group(1);
        final String subComponentId = matcher.group(2);
        final Component compositeComponent = window.getComponent(customComponentId);
        if (compositeComponent != null) {
            if (compositeComponent instanceof Component.UiPermissionAware) {
                Component.UiPermissionAware uiPermissionAwareComponent = (Component.UiPermissionAware) compositeComponent;
                UiPermissionValue uiPermissionValue = UiPermissionValue.fromId(permissionValue);
                UiPermissionDescriptor permissionDescriptor;
                if (subComponentId.contains("<")) {
                    final Matcher actionMatcher = COMPONENT_ACTION_PATTERN.matcher(subComponentId);
                    if (actionMatcher.find()) {
                        final String actionHolderComponentId = actionMatcher.group(1);
                        final String actionId = actionMatcher.group(2);
                        permissionDescriptor = new UiPermissionDescriptor(uiPermissionValue, screenId, actionHolderComponentId, actionId);
                    } else {
                        log.warn(String.format("Incorrect permission definition for component %s in window %s", subComponentId, screenId));
                        return;
                    }
                } else {
                    permissionDescriptor = new UiPermissionDescriptor(uiPermissionValue, screenId, subComponentId);
                }
                uiPermissionAwareComponent.applyPermission(permissionDescriptor);
            }
        } else {
            log.info(String.format("Couldn't find component %s in window %s", componentId, screenId));
        }
    }
}
Also used : UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) Matcher(java.util.regex.Matcher) Component(com.haulmont.cuba.gui.components.Component) UiPermissionDescriptor(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor)

Example 2 with UiPermissionValue

use of com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue in project cuba by cuba-platform.

the class WebAccordion method applyPermission.

@Override
public void applyPermission(UiPermissionDescriptor permissionDescriptor) {
    Preconditions.checkNotNullArgument(permissionDescriptor);
    final String subComponentId = permissionDescriptor.getSubComponentId();
    final Accordion.Tab tab = getTab(subComponentId);
    if (tab != null) {
        UiPermissionValue permissionValue = permissionDescriptor.getPermissionValue();
        if (permissionValue == UiPermissionValue.HIDE) {
            tab.setVisible(false);
        } else if (permissionValue == UiPermissionValue.READ_ONLY) {
            tab.setEnabled(false);
        }
    } else {
        LoggerFactory.getLogger(WebAccordion.class).info(String.format("Couldn't find component %s in window %s", subComponentId, permissionDescriptor.getScreenId()));
    }
}
Also used : UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) CubaAccordion(com.haulmont.cuba.web.toolkit.ui.CubaAccordion) Accordion(com.haulmont.cuba.gui.components.Accordion)

Example 3 with UiPermissionValue

use of com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue in project cuba by cuba-platform.

the class WebFieldGroup method applyPermission.

@Override
public void applyPermission(UiPermissionDescriptor permissionDescriptor) {
    checkNotNullArgument(permissionDescriptor);
    final Logger log = LoggerFactory.getLogger(WebFieldGroup.class);
    final String subComponentId = permissionDescriptor.getSubComponentId();
    final UiPermissionValue permissionValue = permissionDescriptor.getPermissionValue();
    final String screenId = permissionDescriptor.getScreenId();
    if (subComponentId != null) {
        final FieldGroup.FieldConfig field = getField(subComponentId);
        if (field != null) {
            if (permissionValue == UiPermissionValue.HIDE) {
                field.setVisible(false);
            } else if (permissionValue == UiPermissionValue.READ_ONLY) {
                field.setEditable(false);
            }
        } else {
            log.info("Couldn't find suitable component {} in window {} for UI security rule", subComponentId, screenId);
        }
    } else {
        final String actionHolderComponentId = permissionDescriptor.getActionHolderComponentId();
        FieldConfig fieldConfig = getField(actionHolderComponentId);
        if (fieldConfig == null || fieldConfig.getComponent() == null || !((fieldConfig.getComponent() instanceof Component.SecuredActionsHolder))) {
            log.info("Couldn't find suitable component {} in window {} for UI security rule", actionHolderComponentId, screenId);
            return;
        }
        Component fieldComponent = fieldConfig.getComponent();
        String actionId = permissionDescriptor.getActionId();
        ActionsPermissions permissions = ((SecuredActionsHolder) fieldComponent).getActionsPermissions();
        if (permissionValue == UiPermissionValue.HIDE) {
            permissions.addHiddenActionPermission(actionId);
        } else if (permissionValue == UiPermissionValue.READ_ONLY) {
            permissions.addDisabledActionPermission(actionId);
        }
    }
}
Also used : UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) CubaFieldGroup(com.haulmont.cuba.web.toolkit.ui.CubaFieldGroup) Logger(org.slf4j.Logger)

Example 4 with UiPermissionValue

use of com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue in project cuba by cuba-platform.

the class WebTabSheet method applyPermission.

@Override
public void applyPermission(UiPermissionDescriptor permissionDescriptor) {
    Preconditions.checkNotNullArgument(permissionDescriptor);
    final String subComponentId = permissionDescriptor.getSubComponentId();
    final TabSheet.Tab tab = getTab(subComponentId);
    if (tab != null) {
        UiPermissionValue permissionValue = permissionDescriptor.getPermissionValue();
        if (permissionValue == UiPermissionValue.HIDE) {
            tab.setVisible(false);
        } else if (permissionValue == UiPermissionValue.READ_ONLY) {
            tab.setEnabled(false);
        }
    } else {
        LoggerFactory.getLogger(WebTabSheet.class).info(String.format("Couldn't find component %s in window %s", subComponentId, permissionDescriptor.getScreenId()));
    }
}
Also used : UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) CubaTabSheet(com.haulmont.cuba.web.toolkit.ui.CubaTabSheet)

Example 5 with UiPermissionValue

use of com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue in project cuba by cuba-platform.

the class DesktopFieldGroup method applyPermission.

@Override
public void applyPermission(UiPermissionDescriptor permissionDescriptor) {
    checkNotNullArgument(permissionDescriptor);
    final String subComponentId = permissionDescriptor.getSubComponentId();
    final UiPermissionValue permissionValue = permissionDescriptor.getPermissionValue();
    final String screenId = permissionDescriptor.getScreenId();
    if (subComponentId != null) {
        final FieldGroup.FieldConfig field = getField(subComponentId);
        if (field != null) {
            if (permissionValue == UiPermissionValue.HIDE) {
                field.setVisible(false);
            } else if (permissionValue == UiPermissionValue.READ_ONLY) {
                field.setEditable(false);
            }
        } else {
            log.info("Couldn't find suitable component {} in window {} for UI security rule", subComponentId, screenId);
        }
    } else {
        final String actionHolderComponentId = permissionDescriptor.getActionHolderComponentId();
        FieldConfig fieldConfig = getField(actionHolderComponentId);
        if (fieldConfig == null || fieldConfig.getComponent() == null || !((fieldConfig.getComponent() instanceof Component.SecuredActionsHolder))) {
            log.info("Couldn't find suitable component {} in window {} for UI security rule", actionHolderComponentId, screenId);
            return;
        }
        Component fieldComponent = fieldConfig.getComponent();
        String actionId = permissionDescriptor.getActionId();
        ActionsPermissions permissions = ((SecuredActionsHolder) fieldComponent).getActionsPermissions();
        if (permissionValue == UiPermissionValue.HIDE) {
            permissions.addHiddenActionPermission(actionId);
        } else if (permissionValue == UiPermissionValue.READ_ONLY) {
            permissions.addDisabledActionPermission(actionId);
        }
    }
}
Also used : UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) Component(com.haulmont.cuba.gui.components.Component)

Aggregations

UiPermissionValue (com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue)6 Component (com.haulmont.cuba.gui.components.Component)2 UiPermissionDescriptor (com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor)1 Accordion (com.haulmont.cuba.gui.components.Accordion)1 TabSheet (com.haulmont.cuba.gui.components.TabSheet)1 CubaAccordion (com.haulmont.cuba.web.toolkit.ui.CubaAccordion)1 CubaFieldGroup (com.haulmont.cuba.web.toolkit.ui.CubaFieldGroup)1 CubaTabSheet (com.haulmont.cuba.web.toolkit.ui.CubaTabSheet)1 Matcher (java.util.regex.Matcher)1 Logger (org.slf4j.Logger)1