mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-05-09 05:21:25 +08:00
update nacos 2.3.2 => 2.4.3
This commit is contained in:
@@ -43,13 +43,13 @@ import java.time.ZoneId;
|
||||
@EnableScheduling
|
||||
@PropertySource("/application.properties")
|
||||
public class ConsoleConfig {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ControllerMethodsCache methodsCache;
|
||||
|
||||
|
||||
@Value("${nacos.console.ui.enabled:true}")
|
||||
private boolean consoleUiEnabled;
|
||||
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ public class ConsoleConfig {
|
||||
methodsCache.initClassMethod("com.alibaba.nacos.config.server.controller");
|
||||
methodsCache.initClassMethod("com.alibaba.nacos.console.controller");
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
@@ -73,17 +73,17 @@ public class ConsoleConfig {
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public XssFilter xssFilter() {
|
||||
return new XssFilter();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
|
||||
return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(ZoneId.systemDefault().toString());
|
||||
}
|
||||
|
||||
|
||||
public boolean isConsoleUiEnabled() {
|
||||
return consoleUiEnabled;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||
* @author xiweng.yy
|
||||
*/
|
||||
public class ConsoleModuleStateBuilder implements ModuleStateBuilder {
|
||||
|
||||
|
||||
public static final String CONSOLE_MODULE = "console";
|
||||
|
||||
|
||||
private static final String CONSOLE_UI_ENABLED = "console_ui_enabled";
|
||||
|
||||
|
||||
@Override
|
||||
public ModuleState build() {
|
||||
ModuleState result = new ModuleState(CONSOLE_MODULE);
|
||||
|
||||
@@ -37,7 +37,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@RequestMapping("/v1/console/health")
|
||||
@ExtractorManager.Extractor(httpExtractor = ConsoleDefaultHttpParamExtractor.class)
|
||||
public class HealthController {
|
||||
|
||||
|
||||
/**
|
||||
* Whether the Nacos is in broken states or not, and cannot recover except by being restarted.
|
||||
*
|
||||
@@ -48,7 +48,7 @@ public class HealthController {
|
||||
public ResponseEntity<String> liveness() {
|
||||
return ResponseEntity.ok().body("OK");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ready to receive the request or not.
|
||||
*
|
||||
@@ -63,5 +63,5 @@ public class HealthController {
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result.getResultMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,20 +22,14 @@ import com.alibaba.nacos.common.model.RestResult;
|
||||
import com.alibaba.nacos.common.model.RestResultUtils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.console.paramcheck.ConsoleDefaultHttpParamExtractor;
|
||||
import com.alibaba.nacos.core.namespace.repository.NamespacePersistService;
|
||||
import com.alibaba.nacos.core.namespace.model.Namespace;
|
||||
import com.alibaba.nacos.core.namespace.repository.NamespacePersistService;
|
||||
import com.alibaba.nacos.core.paramcheck.ExtractorManager;
|
||||
import com.alibaba.nacos.core.service.NamespaceOperationService;
|
||||
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
|
||||
import com.alibaba.nacos.plugin.auth.impl.constant.AuthConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -94,8 +88,8 @@ public class NamespaceController {
|
||||
@PostMapping
|
||||
@Secured(resource = AuthConstants.CONSOLE_RESOURCE_NAME_PREFIX + "namespaces", action = ActionTypes.WRITE)
|
||||
public Boolean createNamespace(@RequestParam("customNamespaceId") String namespaceId,
|
||||
@RequestParam("namespaceName") String namespaceName,
|
||||
@RequestParam(value = "namespaceDesc", required = false) String namespaceDesc) {
|
||||
@RequestParam("namespaceName") String namespaceName,
|
||||
@RequestParam(value = "namespaceDesc", required = false) String namespaceDesc) {
|
||||
if (StringUtils.isBlank(namespaceId)) {
|
||||
namespaceId = UUID.randomUUID().toString();
|
||||
} else {
|
||||
@@ -147,8 +141,8 @@ public class NamespaceController {
|
||||
@PutMapping
|
||||
@Secured(resource = AuthConstants.CONSOLE_RESOURCE_NAME_PREFIX + "namespaces", action = ActionTypes.WRITE)
|
||||
public Boolean editNamespace(@RequestParam("namespace") String namespace,
|
||||
@RequestParam("namespaceShowName") String namespaceShowName,
|
||||
@RequestParam(value = "namespaceDesc", required = false) String namespaceDesc) {
|
||||
@RequestParam("namespaceShowName") String namespaceShowName,
|
||||
@RequestParam(value = "namespaceDesc", required = false) String namespaceDesc) {
|
||||
// contains illegal chars
|
||||
if (!namespaceNameCheckPattern.matcher(namespaceShowName).matches()) {
|
||||
return false;
|
||||
|
||||
@@ -34,9 +34,7 @@ import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.common.utils.StringUtils.FOLDER_SEPARATOR;
|
||||
import static com.alibaba.nacos.common.utils.StringUtils.TOP_PATH;
|
||||
import static com.alibaba.nacos.common.utils.StringUtils.WINDOWS_FOLDER_SEPARATOR;
|
||||
import static com.alibaba.nacos.common.utils.StringUtils.*;
|
||||
|
||||
/**
|
||||
* Server state controller.
|
||||
@@ -68,7 +66,7 @@ public class ServerStateController {
|
||||
|
||||
@GetMapping("/announcement")
|
||||
public RestResult<String> getAnnouncement(
|
||||
@RequestParam(required = false, name = "language", defaultValue = "zh-CN") String language) {
|
||||
@RequestParam(required = false, name = "language", defaultValue = "zh-CN") String language) {
|
||||
String file = ANNOUNCEMENT_FILE.substring(0, ANNOUNCEMENT_FILE.length() - 5) + "_" + language + ".conf";
|
||||
if (file.contains(TOP_PATH) || file.contains(FOLDER_SEPARATOR) || file.contains(WINDOWS_FOLDER_SEPARATOR)) {
|
||||
throw new IllegalArgumentException("Invalid filename");
|
||||
|
||||
@@ -36,7 +36,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@RequestMapping("/v2/console/health")
|
||||
@ExtractorManager.Extractor(httpExtractor = ConsoleDefaultHttpParamExtractor.class)
|
||||
public class HealthControllerV2 {
|
||||
|
||||
|
||||
/**
|
||||
* Whether the Nacos is in broken states or not, and cannot recover except by being restarted.
|
||||
*
|
||||
@@ -47,7 +47,7 @@ public class HealthControllerV2 {
|
||||
public Result<String> liveness() {
|
||||
return Result.success("ok");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ready to receive the request or not.
|
||||
*
|
||||
@@ -62,5 +62,5 @@ public class HealthControllerV2 {
|
||||
}
|
||||
return Result.failure(result.getResultMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -33,13 +33,7 @@ import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
|
||||
import com.alibaba.nacos.plugin.auth.constant.SignType;
|
||||
import com.alibaba.nacos.plugin.auth.impl.constant.AuthConstants;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -90,7 +84,7 @@ public class NamespaceControllerV2 {
|
||||
*/
|
||||
@GetMapping()
|
||||
@Secured(resource = AuthConstants.CONSOLE_RESOURCE_NAME_PREFIX
|
||||
+ "namespaces", action = ActionTypes.READ, signType = SignType.CONSOLE)
|
||||
+ "namespaces", action = ActionTypes.READ, signType = SignType.CONSOLE)
|
||||
public Result<Namespace> getNamespace(@RequestParam("namespaceId") String namespaceId) throws NacosException {
|
||||
return Result.success(namespaceOperationService.getNamespace(namespaceId));
|
||||
}
|
||||
@@ -103,7 +97,7 @@ public class NamespaceControllerV2 {
|
||||
*/
|
||||
@PostMapping
|
||||
@Secured(resource = AuthConstants.CONSOLE_RESOURCE_NAME_PREFIX
|
||||
+ "namespaces", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
|
||||
+ "namespaces", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
|
||||
public Result<Boolean> createNamespace(NamespaceForm namespaceForm) throws NacosException {
|
||||
|
||||
namespaceForm.validate();
|
||||
@@ -118,16 +112,16 @@ public class NamespaceControllerV2 {
|
||||
namespaceId = namespaceId.trim();
|
||||
if (!namespaceIdCheckPattern.matcher(namespaceId).matches()) {
|
||||
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.ILLEGAL_NAMESPACE,
|
||||
"namespaceId [" + namespaceId + "] mismatch the pattern");
|
||||
"namespaceId [" + namespaceId + "] mismatch the pattern");
|
||||
}
|
||||
if (namespaceId.length() > NAMESPACE_ID_MAX_LENGTH) {
|
||||
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.ILLEGAL_NAMESPACE,
|
||||
"too long namespaceId, over " + NAMESPACE_ID_MAX_LENGTH);
|
||||
"too long namespaceId, over " + NAMESPACE_ID_MAX_LENGTH);
|
||||
}
|
||||
// check unique
|
||||
if (namespacePersistService.tenantInfoCountByTenantId(namespaceId) > 0) {
|
||||
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.ILLEGAL_NAMESPACE,
|
||||
"the namespaceId is existed, namespaceId: " + namespaceForm.getNamespaceId());
|
||||
"the namespaceId is existed, namespaceId: " + namespaceForm.getNamespaceId());
|
||||
}
|
||||
}
|
||||
// contains illegal chars
|
||||
@@ -146,7 +140,7 @@ public class NamespaceControllerV2 {
|
||||
*/
|
||||
@PutMapping
|
||||
@Secured(resource = AuthConstants.CONSOLE_RESOURCE_NAME_PREFIX
|
||||
+ "namespaces", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
|
||||
+ "namespaces", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
|
||||
public Result<Boolean> editNamespace(NamespaceForm namespaceForm) throws NacosException {
|
||||
namespaceForm.validate();
|
||||
// contains illegal chars
|
||||
@@ -155,8 +149,8 @@ public class NamespaceControllerV2 {
|
||||
"namespaceName [" + namespaceForm.getNamespaceName() + "] contains illegal char");
|
||||
}
|
||||
return Result.success(namespaceOperationService
|
||||
.editNamespace(namespaceForm.getNamespaceId(), namespaceForm.getNamespaceName(),
|
||||
namespaceForm.getNamespaceDesc()));
|
||||
.editNamespace(namespaceForm.getNamespaceId(), namespaceForm.getNamespaceName(),
|
||||
namespaceForm.getNamespaceDesc()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +161,7 @@ public class NamespaceControllerV2 {
|
||||
*/
|
||||
@DeleteMapping
|
||||
@Secured(resource = AuthConstants.CONSOLE_RESOURCE_NAME_PREFIX
|
||||
+ "namespaces", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
|
||||
+ "namespaces", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
|
||||
public Result<Boolean> deleteNamespace(@RequestParam("namespaceId") String namespaceId) {
|
||||
return Result.success(namespaceOperationService.removeNamespace(namespaceId));
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
package com.alibaba.nacos.console.exception;
|
||||
|
||||
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
|
||||
import com.alibaba.nacos.plugin.auth.exception.AccessException;
|
||||
import com.alibaba.nacos.common.model.RestResultUtils;
|
||||
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
||||
import com.alibaba.nacos.core.utils.Commons;
|
||||
import com.alibaba.nacos.plugin.auth.exception.AccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -65,9 +65,9 @@ public class ConsoleExceptionHandler {
|
||||
LOGGER.error("CONSOLE {}", uri, e);
|
||||
if (uri.contains(Commons.NACOS_SERVER_VERSION_V2)) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(RestResultUtils.failed(HtmlUtils.htmlEscape(ExceptionUtil.getAllExceptionMsg(e), "utf-8")));
|
||||
.body(RestResultUtils.failed(HtmlUtils.htmlEscape(ExceptionUtil.getAllExceptionMsg(e), "utf-8")));
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(HtmlUtils.htmlEscape(ExceptionUtil.getAllExceptionMsg(e), "utf-8"));
|
||||
.body(HtmlUtils.htmlEscape(ExceptionUtil.getAllExceptionMsg(e), "utf-8"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,15 +52,15 @@ import java.io.IOException;
|
||||
@ControllerAdvice(annotations = {NacosApi.class})
|
||||
@ResponseBody
|
||||
public class NacosApiExceptionHandler {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NacosApiExceptionHandler.class);
|
||||
|
||||
|
||||
@ExceptionHandler(NacosApiException.class)
|
||||
public ResponseEntity<Result<String>> handleNacosApiException(NacosApiException e) {
|
||||
LOGGER.error("got exception. {} {}", e.getErrAbstract(), e.getErrMsg());
|
||||
return ResponseEntity.status(e.getErrCode()).body(new Result<>(e.getDetailErrCode(), e.getErrAbstract(), e.getErrMsg()));
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(NacosException.class)
|
||||
public ResponseEntity<Result<String>> handleNacosException(NacosException e) {
|
||||
LOGGER.error("got exception. {}", e.getErrMsg());
|
||||
@@ -72,63 +72,63 @@ public class NacosApiExceptionHandler {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return ResponseEntity.status(e.getErrCode()).body(Result.failure(ErrorCode.SERVER_ERROR, e.getMessage()));
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(HttpMessageNotReadableException.class)
|
||||
public Result<String> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return Result.failure(ErrorCode.PARAMETER_MISSING, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(HttpMessageConversionException.class)
|
||||
public Result<String> handleHttpMessageConversionException(HttpMessageConversionException e) {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(NumberFormatException.class)
|
||||
public Result<String> handleNumberFormatException(NumberFormatException e) {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public Result<String> handleIllegalArgumentException(IllegalArgumentException e) {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(MissingServletRequestParameterException.class)
|
||||
public Result<String> handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return Result.failure(ErrorCode.PARAMETER_MISSING, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(HttpMediaTypeException.class)
|
||||
public Result<String> handleHttpMediaTypeException(HttpMediaTypeException e) {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return Result.failure(ErrorCode.MEDIA_TYPE_ERROR, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.FORBIDDEN)
|
||||
@ExceptionHandler(AccessException.class)
|
||||
public Result<String> handleAccessException(AccessException e) {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return Result.failure(ErrorCode.ACCESS_DENIED, e.getErrMsg());
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(value = {DataAccessException.class, ServletException.class, IOException.class})
|
||||
public Result<String> handleDataAccessException(Exception e) {
|
||||
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
return Result.failure(ErrorCode.DATA_ACCESS_ERROR, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(Exception.class)
|
||||
public Result<String> handleOtherException(Exception e) {
|
||||
|
||||
@@ -29,15 +29,15 @@ import java.io.IOException;
|
||||
* @author onewe
|
||||
*/
|
||||
public class XssFilter extends OncePerRequestFilter {
|
||||
|
||||
|
||||
private static final String CONTENT_SECURITY_POLICY_HEADER = "Content-Security-Policy";
|
||||
|
||||
|
||||
private static final String CONTENT_SECURITY_POLICY = "script-src 'self'";
|
||||
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
|
||||
throws ServletException, IOException {
|
||||
|
||||
response.setHeader(CONTENT_SECURITY_POLICY_HEADER, CONTENT_SECURITY_POLICY);
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.List;
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class ConsoleDefaultHttpParamExtractor extends AbstractHttpParamExtractor {
|
||||
|
||||
|
||||
@Override
|
||||
public List<ParamInfo> extractParam(HttpServletRequest request) {
|
||||
ParamInfo paramInfo = new ParamInfo();
|
||||
@@ -40,7 +40,7 @@ public class ConsoleDefaultHttpParamExtractor extends AbstractHttpParamExtractor
|
||||
paramInfos.add(paramInfo);
|
||||
return paramInfos;
|
||||
}
|
||||
|
||||
|
||||
private String getAliasNamespaceId(HttpServletRequest request) {
|
||||
String namespaceId = request.getParameter("namespaceId");
|
||||
if (StringUtils.isBlank(namespaceId)) {
|
||||
@@ -48,7 +48,7 @@ public class ConsoleDefaultHttpParamExtractor extends AbstractHttpParamExtractor
|
||||
}
|
||||
return namespaceId;
|
||||
}
|
||||
|
||||
|
||||
private String getAliasNamespaceShowName(HttpServletRequest request) {
|
||||
String namespaceShowName = request.getParameter("namespaceName");
|
||||
return namespaceShowName;
|
||||
|
||||
Reference in New Issue
Block a user