Skip to content

Commit

Permalink
Merge branch 'develop' into dev-extpersist
Browse files Browse the repository at this point in the history
  • Loading branch information
gongycn committed Aug 1, 2024
2 parents ba72d4d + 3967c91 commit 1d0c97c
Show file tree
Hide file tree
Showing 196 changed files with 5,183 additions and 1,234 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ test/logs
derby.log
yarn.lock
.flattened-pom.xml
lefthook.yml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ You can view the full documentation from the [Nacos website](https://nacos.io/en

You can also read this online eBook from the [NACOS ARCHITECTURE & PRINCIPLES](https://www.yuque.com/nacos/ebook/kbyo6n).

All the latest and long-term notice can also be found here from [Github notice issue](https://github.com/alibaba/nacos/labels/notice).
All the latest and long-term notice can also be found here from [GitHub notice issue](https://github.com/alibaba/nacos/labels/notice).

## Contributing

Expand Down Expand Up @@ -134,7 +134,7 @@ https://cn.aliyun.com/product/aliware/mse?spm=nacos-website.topbar.0.0.0
## Download

- [Nacos Official Website](https://nacos.io/download/nacos-server)
- [Github Release](https://github.com/alibaba/nacos/releases)
- [GitHub Release](https://github.com/alibaba/nacos/releases)

## Who is using

Expand Down
4 changes: 4 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-util</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public class PropertyKeyConst {

public static final String LOG_ALL_PROPERTIES = "logAllProperties";

/**
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
*/
public static final String IS_USE_RAM_INFO_PARSING = "isUseRamInfoParsing";

/**
* Get the key value of some variable value from the system property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public interface SystemPropertyKeyConst {
* It is also supported by the -D parameter.
*/
String IS_USE_ENDPOINT_PARSING_RULE = "nacos.use.endpoint.parsing.rule";

/**
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
*/
String IS_USE_RAM_INFO_PARSING = "nacos.use.ram.info.parsing";
}
15 changes: 12 additions & 3 deletions api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -243,6 +247,11 @@ public class Constants {

public static final String CONFIG_GRAY_LABEL = "nacos.config.gray.label";

/**
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
*/
public static final String DEFAULT_USE_RAM_INFO_PARSING = "true";

/**
* The constants in config directory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,7 +109,7 @@ void testParseResourceWithConfigType() throws NoSuchMethodException {
Resource actual = httpProtocolAuthService.parseResource(request, secured);
assertEquals(SignType.CONFIG, actual.getType());
assertEquals("testD", actual.getName());
assertEquals("testCNs", actual.getNamespaceId());
assertEquals("testNNs", actual.getNamespaceId());
assertEquals("testCG", actual.getGroup());
assertNotNull(actual.getProperties());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.auth.config;

import com.alibaba.nacos.auth.mock.MockAuthPluginServiceB;
import com.alibaba.nacos.sys.module.ModuleState;
import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -45,7 +46,6 @@ class AuthModuleStateBuilderTest {
void setUp() throws Exception {
when(context.getBean(AuthConfigs.class)).thenReturn(authConfigs);
ApplicationUtils.injectContext(context);
when(authConfigs.getNacosAuthSystemType()).thenReturn("nacos");
}

@AfterEach
Expand All @@ -54,10 +54,32 @@ void tearDown() throws Exception {

@Test
void testBuild() {
when(authConfigs.getNacosAuthSystemType()).thenReturn("nacos");

ModuleState actual = new AuthModuleStateBuilder().build();
assertFalse((Boolean) actual.getStates().get(AUTH_ENABLED));
assertFalse((Boolean) actual.getStates().get("login_page_enabled"));
assertEquals("nacos", actual.getStates().get("auth_system_type"));
assertTrue((Boolean) actual.getStates().get("auth_admin_request"));

when(authConfigs.getNacosAuthSystemType()).thenReturn(MockAuthPluginServiceB.TEST_PLUGIN);
ModuleState actual2 = new AuthModuleStateBuilder().build();
assertTrue((Boolean) actual2.getStates().get("login_page_enabled"));
assertEquals(MockAuthPluginServiceB.TEST_PLUGIN, actual2.getStates().get("auth_system_type"));
assertFalse((Boolean) actual2.getStates().get("auth_admin_request"));
}

@Test
void testCacheable() {
AuthModuleStateBuilder authModuleStateBuilder = new AuthModuleStateBuilder();
authModuleStateBuilder.build();
boolean cacheable = authModuleStateBuilder.isCacheable();
assertFalse(cacheable);

when(authConfigs.getNacosAuthSystemType()).thenReturn(MockAuthPluginServiceB.TEST_PLUGIN);
AuthModuleStateBuilder authModuleStateBuilder2 = new AuthModuleStateBuilder();
authModuleStateBuilder2.build();
boolean cacheable2 = authModuleStateBuilder2.isCacheable();
assertTrue(cacheable2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.auth.mock;

import com.alibaba.nacos.plugin.auth.api.IdentityContext;
import com.alibaba.nacos.plugin.auth.api.Permission;
import com.alibaba.nacos.plugin.auth.api.Resource;
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
import com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService;

import java.util.Collection;
import java.util.Collections;

public class MockAuthPluginServiceB implements AuthPluginService {

public static final String TEST_PLUGIN = "testB";

public static final String IDENTITY_TEST_KEY = "identity-test-key";

@Override
public Collection<String> identityNames() {
return Collections.singletonList(IDENTITY_TEST_KEY);
}

@Override
public boolean enableAuth(ActionTypes action, String type) {
return true;
}

@Override
public boolean validateIdentity(IdentityContext identityContext, Resource resource) {
return false;
}

@Override
public Boolean validateAuthority(IdentityContext identityContext, Permission permission) {
return false;
}

@Override
public String getAuthServiceName() {
return TEST_PLUGIN;
}

@Override
public boolean isLoginEnabled() {
return true;
}

@Override
public boolean isAdminRequest() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#

com.alibaba.nacos.auth.mock.MockAuthPluginService
com.alibaba.nacos.auth.mock.MockAuthPluginServiceB
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alibaba.nacos.client.auth.ram.injector.AbstractResourceInjector;
import com.alibaba.nacos.client.auth.ram.injector.ConfigResourceInjector;
import com.alibaba.nacos.client.auth.ram.injector.NamingResourceInjector;
import com.alibaba.nacos.client.auth.ram.utils.RamUtil;
import com.alibaba.nacos.client.auth.ram.utils.SpasAdapter;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.auth.api.LoginIdentityContext;
Expand Down Expand Up @@ -76,13 +77,11 @@ private void loadRoleName(Properties properties) {
}

private void loadAccessKey(Properties properties) {
String accessKey = properties.getProperty(PropertyKeyConst.ACCESS_KEY);
ramContext.setAccessKey(StringUtils.isBlank(accessKey) ? SpasAdapter.getAk() : accessKey);
ramContext.setAccessKey(RamUtil.getAccessKey(properties));
}

private void loadSecretKey(Properties properties) {
String secretKey = properties.getProperty(PropertyKeyConst.SECRET_KEY);
ramContext.setSecretKey(StringUtils.isBlank(secretKey) ? SpasAdapter.getSk() : secretKey);
ramContext.setSecretKey(RamUtil.getSecretKey(properties));
}

private void loadRegionId(Properties properties) {
Expand Down
Loading

0 comments on commit 1d0c97c

Please sign in to comment.