Skip to content

Commit

Permalink
[ISSUE alibaba#10583]修复权限 (alibaba#10587)
Browse files Browse the repository at this point in the history
* 修复权限

* 修改为console

* 修改为console
  • Loading branch information
985492783 authored and wukong121 committed Aug 3, 2023
1 parent 3767c84 commit 579940a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest;
import com.alibaba.nacos.api.config.remote.response.ClientConfigMetricResponse;
import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.common.http.Callback;
import com.alibaba.nacos.common.http.HttpClientBeanHolder;
import com.alibaba.nacos.common.http.HttpUtils;
Expand All @@ -34,6 +35,8 @@
import com.alibaba.nacos.core.remote.ConnectionManager;
import com.alibaba.nacos.core.utils.GenericType;
import com.alibaba.nacos.core.utils.Loggers;
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
import com.alibaba.nacos.plugin.auth.constant.SignType;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -76,6 +79,7 @@ public ClientMetricsController(ServerMemberManager serverMemberManager, Connecti
* @return ResponseEntity
*/
@GetMapping("/cluster")
@Secured(resource = Constants.METRICS_CONTROLLER_PATH, action = ActionTypes.READ, signType = SignType.CONFIG)
public ResponseEntity metric(@RequestParam("ip") String ip,
@RequestParam(value = "dataId", required = false) String dataId,
@RequestParam(value = "group", required = false) String group,
Expand Down Expand Up @@ -132,6 +136,7 @@ public void onCancel() {
* Get client config listener lists of subscriber in local machine.
*/
@GetMapping("/current")
@Secured(resource = Constants.METRICS_CONTROLLER_PATH, action = ActionTypes.READ, signType = SignType.CONFIG)
public Map<String, Object> getClientMetrics(@RequestParam("ip") String ip,
@RequestParam(value = "dataId", required = false) String dataId,
@RequestParam(value = "group", required = false) String group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.plugin.auth.constant.SignType;
import com.alibaba.nacos.sys.utils.ApplicationUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -70,6 +71,7 @@ public ConfigOpsController(DumpService dumpService) {
* Manually trigger dump of a local configuration file.
*/
@PostMapping(value = "/localCache")
@Secured(resource = Constants.OPS_CONTROLLER_PATH, action = ActionTypes.WRITE, signType = SignType.CONSOLE)
public String updateLocalCacheFromStore() {
LOGGER.info("start to dump all data from store.");
dumpService.dumpAll();
Expand All @@ -78,6 +80,7 @@ public String updateLocalCacheFromStore() {
}

@PutMapping(value = "/log")
@Secured(resource = Constants.OPS_CONTROLLER_PATH, action = ActionTypes.WRITE, signType = SignType.CONSOLE)
public String setLogLevel(@RequestParam String logName, @RequestParam String logLevel) {
LogUtil.setLogLevel(logName, logLevel);
return HttpServletResponse.SC_OK + "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

package com.alibaba.nacos.config.server.controller;

import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.GroupkeyListenserStatus;
import com.alibaba.nacos.config.server.model.SampleResult;
import com.alibaba.nacos.config.server.service.ConfigSubService;
import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
import com.alibaba.nacos.plugin.auth.constant.SignType;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -50,6 +53,7 @@ public ListenerController(ConfigSubService configSubService) {
* Get subscribe information from client side.
*/
@GetMapping
@Secured(resource = Constants.LISTENER_CONTROLLER_PATH, action = ActionTypes.READ, signType = SignType.CONFIG)
public GroupkeyListenserStatus getAllSubClientConfigByIp(@RequestParam("ip") String ip,
@RequestParam(value = "all", required = false) boolean all,
@RequestParam(value = "tenant", required = false) String tenant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
import com.alibaba.nacos.core.utils.Commons;
import com.alibaba.nacos.core.utils.Loggers;
import com.alibaba.nacos.plugin.auth.constant.SignType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand Down Expand Up @@ -80,6 +81,7 @@ public RestResult<Map<String, Map<Object, Object>>> idInfo() {
}

@PutMapping(value = "/log")
@Secured(action = ActionTypes.WRITE, resource = "nacos/admin", signType = SignType.CONSOLE)
public String setLogLevel(@RequestParam String logName, @RequestParam String logLevel) {
Loggers.setLogLevel(logName, logLevel);
return HttpServletResponse.SC_OK + "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.core.controller;

import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.common.model.RestResultUtils;
import com.alibaba.nacos.common.utils.JacksonUtils;
Expand All @@ -26,6 +27,8 @@
import com.alibaba.nacos.core.cluster.ServerMemberManager;
import com.alibaba.nacos.core.utils.Commons;
import com.alibaba.nacos.core.utils.Loggers;
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
import com.alibaba.nacos.plugin.auth.constant.SignType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -52,6 +55,7 @@ public NacosClusterController(ServerMemberManager memberManager) {
}

@GetMapping(value = "/self")
@Secured(resource = Commons.NACOS_CORE_CONTEXT + "/cluster", action = ActionTypes.READ, signType = SignType.CONSOLE)
public RestResult<Member> self() {
return RestResultUtils.success(memberManager.getSelf());
}
Expand All @@ -63,6 +67,7 @@ public RestResult<Member> self() {
* @return all members
*/
@GetMapping(value = "/nodes")
@Secured(resource = Commons.NACOS_CORE_CONTEXT + "/cluster", action = ActionTypes.READ, signType = SignType.CONSOLE)
public RestResult<Collection<Member>> listNodes(
@RequestParam(value = "keyword", required = false) String ipKeyWord) {
Collection<Member> members = memberManager.allMembers();
Expand All @@ -86,11 +91,13 @@ public RestResult<Collection<Member>> listNodes(
// cluster according to this interface

@GetMapping(value = "/simple/nodes")
@Secured(resource = Commons.NACOS_CORE_CONTEXT + "/cluster", action = ActionTypes.READ, signType = SignType.CONSOLE)
public RestResult<Collection<String>> listSimpleNodes() {
return RestResultUtils.success(memberManager.getMemberAddressInfos());
}

@GetMapping("/health")
@Secured(resource = Commons.NACOS_CORE_CONTEXT + "/cluster", action = ActionTypes.READ, signType = SignType.CONSOLE)
public RestResult<String> getHealth() {
return RestResultUtils.success(memberManager.getSelf().getState().name());
}
Expand All @@ -103,6 +110,7 @@ public RestResult<String> getHealth() {
*/
@Deprecated
@PostMapping(value = {"/report"})
@Secured(resource = Commons.NACOS_CORE_CONTEXT + "/cluster", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
public RestResult<String> report(@RequestBody Member node) {
if (!node.check()) {
return RestResultUtils.failedWithMsg(400, "Node information is illegal");
Expand All @@ -121,6 +129,7 @@ public RestResult<String> report(@RequestBody Member node) {
* @return {@link RestResult}
*/
@PostMapping(value = "/switch/lookup")
@Secured(resource = Commons.NACOS_CORE_CONTEXT + "/cluster", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
public RestResult<String> switchLookup(@RequestParam(name = "type") String type) {
try {
memberManager.switchLookup(type);
Expand All @@ -138,6 +147,7 @@ public RestResult<String> switchLookup(@RequestParam(name = "type") String type)
* @throws Exception {@link Exception}
*/
@PostMapping("/server/leave")
@Secured(resource = Commons.NACOS_CORE_CONTEXT + "/cluster", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
public RestResult<String> leave(@RequestBody Collection<String> params,
@RequestParam(defaultValue = "true") Boolean notifyOtherMembers) throws Exception {
return RestResultUtils.failed(405, "/v1/core/cluster/server/leave API not allow to use temporarily.");
Expand Down

0 comments on commit 579940a

Please sign in to comment.