|
@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.portal.controller;
|
|
|
|
|
|
import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
|
|
|
import com.ctrip.framework.apollo.common.dto.ItemDTO;
|
|
|
+import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
|
|
|
import com.ctrip.framework.apollo.common.exception.BadRequestException;
|
|
|
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
|
|
|
import com.ctrip.framework.apollo.core.enums.Env;
|
|
@@ -12,6 +13,7 @@ import com.ctrip.framework.apollo.portal.entity.model.NamespaceTextModel;
|
|
|
import com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs;
|
|
|
import com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier;
|
|
|
import com.ctrip.framework.apollo.portal.service.ItemService;
|
|
|
+import com.ctrip.framework.apollo.portal.service.NamespaceService;
|
|
|
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
|
|
|
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
@@ -38,13 +40,16 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM
|
|
|
public class ItemController {
|
|
|
|
|
|
private final ItemService configService;
|
|
|
+ private final NamespaceService namespaceService;
|
|
|
private final UserInfoHolder userInfoHolder;
|
|
|
private final PermissionValidator permissionValidator;
|
|
|
|
|
|
- public ItemController(final ItemService configService, final UserInfoHolder userInfoHolder, final PermissionValidator permissionValidator) {
|
|
|
+ public ItemController(final ItemService configService, final UserInfoHolder userInfoHolder,
|
|
|
+ final PermissionValidator permissionValidator, final NamespaceService namespaceService) {
|
|
|
this.configService = configService;
|
|
|
this.userInfoHolder = userInfoHolder;
|
|
|
this.permissionValidator = permissionValidator;
|
|
|
+ this.namespaceService = namespaceService;
|
|
|
}
|
|
|
|
|
|
@PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName, #env)")
|
|
@@ -99,9 +104,14 @@ public class ItemController {
|
|
|
public void deleteItem(@PathVariable String appId, @PathVariable String env,
|
|
|
@PathVariable String clusterName, @PathVariable String namespaceName,
|
|
|
@PathVariable long itemId) {
|
|
|
- if (itemId <= 0) {
|
|
|
- throw new BadRequestException("item id invalid");
|
|
|
+ ItemDTO item = configService.loadItemById(Env.fromString(env), itemId);
|
|
|
+ NamespaceDTO namespace = namespaceService.loadNamespaceBaseInfo(appId, Env.fromString(env), clusterName, namespaceName);
|
|
|
+
|
|
|
+ // In case someone constructs an attack scenario
|
|
|
+ if (item.getNamespaceId() != namespace.getId()) {
|
|
|
+ throw new BadRequestException("Invalid request, item and namespace do not match!");
|
|
|
}
|
|
|
+
|
|
|
configService.deleteItem(Env.valueOf(env), itemId, userInfoHolder.getUser().getUserId());
|
|
|
}
|
|
|
|