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));
}
}
}
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()));
}
}
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);
}
}
}
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()));
}
}
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);
}
}
}
Aggregations