Search in sources :

Example 1 with GlobalValidationResult

use of org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult in project BroadleafCommerce by BroadleafCommerce.

the class RowLevelSecurityServiceImpl method validateAddRequest.

@Override
public GlobalValidationResult validateAddRequest(AdminUser currentUser, Entity entity, PersistencePackage persistencePackage) {
    GlobalValidationResult validationResult = new GlobalValidationResult(true);
    for (RowLevelSecurityProvider provider : getProviders()) {
        GlobalValidationResult providerValidation = provider.validateAddRequest(currentUser, entity, persistencePackage);
        if (providerValidation.isNotValid()) {
            validationResult.setValid(false);
            validationResult.addErrorMessage(providerValidation.getErrorMessage());
        }
    }
    return validationResult;
}
Also used : GlobalValidationResult(org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult)

Example 2 with GlobalValidationResult

use of org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult in project BroadleafCommerce by BroadleafCommerce.

the class AdminSecurityServiceRemote method securityCheck.

@Override
public void securityCheck(PersistencePackage persistencePackage, EntityOperationType operationType) throws ServiceException {
    Set<String> ceilingNames = new HashSet<String>();
    ceilingNames.add(persistencePackage.getSecurityCeilingEntityFullyQualifiedClassname());
    if (!ArrayUtils.isEmpty(persistencePackage.getSectionCrumbs())) {
        ceilingNames.addAll(CollectionUtils.transform(Arrays.asList(persistencePackage.getSectionCrumbs()), new Transformer() {

            @Override
            public Object transform(Object o) {
                return ((SectionCrumb) o).getSectionIdentifier();
            }
        }));
    }
    Entity entity = persistencePackage.getEntity();
    if (persistencePackage.getPersistencePerspectiveItems().containsKey(PersistencePerspectiveItemType.ADORNEDTARGETLIST)) {
        if (persistencePackage.getEntity() != null) {
            for (Property property : persistencePackage.getProperties()) {
                if (property.getName() != null && property.getName().endsWith(".id") && property.getValue() == null) {
                    entity.addGlobalValidationError("adornedTargetRequired");
                    throw new ValidationException(entity);
                }
            }
        }
    }
    GlobalValidationResult globalValidationResult = null;
    if (operationType.equals(EntityOperationType.UPDATE)) {
        globalValidationResult = rowLevelSecurityService.validateUpdateRequest(getPersistentAdminUser(), entity, persistencePackage);
    } else if (operationType.equals(EntityOperationType.REMOVE)) {
        globalValidationResult = rowLevelSecurityService.validateRemoveRequest(getPersistentAdminUser(), entity, persistencePackage);
    } else if (operationType.equals(EntityOperationType.ADD)) {
        globalValidationResult = rowLevelSecurityService.validateAddRequest(getPersistentAdminUser(), entity, persistencePackage);
    }
    if (globalValidationResult != null) {
        if (!globalValidationResult.isValid()) {
            if (StringUtils.isEmpty(globalValidationResult.getErrorMessage())) {
                entity.addGlobalValidationError("rowLevelSecurityFailed");
            } else {
                entity.addGlobalValidationErrors(globalValidationResult.getErrorMessages());
            }
            throw new ValidationException(entity, "Row level security check failed for " + operationType);
        }
    }
    securityCheck(ceilingNames.toArray(new String[ceilingNames.size()]), operationType);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Entity(org.broadleafcommerce.openadmin.dto.Entity) Transformer(org.springframework.cglib.core.Transformer) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) GlobalValidationResult(org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult) Property(org.broadleafcommerce.openadmin.dto.Property) HashSet(java.util.HashSet)

Example 3 with GlobalValidationResult

use of org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult in project BroadleafCommerce by BroadleafCommerce.

the class RowLevelSecurityServiceImpl method validateRemoveRequest.

@Override
public GlobalValidationResult validateRemoveRequest(AdminUser currentUser, Entity entity, PersistencePackage persistencePackage) {
    GlobalValidationResult validationResult = new GlobalValidationResult(true);
    for (RowLevelSecurityProvider provider : getProviders()) {
        GlobalValidationResult providerValidation = provider.validateRemoveRequest(currentUser, entity, persistencePackage);
        if (providerValidation.isNotValid()) {
            validationResult.setValid(false);
            validationResult.addErrorMessage(providerValidation.getErrorMessage());
        }
    }
    return validationResult;
}
Also used : GlobalValidationResult(org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult)

Example 4 with GlobalValidationResult

use of org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult in project BroadleafCommerce by BroadleafCommerce.

the class RowLevelSecurityServiceImpl method validateUpdateRequest.

@Override
public GlobalValidationResult validateUpdateRequest(AdminUser currentUser, Entity entity, PersistencePackage persistencePackage) {
    GlobalValidationResult validationResult = new GlobalValidationResult(true);
    for (RowLevelSecurityProvider provider : getProviders()) {
        GlobalValidationResult providerValidation = provider.validateUpdateRequest(currentUser, entity, persistencePackage);
        if (providerValidation.isNotValid()) {
            validationResult.setValid(false);
            validationResult.addErrorMessage(providerValidation.getErrorMessage());
        }
    }
    return validationResult;
}
Also used : GlobalValidationResult(org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult)

Aggregations

GlobalValidationResult (org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult)4 HashSet (java.util.HashSet)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 Property (org.broadleafcommerce.openadmin.dto.Property)1 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)1 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)1 Transformer (org.springframework.cglib.core.Transformer)1