Search in sources :

Example 21 with CrudEntityContext

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()));
    }
}
Also used : CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext)

Example 22 with CrudEntityContext

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;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) EntityAttributeContext(io.jmix.core.accesscontext.EntityAttributeContext)

Example 23 with CrudEntityContext

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();
}
Also used : CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) Report(io.jmix.reports.entity.Report)

Example 24 with CrudEntityContext

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;
}
Also used : PermissionsInfo(io.jmix.rest.impl.service.filter.data.PermissionsInfo) PermissionsController(io.jmix.rest.impl.controller.PermissionsController) MetaClass(io.jmix.core.metamodel.model.MetaClass) PermissionsInfo(io.jmix.rest.impl.service.filter.data.PermissionsInfo) EntityAttributeContext(io.jmix.core.accesscontext.EntityAttributeContext) AccessManager(io.jmix.core.AccessManager) SpecificOperationAccessContext(io.jmix.core.accesscontext.SpecificOperationAccessContext) Autowired(org.springframework.beans.factory.annotation.Autowired) Metadata(io.jmix.core.Metadata) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) List(java.util.List) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) CurrentUserSubstitution(io.jmix.core.usersubstitution.CurrentUserSubstitution) SpecificPolicyInfoRegistry(io.jmix.core.security.SpecificPolicyInfoRegistry) ShortPermissionInfo(io.jmix.rest.impl.service.filter.data.ShortPermissionInfo) SpecificOperationAccessContext(io.jmix.core.accesscontext.SpecificOperationAccessContext) EntityAttributeContext(io.jmix.core.accesscontext.EntityAttributeContext) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) ShortPermissionInfo(io.jmix.rest.impl.service.filter.data.ShortPermissionInfo) SpecificPolicyInfoRegistry(io.jmix.core.security.SpecificPolicyInfoRegistry) MetaClass(io.jmix.core.metamodel.model.MetaClass) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 25 with CrudEntityContext

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);
    }
}
Also used : CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) RestAPIException(io.jmix.rest.exception.RestAPIException)

Aggregations

CrudEntityContext (io.jmix.core.accesscontext.CrudEntityContext)26 MetaClass (io.jmix.core.metamodel.model.MetaClass)9 EntityAttributeContext (io.jmix.core.accesscontext.EntityAttributeContext)4 AttributeLocalizationFragment (io.jmix.dynattrui.screen.localization.AttributeLocalizationFragment)4 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 AccessDeniedException (io.jmix.core.security.AccessDeniedException)3 ArrayList (java.util.ArrayList)3 CategoryAttrsFragment (io.jmix.dynattrui.screen.categoryattr.CategoryAttrsFragment)2 AttributeLocationFragment (io.jmix.dynattrui.screen.location.AttributeLocationFragment)2 UiSetting (io.jmix.uidata.entity.UiSetting)2 UiTablePresentation (io.jmix.uidata.entity.UiTablePresentation)2 UUID (java.util.UUID)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 Attribute (org.dom4j.Attribute)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)1 AccessManager (io.jmix.core.AccessManager)1 Metadata (io.jmix.core.Metadata)1