Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
Rocketmq
提交
5b640bed
R
Rocketmq
项目概览
s920243400
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
5b640bed
编写于
12月 17, 2018
作者:
Z
Zhendong Liu
提交者:
GitHub
12月 17, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #606 from githublaohu/feature_acl
Polish and rename the conf file name
上级
e3d38d7c
c1274383
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
45 addition
and
33 deletion
+45
-33
acl/src/main/java/org/apache/rocketmq/acl/common/Permission.java
.../main/java/org/apache/rocketmq/acl/common/Permission.java
+2
-1
acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessResource.java
...va/org/apache/rocketmq/acl/plain/PlainAccessResource.java
+1
-0
acl/src/main/java/org/apache/rocketmq/acl/plain/PlainPermissionLoader.java
.../org/apache/rocketmq/acl/plain/PlainPermissionLoader.java
+12
-8
acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
...ache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
+4
-2
acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
...est/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
+2
-2
acl/src/test/java/org/apache/rocketmq/acl/plain/PlainPermissionLoaderTest.java
.../apache/rocketmq/acl/plain/PlainPermissionLoaderTest.java
+14
-14
acl/src/test/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
.../apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
+8
-4
acl/src/test/resources/conf/plain_acl.yml
acl/src/test/resources/conf/plain_acl.yml
+0
-0
acl/src/test/resources/conf/plain_acl_null.yml
acl/src/test/resources/conf/plain_acl_null.yml
+0
-0
distribution/conf/plain_acl.yml
distribution/conf/plain_acl.yml
+0
-0
pom.xml
pom.xml
+2
-2
未找到文件。
acl/src/main/java/org/apache/rocketmq/acl/common/Permission.java
浏览文件 @
5b640bed
...
...
@@ -77,7 +77,8 @@ public class Permission {
}
}
public
static
void
parseResourcePerms
(
PlainAccessResource
plainAccessResource
,
Boolean
isTopic
,
List
<
String
>
resources
)
{
public
static
void
parseResourcePerms
(
PlainAccessResource
plainAccessResource
,
Boolean
isTopic
,
List
<
String
>
resources
)
{
if
(
resources
==
null
||
resources
.
isEmpty
())
{
return
;
}
...
...
acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessResource.java
浏览文件 @
5b640bed
...
...
@@ -76,6 +76,7 @@ public class PlainAccessResource implements AccessResource {
}
return
retryTopic
.
substring
(
MixAll
.
RETRY_GROUP_TOPIC_PREFIX
.
length
());
}
public
static
String
getRetryTopic
(
String
group
)
{
if
(
group
==
null
)
{
return
null
;
...
...
acl/src/main/java/org/apache/rocketmq/acl/plain/PlainPermissionLoader.java
浏览文件 @
5b640bed
...
...
@@ -45,12 +45,12 @@ public class PlainPermissionLoader {
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
ACL_PLUG_LOGGER_NAME
);
private
static
final
String
DEFAULT_PLAIN_ACL_FILE
=
"/conf/plain_acl.yml"
;
private
String
fileHome
=
System
.
getProperty
(
MixAll
.
ROCKETMQ_HOME_PROPERTY
,
System
.
getenv
(
MixAll
.
ROCKETMQ_HOME_ENV
));
//TODO rename transport to plain_acl.yml
private
String
fileName
=
System
.
getProperty
(
"rocketmq.acl.plain.file"
,
"/conf/transport.yml"
);
private
String
fileName
=
System
.
getProperty
(
"rocketmq.acl.plain.file"
,
DEFAULT_PLAIN_ACL_FILE
);
private
Map
<
String
/** AccessKey **/
,
PlainAccessResource
>
plainAccessResourceMap
=
new
HashMap
<>();
...
...
@@ -61,7 +61,6 @@ public class PlainPermissionLoader {
private
boolean
isWatchStart
;
public
PlainPermissionLoader
()
{
//TODO test what will happen if initialize failed
initialize
();
watch
();
}
...
...
@@ -97,9 +96,15 @@ public class PlainPermissionLoader {
log
.
warn
(
"Watch need jdk equal or greater than 1.7, current version is {}"
,
str
[
1
]);
return
;
}
try
{
int
fileIndex
=
fileName
.
lastIndexOf
(
"/"
)
+
1
;
String
watchDirectory
=
fileName
.
substring
(
0
,
fileIndex
);
final
String
watchFileName
=
fileName
.
substring
(
fileIndex
);
log
.
info
(
"watch directory is {} , watch directory file name is {} "
,
fileHome
+
watchDirectory
,
watchFileName
);
final
WatchService
watcher
=
FileSystems
.
getDefault
().
newWatchService
();
Path
p
=
Paths
.
get
(
fileHome
+
"/conf/"
);
Path
p
=
Paths
.
get
(
fileHome
+
watchDirectory
);
p
.
register
(
watcher
,
StandardWatchEventKinds
.
ENTRY_MODIFY
,
StandardWatchEventKinds
.
ENTRY_CREATE
);
ServiceThread
watcherServcie
=
new
ServiceThread
()
{
...
...
@@ -109,11 +114,10 @@ public class PlainPermissionLoader {
WatchKey
watchKey
=
watcher
.
take
();
List
<
WatchEvent
<?>>
watchEvents
=
watchKey
.
pollEvents
();
for
(
WatchEvent
<?>
event
:
watchEvents
)
{
//TODO use variable instead of raw text
if
(
"transport.yml"
.
equals
(
event
.
context
().
toString
())
if
(
watchFileName
.
equals
(
event
.
context
().
toString
())
&&
(
StandardWatchEventKinds
.
ENTRY_MODIFY
.
equals
(
event
.
kind
())
||
StandardWatchEventKinds
.
ENTRY_CREATE
.
equals
(
event
.
kind
())))
{
log
.
info
(
"
transprot.yml make a difference change is : "
,
event
.
toString
());
log
.
info
(
"
{} make a difference change is : {}"
,
watchFileName
,
event
.
toString
());
PlainPermissionLoader
.
this
.
clearPermissionInfo
();
initialize
();
}
...
...
@@ -126,6 +130,7 @@ public class PlainPermissionLoader {
}
}
}
@Override
public
String
getServiceName
()
{
return
"AclWatcherService"
;
...
...
@@ -240,7 +245,6 @@ public class PlainPermissionLoader {
return
;
}
//Step 3, check the signature
String
signature
=
AclUtils
.
calSignature
(
plainAccessResource
.
getContent
(),
ownedAccess
.
getSecretKey
());
if
(!
signature
.
equals
(
plainAccessResource
.
getSignature
()))
{
...
...
acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
浏览文件 @
5b640bed
...
...
@@ -32,8 +32,10 @@ public class RemoteAddressStrategyFactory {
}
public
RemoteAddressStrategy
getRemoteAddressStrategy
(
String
remoteAddr
)
{
//TODO if the white addr is not configured, should reject it.
if
(
StringUtils
.
isBlank
(
remoteAddr
)
||
"*"
.
equals
(
remoteAddr
))
{
if
(
StringUtils
.
isBlank
(
remoteAddr
))
{
throw
new
AclException
(
"Must fill in the white list address"
);
}
if
(
"*"
.
equals
(
remoteAddr
))
{
return
NULL_NET_ADDRESS_STRATEGY
;
}
if
(
remoteAddr
.
endsWith
(
"}"
))
{
...
...
acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
浏览文件 @
5b640bed
...
...
@@ -129,13 +129,13 @@ public class AclUtilsTest {
@Test
public
void
getYamlDataObjectTest
()
{
Map
<
String
,
Object
>
map
=
AclUtils
.
getYamlDataObject
(
"src/test/resources/conf/
transport
.yml"
,
Map
.
class
);
Map
<
String
,
Object
>
map
=
AclUtils
.
getYamlDataObject
(
"src/test/resources/conf/
plain_acl
.yml"
,
Map
.
class
);
Assert
.
assertFalse
(
map
.
isEmpty
());
}
@Test
(
expected
=
Exception
.
class
)
public
void
getYamlDataObjectExceptionTest
()
{
AclUtils
.
getYamlDataObject
(
"
transport
.yml"
,
Map
.
class
);
AclUtils
.
getYamlDataObject
(
"
plain_acl
.yml"
,
Map
.
class
);
}
}
acl/src/test/java/org/apache/rocketmq/acl/plain/PlainPermissionLoaderTest.java
浏览文件 @
5b640bed
...
...
@@ -63,7 +63,7 @@ public class PlainPermissionLoaderTest {
System
.
setProperty
(
"java.version"
,
"1.6.11"
);
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
System
.
setProperty
(
"romcketmq.acl.plain.fileName"
,
"/conf/
transport
.yml"
);
System
.
setProperty
(
"romcketmq.acl.plain.fileName"
,
"/conf/
plain_acl
.yml"
);
plainPermissionLoader
=
new
PlainPermissionLoader
();
}
...
...
@@ -154,16 +154,16 @@ public class PlainPermissionLoaderTest {
public
void
checkPerm
()
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
addResourceAndPerm
(
"
pub
"
,
Permission
.
PUB
);
plainPermissionLoader
.
checkPerm
(
PUBPlainAccessResource
,
p
lainAccessResource
);
plainAccessResource
.
addResourceAndPerm
(
"
sub
"
,
Permission
.
SUB
);
plainPermissionLoader
.
checkPerm
(
ANYPlainAccessResource
,
p
lainAccessResource
);
plainAccessResource
.
addResourceAndPerm
(
"
topicA
"
,
Permission
.
PUB
);
plainPermissionLoader
.
checkPerm
(
plainAccessResource
,
PUBP
lainAccessResource
);
plainAccessResource
.
addResourceAndPerm
(
"
topicB
"
,
Permission
.
SUB
);
plainPermissionLoader
.
checkPerm
(
plainAccessResource
,
ANYP
lainAccessResource
);
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
addResourceAndPerm
(
"
sub
"
,
Permission
.
SUB
);
plainPermissionLoader
.
checkPerm
(
SUBPlainAccessResource
,
p
lainAccessResource
);
plainAccessResource
.
addResourceAndPerm
(
"
pub
"
,
Permission
.
PUB
);
plainPermissionLoader
.
checkPerm
(
ANYPlainAccessResource
,
p
lainAccessResource
);
plainAccessResource
.
addResourceAndPerm
(
"
topicB
"
,
Permission
.
SUB
);
plainPermissionLoader
.
checkPerm
(
plainAccessResource
,
SUBP
lainAccessResource
);
plainAccessResource
.
addResourceAndPerm
(
"
topicA
"
,
Permission
.
PUB
);
plainPermissionLoader
.
checkPerm
(
plainAccessResource
,
ANYP
lainAccessResource
);
}
...
...
@@ -226,7 +226,7 @@ public class PlainPermissionLoaderTest {
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources/watch"
);
File
file
=
new
File
(
"src/test/resources/watch/conf"
);
file
.
mkdirs
();
File
transport
=
new
File
(
"src/test/resources/watch/conf/
transport
.yml"
);
File
transport
=
new
File
(
"src/test/resources/watch/conf/
plain_acl
.yml"
);
transport
.
createNewFile
();
FileWriter
writer
=
new
FileWriter
(
transport
);
...
...
@@ -240,9 +240,9 @@ public class PlainPermissionLoaderTest {
PlainPermissionLoader
plainPermissionLoader
=
new
PlainPermissionLoader
();
Map
<
String
,
List
<
PlainAccessResource
>>
plainAccessResourceMap
=
(
Map
<
String
,
List
<
PlainAccessResource
>>)
FieldUtils
.
readDeclaredField
(
plainPermissionLoader
,
"plainAccessResourceMap"
,
true
);
Assert
.
assert
Equals
(
plainAccessResourceMap
.
get
(
"rokcetmq"
).
size
(),
1
);
Assert
.
assert
NotNull
(
plainAccessResourceMap
.
get
(
"rokcetmq"
)
);
writer
=
new
FileWriter
(
new
File
(
"src/test/resources/watch/conf/
transport
.yml"
),
true
);
writer
=
new
FileWriter
(
new
File
(
"src/test/resources/watch/conf/
plain_acl
.yml"
),
true
);
writer
.
write
(
"- accessKey: rokcet1\r\n"
);
writer
.
write
(
" secretKey: aliyun1\r\n"
);
writer
.
write
(
" whiteRemoteAddress: 127.0.0.1\r\n"
);
...
...
@@ -256,7 +256,7 @@ public class PlainPermissionLoaderTest {
e
.
printStackTrace
();
}
plainAccessResourceMap
=
(
Map
<
String
,
List
<
PlainAccessResource
>>)
FieldUtils
.
readDeclaredField
(
plainPermissionLoader
,
"plainAccessResourceMap"
,
true
);
Assert
.
assert
Equals
(
plainAccessResourceMap
.
get
(
"rokcet1"
).
size
(),
1
);
Assert
.
assert
NotNull
(
plainAccessResourceMap
.
get
(
"rokcet1"
)
);
transport
.
delete
();
file
.
delete
();
...
...
@@ -267,7 +267,7 @@ public class PlainPermissionLoaderTest {
@Test
(
expected
=
AclException
.
class
)
public
void
initializeTest
()
{
System
.
setProperty
(
"ro
mcketmq.acl.plain.fileName"
,
"/conf/transport-
null.yml"
);
System
.
setProperty
(
"ro
cketmq.acl.plain.file"
,
"/conf/plain_acl_
null.yml"
);
new
PlainPermissionLoader
();
}
...
...
acl/src/test/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
浏览文件 @
5b640bed
...
...
@@ -24,14 +24,18 @@ public class RemoteAddressStrategyTest {
RemoteAddressStrategyFactory
remoteAddressStrategyFactory
=
new
RemoteAddressStrategyFactory
();
@Test
(
expected
=
AclException
.
class
)
public
void
netaddressStrategyFactoryExceptionTest
()
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
remoteAddressStrategyFactory
.
getRemoteAddressStrategy
(
plainAccessResource
);
}
@Test
public
void
N
etaddressStrategyFactoryTest
()
{
public
void
n
etaddressStrategyFactoryTest
()
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
RemoteAddressStrategy
remoteAddressStrategy
=
remoteAddressStrategyFactory
.
getRemoteAddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
,
RemoteAddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
plainAccessResource
.
setWhiteRemoteAddress
(
"*"
);
remoteAddressStrategy
=
remoteAddressStrategyFactory
.
getRemoteAddressStrategy
(
plainAccessResource
);
RemoteAddressStrategy
remoteAddressStrategy
=
remoteAddressStrategyFactory
.
getRemoteAddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
,
RemoteAddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
plainAccessResource
.
setWhiteRemoteAddress
(
"127.0.0.1"
);
...
...
acl/src/test/resources/conf/
transport
.yml
→
acl/src/test/resources/conf/
plain_acl
.yml
浏览文件 @
5b640bed
文件已移动
acl/src/test/resources/conf/
transport-
null.yml
→
acl/src/test/resources/conf/
plain_acl_
null.yml
浏览文件 @
5b640bed
文件已移动
distribution/conf/
transport
.yml
→
distribution/conf/
plain_acl
.yml
浏览文件 @
5b640bed
文件已移动
pom.xml
浏览文件 @
5b640bed
...
...
@@ -216,9 +216,9 @@
<execution>
<id>
generate-effective-dependencies-pom
</id>
<phase>
generate-resources
</phase>
<goals>
<
!-- <
goals>
<goal>effective-pom</goal>
</goals>
</goals>
-->
<configuration>
<output>
${project.build.directory}/effective-pom/effective-dependencies.xml
</output>
</configuration>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录