public static boolean isHiddenOrReadOnly(SecurityState securityState, String attributeName) { if (securityState == null) { return false; } return securityState.getHiddenAttributes().contains(attributeName) || securityState.getReadonlyAttributes().contains(attributeName); }
public static boolean isRequired(SecurityState securityState, String attributeName) { if (securityState == null) { return false; } return securityState.getRequiredAttributes().contains(attributeName); }
public static SecurityState getOrCreateSecurityState(Entity entity) { Preconditions.checkNotNullArgument(entity, "Entity is null"); SecurityState securityState; if (entity instanceof BaseGenericIdEntity) { BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity; if (baseGenericIdEntity.__securityState == null) { baseGenericIdEntity.__securityState = new SecurityState(); } securityState = baseGenericIdEntity.__securityState; } else if (entity instanceof EmbeddableEntity) { EmbeddableEntity embeddableEntity = (EmbeddableEntity) entity; if (embeddableEntity.__securityState == null) { embeddableEntity.__securityState = new SecurityState(); } securityState = embeddableEntity.__securityState; } else { throw new IllegalArgumentException(String.format("Entity with type [%s] does not support security state", entity.getMetaClass().getName())); } return securityState; }
if (!securityState.getReadonlyAttributes().isEmpty()) { jsonObject.put(READ_ONLY_ATTRIBUTES_KEY, securityState.getReadonlyAttributes()); if (!securityState.getHiddenAttributes().isEmpty()) { jsonObject.put(HIDDEN_ATTRIBUTES_KEY, securityState.getHiddenAttributes()); if (!securityState.getRequiredAttributes().isEmpty()) { jsonObject.put(REQUIRED_ATTRIBUTES_KEY, securityState.getRequiredAttributes());
@Override public void visit(Entity entity, MetaProperty property) { MetaClass metaClass = metadata.getClassNN(entity.getClass()); if (!security.isEntityAttrReadPermitted(metaClass, property.getName())) { addInaccessibleAttribute(entity, property.getName()); if (!metadataTools.isSystem(property) && !property.isReadOnly()) { setNullPropertyValue(entity, property); } } SecurityState securityState = BaseEntityInternalAccess.getSecurityState(entity); if (securityState != null && securityState.getHiddenAttributes().contains(property.getName())) { addInaccessibleAttribute(entity, property.getName()); if (!metadataTools.isSystem(property)) { setNullPropertyValue(entity, property); } } } }
protected ComponentState calculateComponentState(Entity entity, MetaPropertyPath propertyPath) { MetaProperty[] metaProperties = propertyPath.getMetaProperties(); ComponentState componentState = new ComponentState(); for (int i = 0; i < metaProperties.length; i++) { MetaProperty metaProperty = metaProperties[i]; String name = metaProperty.getName(); SecurityState securityState = getSecurityState(entity); if (securityState != null) { componentState.hidden = test(componentState.hidden, securityState.getHiddenAttributes(), name); componentState.readOnly = test(componentState.readOnly, securityState.getReadonlyAttributes(), name); if (i == metaProperties.length - 1) { componentState.required = test(componentState.required, securityState.getRequiredAttributes(), name); } } if (i != metaProperties.length - 1) { entity = entity.getValue(name); if (entity == null) { break; } } } return componentState; }
@Override public void visit(Entity entity, MetaProperty property) { MetaClass metaClass = metadata.getClassNN(entity.getClass()); String propertyName = property.getName(); if (!security.isEntityAttrReadPermitted(metaClass, propertyName)) { addInaccessibleAttribute(entity, propertyName); if (!metadataTools.isSystem(property) && !property.isReadOnly()) { setNullPropertyValue(entity, property); } } SecurityState securityState = BaseEntityInternalAccess.getSecurityState(entity); if (securityState != null && securityState.getHiddenAttributes().contains(property.getName())) { addInaccessibleAttribute(entity, property.getName()); if (!metadataTools.isSystem(property)) { setNullPropertyValue(entity, property); } } } }
@Override public void visit(Entity entity, MetaProperty property) { MetaClass metaClass = metadata.getClassNN(entity.getClass()); if (!security.isEntityAttrReadPermitted(metaClass, property.getName())) { addInaccessibleAttribute((BaseGenericIdEntity) entity, property.getName()); if (!metadataTools.isSystem(property) && !property.isReadOnly()) { // Using reflective access to field because the attribute can be unfetched if loading not partial entities, // which is the case when in-memory constraints exist BaseEntityInternalAccess.setValue(entity, property.getName(), null); } } SecurityState securityState = BaseEntityInternalAccess.getSecurityState(entity); if (securityState != null && securityState.getHiddenAttributes().contains(property.getName())) { if (!metadataTools.isSystem(property)) { // Using reflective access to field because the attribute can be unfetched if loading not partial entities, // which is the case when in-memory constraints exist BaseEntityInternalAccess.setValue(entity, property.getName(), null); } } } }
protected void checkRequiredAttributes(Entity entity) { SecurityState securityState = getSecurityState(entity); if (securityState != null && !securityState.getRequiredAttributes().isEmpty()) { for (MetaProperty metaProperty : entity.getMetaClass().getProperties()) { String propertyName = metaProperty.getName(); if (BaseEntityInternalAccess.isRequired(securityState, propertyName) && entity.getValue(propertyName) == null) { throw new RowLevelSecurityException(format("Attribute [%s] is required for entity %s", propertyName, entity), entity.getMetaClass().getName()); } } } }