use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class AdminPermissionCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = checkPermissionName(persistencePackage);
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(AdminPermission.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
AdminPermission adminInstance = (AdminPermission) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
adminInstance = (AdminPermission) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance = dynamicEntityDao.merge(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class AdminPermissionCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
if (persistencePackage.getEntity().findProperty("id") != null && !StringUtils.isEmpty(persistencePackage.getEntity().findProperty("id").getValue())) {
return update(persistencePackage, dynamicEntityDao, helper);
}
Entity entity = checkPermissionName(persistencePackage);
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
AdminPermission adminInstance = (AdminPermission) Class.forName(entity.getType()[0]).newInstance();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(AdminPermission.class.getName(), persistencePerspective);
adminInstance = (AdminPermission) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance = dynamicEntityDao.merge(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class AdminUserCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(AdminUser.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
AdminUser adminInstance = (AdminUser) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
Entity errorEntity = validateLegalUsernameAndEmail(entity, adminInstance, false);
if (errorEntity != null) {
return errorEntity;
}
String passwordBefore = adminInstance.getPassword();
adminInstance.setPassword(null);
adminInstance = (AdminUser) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
Property passwordProperty = entity.getPMap().get("password");
if (passwordProperty != null) {
if (StringUtils.isNotEmpty(passwordProperty.getValue())) {
adminInstance.setUnencodedPassword(passwordProperty.getValue());
adminInstance.setPassword(null);
} else {
adminInstance.setPassword(passwordBefore);
}
}
validateUserUpdateSecurity(persistencePackage, adminInstance);
adminInstance = adminSecurityService.saveAdminUser(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class AdminUserCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.ADD);
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
AdminUser adminInstance = (AdminUser) Class.forName(entity.getType()[0]).newInstance();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(AdminUser.class.getName(), persistencePerspective);
adminInstance = (AdminUser) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
Entity errorEntity = validateLegalUsernameAndEmail(entity, adminInstance, true);
if (errorEntity != null) {
return errorEntity;
}
adminInstance.setUnencodedPassword(adminInstance.getPassword());
adminInstance.setPassword(null);
adminInstance = adminSecurityService.saveAdminUser(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity 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);
}
Aggregations