diff --git a/api/src/main/java/com/alibaba/nacos/api/common/Constants.java b/api/src/main/java/com/alibaba/nacos/api/common/Constants.java index 0d9b6a1ac69..9e9820a5590 100644 --- a/api/src/main/java/com/alibaba/nacos/api/common/Constants.java +++ b/api/src/main/java/com/alibaba/nacos/api/common/Constants.java @@ -43,10 +43,14 @@ public class Constants { public static final String NULL = ""; - public static final String DATAID = "dataId"; - + public static final String DATA_ID = "dataId"; + + public static final String TENANT = "tenant"; + public static final String GROUP = "group"; - + + public static final String NAMESPACE_ID = "namespaceId"; + public static final String LAST_MODIFIED = "Last-Modified"; public static final String ACCEPT_ENCODING = "Accept-Encoding"; diff --git a/auth/src/main/java/com/alibaba/nacos/auth/parser/grpc/ConfigGrpcResourceParser.java b/auth/src/main/java/com/alibaba/nacos/auth/parser/grpc/ConfigGrpcResourceParser.java index 78fd66e776b..eb1a5aaab8b 100644 --- a/auth/src/main/java/com/alibaba/nacos/auth/parser/grpc/ConfigGrpcResourceParser.java +++ b/auth/src/main/java/com/alibaba/nacos/auth/parser/grpc/ConfigGrpcResourceParser.java @@ -67,7 +67,7 @@ protected String getResourceName(Request request) { dataId = ((AbstractConfigRequest) request).getDataId(); } else { dataId = (String) ReflectUtils - .getFieldValue(request, com.alibaba.nacos.api.common.Constants.DATAID, StringUtils.EMPTY); + .getFieldValue(request, com.alibaba.nacos.api.common.Constants.DATA_ID, StringUtils.EMPTY); } return StringUtils.isBlank(dataId) ? StringUtils.EMPTY : dataId; } diff --git a/auth/src/main/java/com/alibaba/nacos/auth/parser/http/ConfigHttpResourceParser.java b/auth/src/main/java/com/alibaba/nacos/auth/parser/http/ConfigHttpResourceParser.java index b453638e09e..edba5189000 100644 --- a/auth/src/main/java/com/alibaba/nacos/auth/parser/http/ConfigHttpResourceParser.java +++ b/auth/src/main/java/com/alibaba/nacos/auth/parser/http/ConfigHttpResourceParser.java @@ -16,6 +16,7 @@ package com.alibaba.nacos.auth.parser.http; +import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.common.utils.NamespaceUtil; import com.alibaba.nacos.common.utils.StringUtils; @@ -31,8 +32,11 @@ public class ConfigHttpResourceParser extends AbstractHttpResourceParser { @Override protected String getNamespaceId(HttpServletRequest request) { - return NamespaceUtil.processNamespaceParameter(request.getParameter("tenant")); - + String namespaceId = request.getParameter(Constants.NAMESPACE_ID); + if (StringUtils.isBlank(namespaceId)) { + namespaceId = request.getParameter(Constants.TENANT); + } + return NamespaceUtil.processNamespaceParameter(namespaceId); } @Override @@ -43,7 +47,7 @@ protected String getGroup(HttpServletRequest request) { @Override protected String getResourceName(HttpServletRequest request) { - String dataId = request.getParameter(com.alibaba.nacos.api.common.Constants.DATAID); + String dataId = request.getParameter(com.alibaba.nacos.api.common.Constants.DATA_ID); return StringUtils.isBlank(dataId) ? StringUtils.EMPTY : dataId; } diff --git a/auth/src/test/java/com/alibaba/nacos/auth/HttpProtocolAuthServiceTest.java b/auth/src/test/java/com/alibaba/nacos/auth/HttpProtocolAuthServiceTest.java index a07048e5dc8..aaf057484d7 100644 --- a/auth/src/test/java/com/alibaba/nacos/auth/HttpProtocolAuthServiceTest.java +++ b/auth/src/test/java/com/alibaba/nacos/auth/HttpProtocolAuthServiceTest.java @@ -67,7 +67,7 @@ void setUp() throws Exception { Mockito.when(request.getParameter(eq(CommonParams.SERVICE_NAME))).thenReturn("testS"); Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testCNs"); Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testCG"); - Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD"); + Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD"); } @Test diff --git a/auth/src/test/java/com/alibaba/nacos/auth/parser/http/ConfigHttpResourceParserTest.java b/auth/src/test/java/com/alibaba/nacos/auth/parser/http/ConfigHttpResourceParserTest.java index 382daa6ac41..600dd64ed63 100644 --- a/auth/src/test/java/com/alibaba/nacos/auth/parser/http/ConfigHttpResourceParserTest.java +++ b/auth/src/test/java/com/alibaba/nacos/auth/parser/http/ConfigHttpResourceParserTest.java @@ -56,20 +56,49 @@ void testParseWithFullContext() throws NoSuchMethodException { Secured secured = getMethodSecure(); Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testNs"); Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG"); - Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD"); + Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD"); Resource actual = resourceParser.parse(request, secured); assertEquals("testNs", actual.getNamespaceId()); assertEquals("testG", actual.getGroup()); assertEquals("testD", actual.getName()); assertEquals(Constants.Config.CONFIG_MODULE, actual.getType()); } + + @Test + @Secured(signType = Constants.Config.CONFIG_MODULE) + void testParseWithNamespaceId() throws NoSuchMethodException { + Secured secured = getMethodSecure(); + Mockito.when(request.getParameter(eq("namespaceId"))).thenReturn("testNs"); + Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG"); + Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD"); + Resource actual = resourceParser.parse(request, secured); + assertEquals("testNs", actual.getNamespaceId()); + assertEquals("testG", actual.getGroup()); + assertEquals("testD", actual.getName()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getType()); + } + + @Test + @Secured(signType = Constants.Config.CONFIG_MODULE) + void testParseWithNamespaceIdFirst() throws NoSuchMethodException { + Secured secured = getMethodSecure(); + Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testNs"); + Mockito.when(request.getParameter(eq("namespaceId"))).thenReturn("testNsFirst"); + Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG"); + Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD"); + Resource actual = resourceParser.parse(request, secured); + assertEquals("testNsFirst", actual.getNamespaceId()); + assertEquals("testG", actual.getGroup()); + assertEquals("testD", actual.getName()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getType()); + } @Test @Secured(signType = Constants.Config.CONFIG_MODULE) void testParseWithoutNamespace() throws NoSuchMethodException { Secured secured = getMethodSecure(); Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG"); - Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD"); + Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD"); Resource actual = resourceParser.parse(request, secured); assertEquals(StringUtils.EMPTY, actual.getNamespaceId()); assertEquals("testG", actual.getGroup()); @@ -82,7 +111,7 @@ void testParseWithoutNamespace() throws NoSuchMethodException { void testParseWithoutGroup() throws NoSuchMethodException { Secured secured = getMethodSecure(); Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testNs"); - Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD"); + Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD"); Resource actual = resourceParser.parse(request, secured); assertEquals("testNs", actual.getNamespaceId()); assertEquals(StringUtils.EMPTY, actual.getGroup());