use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.
the class EntityQueryDataFetcher method checkCanReadEntity.
// todo methods above copypasted from 'jmix-rest'
protected void checkCanReadEntity(MetaClass metaClass) {
CrudEntityContext entityContext = applyEntityConstraints(metaClass);
if (!entityContext.isReadPermitted()) {
String exceptionMessage = String.format("Reading of the %s is forbidden", metaClass.getName());
log.warn("checkCanReadEntity: throw exception {}", exceptionMessage);
throw new GqlEntityValidationException(String.format("Reading of the %s is forbidden", metaClass.getName()));
}
}
use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.
the class SnapshotDiffViewer method loadPropertyDiff.
private EntityPropertyDifferenceModel loadPropertyDiff(EntityPropertyDifferenceModel propertyDiff, List<EntityPropertyDifferenceModel> entityPropertyDifferenceModels) {
if (propertyDiff == null) {
return null;
}
MetaClass propMetaClass = metadata.getClass(propertyDiff.getMetaClassName());
CrudEntityContext entityContext = new CrudEntityContext(propMetaClass);
accessManager.applyRegisteredConstraints(entityContext);
EntityAttributeContext attributeContext = new EntityAttributeContext(propMetaClass, propertyDiff.getPropertyName());
accessManager.applyRegisteredConstraints(attributeContext);
if (!entityContext.isReadPermitted() || !attributeContext.canView()) {
return null;
}
if (propertyDiff instanceof EntityClassPropertyDifferenceModel) {
EntityClassPropertyDifferenceModel classPropertyDiff = (EntityClassPropertyDifferenceModel) propertyDiff;
for (EntityPropertyDifferenceModel childPropertyDiff : classPropertyDiff.getPropertyDiffs()) {
EntityPropertyDifferenceModel entityPropertyDifferenceModel = loadPropertyDiff(childPropertyDiff, entityPropertyDifferenceModels);
if (entityPropertyDifferenceModel != null) {
entityPropertyDifferenceModels.add(entityPropertyDifferenceModel);
entityPropertyDifferenceModel.setParentProperty(propertyDiff);
}
}
} else if (propertyDiff instanceof EntityCollectionPropertyDifferenceModel) {
EntityCollectionPropertyDifferenceModel collectionPropertyDiff = (EntityCollectionPropertyDifferenceModel) propertyDiff;
for (EntityPropertyDifferenceModel childPropertyDiff : collectionPropertyDiff.getAddedEntities()) {
EntityPropertyDifferenceModel entityPropertyDifferenceModel = loadPropertyDiff(childPropertyDiff, entityPropertyDifferenceModels);
if (entityPropertyDifferenceModel != null) {
entityPropertyDifferenceModels.add(entityPropertyDifferenceModel);
entityPropertyDifferenceModel.setParentProperty(propertyDiff);
}
}
for (EntityPropertyDifferenceModel childPropertyDiff : collectionPropertyDiff.getModifiedEntities()) {
EntityPropertyDifferenceModel entityPropertyDifferenceModel = loadPropertyDiff(childPropertyDiff, entityPropertyDifferenceModels);
if (entityPropertyDifferenceModel != null) {
entityPropertyDifferenceModels.add(entityPropertyDifferenceModel);
entityPropertyDifferenceModel.setParentProperty(propertyDiff);
}
}
for (EntityPropertyDifferenceModel childPropertyDiff : collectionPropertyDiff.getRemovedEntities()) {
EntityPropertyDifferenceModel entityPropertyDifferenceModel = loadPropertyDiff(childPropertyDiff, entityPropertyDifferenceModels);
if (entityPropertyDifferenceModel != null) {
entityPropertyDifferenceModels.add(entityPropertyDifferenceModel);
entityPropertyDifferenceModel.setParentProperty(propertyDiff);
}
}
}
return propertyDiff;
}
use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.
the class ReportBrowser method isPermissionsToCreateReports.
private boolean isPermissionsToCreateReports() {
CrudEntityContext showScreenContext = new CrudEntityContext(metadata.getClass(Report.class));
accessManager.applyRegisteredConstraints(showScreenContext);
return showScreenContext.isCreatePermitted();
}
use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.
the class PermissionsControllerManager method getPermissions.
public PermissionsInfo getPermissions() {
PermissionsInfo permissionsInfo = new PermissionsInfo();
List<String> authorities = currentUserSubstitution.getEffectiveUser().getAuthorities().stream().map(GrantedAuthority::getAuthority).filter(Objects::nonNull).collect(Collectors.toList());
permissionsInfo.setAuthorities(authorities);
List<ShortPermissionInfo> entityPermissions = new ArrayList<>();
List<ShortPermissionInfo> entityAttributePermissions = new ArrayList<>();
permissionsInfo.setEntities(entityPermissions);
permissionsInfo.setEntityAttributes(entityAttributePermissions);
for (MetaClass metaClass : metadata.getSession().getClasses()) {
CrudEntityContext entityContext = new CrudEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
if (entityContext.isCreatePermitted()) {
entityPermissions.add(new ShortPermissionInfo(getEntityTarget(metaClass, "create"), ALLOWED_CRUD_PERMISSION));
}
if (entityContext.isReadPermitted()) {
entityPermissions.add(new ShortPermissionInfo(getEntityTarget(metaClass, "read"), ALLOWED_CRUD_PERMISSION));
}
if (entityContext.isUpdatePermitted()) {
entityPermissions.add(new ShortPermissionInfo(getEntityTarget(metaClass, "update"), ALLOWED_CRUD_PERMISSION));
}
if (entityContext.isDeletePermitted()) {
entityPermissions.add(new ShortPermissionInfo(getEntityTarget(metaClass, "delete"), ALLOWED_CRUD_PERMISSION));
}
for (MetaProperty metaProperty : metaClass.getProperties()) {
EntityAttributeContext attributeContext = new EntityAttributeContext(metaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(attributeContext);
if (attributeContext.canModify()) {
entityAttributePermissions.add(new ShortPermissionInfo(getEntityAttributeTarget(metaClass, metaProperty), MODIFY_ATTRIBUTE_PERMISSION));
} else if (attributeContext.canView()) {
entityAttributePermissions.add(new ShortPermissionInfo(getEntityAttributeTarget(metaClass, metaProperty), VIEW_ATTRIBUTE_PERMISSION));
}
}
}
List<ShortPermissionInfo> grantedSpecificPolicies = specificPolicyInfoRegistry.getSpecificPolicyInfos().stream().map(SpecificPolicyInfoRegistry.SpecificPolicyInfo::getName).filter(specificPolicyName -> {
SpecificOperationAccessContext accessContext = new SpecificOperationAccessContext(specificPolicyName);
accessManager.applyRegisteredConstraints(accessContext);
return accessContext.isPermitted();
}).map(specificPolicyName -> new ShortPermissionInfo(specificPolicyName, 1)).collect(Collectors.toList());
permissionsInfo.setSpecifics(grantedSpecificPolicies);
return permissionsInfo;
}
use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.
the class QueriesControllerManager method checkCanReadEntity.
protected void checkCanReadEntity(MetaClass metaClass) {
CrudEntityContext entityContext = new CrudEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isReadPermitted()) {
throw new RestAPIException("Reading forbidden", String.format("Reading of the %s is forbidden", metaClass.getName()), HttpStatus.FORBIDDEN);
}
}
Aggregations