Skip to content

Commit

Permalink
Merge branch 'develop' into release-5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
odbozhou committed Sep 23, 2022
2 parents ac82378 + 7e6bee2 commit 251fc77
Show file tree
Hide file tree
Showing 50 changed files with 1,093 additions and 698 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ $ java -version
java version "1.8.0_121"
```

For Windows users, click [here](https://archive.apache.org/dist/rocketmq/4.9.3/rocketmq-all-4.9.3-bin-release.zip) to download the 4.9.3 RocketMQ binary release,
For Windows users, click [here](https://archive.apache.org/dist/rocketmq/4.9.4/rocketmq-all-4.9.4-bin-release.zip) to download the 4.9.4 RocketMQ binary release,
unpack it to your local disk, such as `D:\rocketmq`.
For macOS and Linux users, execute following commands:
```shell
# Download release from the Apache mirror
$ wget https://archive.apache.org/dist/rocketmq/4.9.3/rocketmq-all-4.9.3-bin-release.zip
$ wget https://archive.apache.org/dist/rocketmq/4.9.4/rocketmq-all-4.9.4-bin-release.zip

# Unpack the release
$ unzip rocketmq-all-4.9.3-bin-release.zip
$ unzip rocketmq-all-4.9.4-bin-release.zip
```

Prepare a terminal and change to the extracted `bin` directory:
```shell
$ cd rocketmq-4.9.3/bin
$ cd rocketmq-4.9.4/bin
```

**1) Start NameServer**
Expand Down Expand Up @@ -168,7 +168,7 @@ name-service 1/1 107m
* [RocketMQ Flink](https://github.com/apache/rocketmq-flink): The Apache RocketMQ connector of Apache Flink that supports source and sink connector in data stream and Table.
* [RocketMQ APIs](https://github.com/apache/rocketmq-apis): RocketMQ protobuf protocol.
* [RocketMQ Clients](https://github.com/apache/rocketmq-clients): gRPC/protobuf-based RocketMQ clients.
* RocketMQ Native Protocol-Based Clients
* RocketMQ Remoting-based Clients
- [RocketMQ Client CPP](https://github.com/apache/rocketmq-client-cpp)
- [RocketMQ Client Go](https://github.com/apache/rocketmq-client-go)
- [RocketMQ Client Python](https://github.com/apache/rocketmq-client-python)
Expand Down
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ maven_install(
"io.grpc:grpc-stub:1.47.0",
"io.grpc:grpc-api:1.47.0",
"io.grpc:grpc-testing:1.47.0",
"org.springframework:spring-core:5.3.23",
],
fetch_sources = True,
repositories = [
Expand Down
44 changes: 23 additions & 21 deletions acl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,53 @@ java_library(
visibility = ["//visibility:public"],
deps = [
"//common",
"//logging",
"//remoting",
"//logging",
"//srvutil",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:commons_validator_commons_validator",
"@maven//:com_github_luben_zstd_jni",
"@maven//:org_lz4_lz4_java",
"@maven//:com_alibaba_fastjson",
"@maven//:io_netty_netty_all",
"@maven//:org_yaml_snakeyaml",
"@maven//:com_github_luben_zstd_jni",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:commons_codec_commons_codec",
"@maven//:commons_validator_commons_validator",
"@maven//:io_netty_netty_all",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_apache_rocketmq_rocketmq_proto",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_guava_guava",
"@maven//:org_lz4_lz4_java",
"@maven//:org_yaml_snakeyaml",
],
)

java_library(
name = "tests",
srcs = glob(["src/test/java/**/*.java"]),
resources = glob(["src/test/resources/**/*.yml"]),
visibility = ["//visibility:public"],
deps = [
":acl",
"//:test_deps",
"//common",
"//remoting",
"//:test_deps",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:io_netty_netty_all",
"@maven//:com_alibaba_fastjson",
"@maven//:com_google_guava_guava",
"@maven//:commons_codec_commons_codec",
"@maven//:io_netty_netty_all",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_springframework_spring_core",
"@maven//:org_yaml_snakeyaml",
"@maven//:commons_codec_commons_codec",
"@maven//:com_alibaba_fastjson",
],
resources = glob(["src/test/resources/**/*.yml"])
)

GenTestRules(
name = "GeneratedTestRules",
test_files = glob(["src/test/java/**/*Test.java"]),
deps = [
":tests",
],
# The following tests are not hermetic. Fix them later.
exclude_tests = [
"src/test/java/org/apache/rocketmq/acl/plain/PlainAccessControlFlowTest",
"src/test/java/org/apache/rocketmq/acl/plain/PlainPermissionManagerTest",
],
medium_tests = [
"src/test/java/org/apache/rocketmq/acl/plain/PlainAccessValidatorTest",
],
test_files = glob(["src/test/java/**/*Test.java"]),
deps = [
":tests",
],
)
5 changes: 5 additions & 0 deletions acl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@
<artifactId>protobuf-java-util</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class PlainPermissionManager {

public PlainPermissionManager() {
this.defaultAclDir = MixAll.dealFilePath(fileHome + File.separator + "conf" + File.separator + "acl");
this.defaultAclFile = MixAll.dealFilePath(fileHome + File.separator + System.getProperty("rocketmq.acl.plain.file", "conf/plain_acl.yml"));
this.defaultAclFile = MixAll.dealFilePath(fileHome + File.separator + System.getProperty("rocketmq.acl.plain.file", "conf" + File.separator + "plain_acl.yml"));
load();
watch();
}
Expand All @@ -96,7 +96,7 @@ public List<String> getAllAclFiles(String path) {
log.info("The default acl dir {} is not exist", path);
return new ArrayList<>();
}
List<String> allAclFileFullPath = new ArrayList<>();
List<String> allAclFileFullPath = new ArrayList<>();
File file = new File(path);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
Expand Down Expand Up @@ -165,7 +165,7 @@ public void load() {
plainAccessResourceMap.put(plainAccessResource.getAccessKey(), plainAccessResource);
accessKeyTable.put(plainAccessResource.getAccessKey(), currentFile);
} else {
log.warn("The accesssKey {} is repeated in multiple ACL files", plainAccessResource.getAccessKey());
log.warn("The accessKey {} is repeated in multiple ACL files", plainAccessResource.getAccessKey());
}
}
}
Expand Down Expand Up @@ -239,7 +239,6 @@ public void load(String aclFilePath) {
this.globalWhiteRemoteAddressStrategyMap.put(aclFilePath, globalWhiteRemoteAddressStrategy);
}


JSONArray accounts = plainAclConfData.getJSONArray(AclConstants.CONFIG_ACCOUNTS);
if (accounts != null && !accounts.isEmpty()) {
List<PlainAccessConfig> plainAccessConfigList = accounts.toJavaList(PlainAccessConfig.class);
Expand Down Expand Up @@ -270,7 +269,6 @@ public void load(String aclFilePath) {
}
}


@Deprecated
public String getAclConfigDataVersion() {
return this.dataVersion.toJson();
Expand Down Expand Up @@ -647,7 +645,6 @@ public void validate(PlainAccessResource plainAccessResource) {
}
}


// Check perm of each resource
checkPerm(plainAccessResource, ownedAccess);
}
Expand Down
116 changes: 116 additions & 0 deletions acl/src/test/java/org/apache/rocketmq/acl/plain/AclTestHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.rocketmq.acl.plain;

import com.google.common.base.Preconditions;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.UUID;
import org.junit.Assert;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

public final class AclTestHelper {
private AclTestHelper() {
}

private static void copyTo(String path, InputStream src, File dstDir, String flag, boolean into)
throws IOException {
Preconditions.checkNotNull(flag);
String[] folders = path.split(File.separator);
boolean found = false;
File dir = dstDir;
for (int i = 0; i < folders.length; i++) {
if (!found && flag.equals(folders[i])) {
found = true;
if (into) {
dir = new File(dir, flag);
if (!dir.exists()) {
Assert.assertTrue(dir.mkdirs());
}
}
continue;
}

if (found) {
if (i == folders.length - 1) {
dir = new File(dir, folders[i]);
} else {
dir = new File(dir, folders[i]);
if (!dir.exists()) {
Assert.assertTrue(dir.mkdir());
}
}
}
}

Assert.assertTrue(dir.createNewFile());
byte[] buffer = new byte[4096];
BufferedInputStream bis = new BufferedInputStream(src);
int len = 0;
try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(dir.toPath()))) {
while ((len = bis.read(buffer)) > 0) {
bos.write(buffer, 0, len);
}
}
}

public static void recursiveDelete(File file) {
if (file.isFile()) {
Assert.assertTrue(file.delete());
return;
}
File[] files = file.listFiles();
if (null != files) {
for (File f : files) {
recursiveDelete(f);
}
}
Assert.assertTrue(file.delete());
}

public static File copyResources(String folder) throws IOException {
return copyResources(folder, false);
}

public static File copyResources(String folder, boolean into) throws IOException {
File home = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString().replace('-', '_'));
if (!home.exists()) {
Assert.assertTrue(home.mkdirs());
}
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(AclTestHelper.class.getClassLoader());
Resource[] resources = resolver.getResources(String.format("classpath:%s/**/*", folder));
for (Resource resource : resources) {
if (!resource.isReadable()) {
continue;
}
String description = resource.getDescription();
int start = description.indexOf('[');
int end = description.lastIndexOf(']');
String path = description.substring(start + 1, end);
try (InputStream inputStream = resource.getInputStream()) {
copyTo(path, inputStream, home, folder, into);
}
}
return home;
}
}
Loading

0 comments on commit 251fc77

Please sign in to comment.