Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
c6297003
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
267
Star
16139
Fork
68
代码
文件
提交
分支
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看板
提交
c6297003
编写于
11月 01, 2018
作者:
L
laohu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean
上级
74f4213b
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
190 addition
and
213 deletion
+190
-213
acl-plug/pom.xml
acl-plug/pom.xml
+1
-1
acl-plug/src/main/java/org/apache/rocketmq/acl/AccessValidator.java
...rc/main/java/org/apache/rocketmq/acl/AccessValidator.java
+4
-2
acl-plug/src/main/java/org/apache/rocketmq/acl/DefaultAccessValidator.java
.../java/org/apache/rocketmq/acl/DefaultAccessValidator.java
+4
-2
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/AccessContralAnalysis.java
...a/org/apache/rocketmq/acl/plug/AccessContralAnalysis.java
+4
-3
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/Authentication.java
...ain/java/org/apache/rocketmq/acl/plug/Authentication.java
+1
-1
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/DefaultAclRemotingServiceImpl.java
...ache/rocketmq/acl/plug/DefaultAclRemotingServiceImpl.java
+17
-17
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/engine/AclPlugEngine.java
...va/org/apache/rocketmq/acl/plug/engine/AclPlugEngine.java
+2
-2
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/engine/AuthenticationInfoManagementAclPlugEngine.java
...lug/engine/AuthenticationInfoManagementAclPlugEngine.java
+23
-21
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/engine/LoginInfoAclPlugEngine.java
...ache/rocketmq/acl/plug/engine/LoginInfoAclPlugEngine.java
+2
-1
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngine.java
...g/apache/rocketmq/acl/plug/engine/PlainAclPlugEngine.java
+5
-4
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/AccessControl.java
...va/org/apache/rocketmq/acl/plug/entity/AccessControl.java
+3
-3
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/AuthenticationInfo.java
...g/apache/rocketmq/acl/plug/entity/AuthenticationInfo.java
+4
-3
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/BorkerAccessControl.java
.../apache/rocketmq/acl/plug/entity/BorkerAccessControl.java
+2
-2
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/ControllerParameters.java
...apache/rocketmq/acl/plug/entity/ControllerParameters.java
+1
-1
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/LoginInfo.java
...n/java/org/apache/rocketmq/acl/plug/entity/LoginInfo.java
+2
-2
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/strategy/NetaddressStrategyFactory.java
...rocketmq/acl/plug/strategy/NetaddressStrategyFactory.java
+3
-2
acl-plug/src/test/java/org/apache/rocketmq/acl/plug/AclRemotingServiceTest.java
.../org/apache/rocketmq/acl/plug/AclRemotingServiceTest.java
+101
-102
acl-plug/src/test/java/org/apache/rocketmq/acl/plug/AclUtilsTest.java
.../test/java/org/apache/rocketmq/acl/plug/AclUtilsTest.java
+2
-3
acl-plug/src/test/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java
...ache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java
+7
-38
broker/pom.xml
broker/pom.xml
+1
-1
broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java
...ain/java/org/apache/rocketmq/broker/BrokerController.java
+0
-1
pom.xml
pom.xml
+1
-1
未找到文件。
acl-plug/pom.xml
浏览文件 @
c6297003
...
...
@@ -18,7 +18,7 @@
<artifactId>
rocketmq-all
</artifactId>
<version>
4.4.0-SNAPSHOT
</version>
</parent>
<artifactId>
rocketmq-acl
-plug
</artifactId>
<artifactId>
rocketmq-acl
</artifactId>
<name>
rocketmq-acl-plug ${project.version}
</name>
<url>
http://maven.apache.org
</url>
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/AccessValidator.java
浏览文件 @
c6297003
...
...
@@ -22,14 +22,16 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand;
public
interface
AccessValidator
{
/**
* Parse to get the AccessResource(user, resource, needed permission)
*
* @param request
* @return
*/
AccessResource
parse
(
RemotingCommand
request
,
String
remoteAddr
);
AccessResource
parse
(
RemotingCommand
request
,
String
remoteAddr
);
/**
* Validate the access resource.
*
* @param accessResource
*/
void
validate
(
AccessResource
accessResource
)
;
void
validate
(
AccessResource
accessResource
);
}
acl-plug/src/main/java/org/apache/rocketmq/acl/DefaultAccessValidator.java
浏览文件 @
c6297003
...
...
@@ -21,11 +21,13 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand;
public
class
DefaultAccessValidator
implements
AccessValidator
{
@Override
public
AccessResource
parse
(
RemotingCommand
request
,
String
remoteAddr
)
{
@Override
public
AccessResource
parse
(
RemotingCommand
request
,
String
remoteAddr
)
{
return
null
;
}
@Override
public
void
validate
(
AccessResource
accessResource
)
{
@Override
public
void
validate
(
AccessResource
accessResource
)
{
}
}
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/AccessContralAnalysis.java
浏览文件 @
c6297003
...
...
@@ -16,14 +16,15 @@
*/
package
org.apache.rocketmq.acl.plug
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
java.lang.reflect.Field
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
public
class
AccessContralAnalysis
{
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/Authentication.java
浏览文件 @
c6297003
...
...
@@ -24,7 +24,7 @@ import org.apache.rocketmq.acl.plug.entity.BorkerAccessControl;
public
class
Authentication
{
public
boolean
authentication
(
AuthenticationInfo
authenticationInfo
,
AccessControl
accessControl
,
AuthenticationResult
authenticationResult
)
{
AccessControl
accessControl
,
AuthenticationResult
authenticationResult
)
{
int
code
=
accessControl
.
getCode
();
if
(!
authenticationInfo
.
getAuthority
().
get
(
code
))
{
authenticationResult
.
setResultString
(
String
.
format
(
"code is %d Authentication failed"
,
code
));
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/DefaultAclRemotingServiceImpl.java
浏览文件 @
c6297003
...
...
@@ -16,8 +16,6 @@
*/
package
org.apache.rocketmq.acl.plug
;
import
java.util.HashMap
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.acl.AccessResource
;
import
org.apache.rocketmq.acl.AccessValidator
;
...
...
@@ -29,16 +27,18 @@ import org.apache.rocketmq.acl.plug.entity.ControllerParameters;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
public
class
DefaultAclRemotingServiceImpl
implements
AclRemotingService
,
AccessValidator
{
import
java.util.HashMap
;
public
class
DefaultAclRemotingServiceImpl
implements
AclRemotingService
,
AccessValidator
{
private
AclPlugEngine
aclPlugEngine
;
public
DefaultAclRemotingServiceImpl
()
{
ControllerParameters
controllerParameters
=
new
ControllerParameters
();
this
.
aclPlugEngine
=
new
PlainAclPlugEngine
(
controllerParameters
);
this
.
aclPlugEngine
.
initialize
();
ControllerParameters
controllerParameters
=
new
ControllerParameters
();
this
.
aclPlugEngine
=
new
PlainAclPlugEngine
(
controllerParameters
);
this
.
aclPlugEngine
.
initialize
();
}
public
DefaultAclRemotingServiceImpl
(
AclPlugEngine
aclPlugEngine
)
{
this
.
aclPlugEngine
=
aclPlugEngine
;
}
...
...
@@ -55,9 +55,9 @@ public class DefaultAclRemotingServiceImpl implements AclRemotingService ,Access
return
authenticationResult
;
}
@Override
public
AccessResource
parse
(
RemotingCommand
request
,
String
remoteAddr
)
{
HashMap
<
String
,
String
>
extFields
=
request
.
getExtFields
();
@Override
public
AccessResource
parse
(
RemotingCommand
request
,
String
remoteAddr
)
{
HashMap
<
String
,
String
>
extFields
=
request
.
getExtFields
();
AccessControl
accessControl
=
new
AccessControl
();
accessControl
.
setCode
(
request
.
getCode
());
accessControl
.
setRecognition
(
remoteAddr
);
...
...
@@ -66,19 +66,19 @@ public class DefaultAclRemotingServiceImpl implements AclRemotingService ,Access
accessControl
.
setPassword
(
extFields
.
get
(
"password"
));
accessControl
.
setNetaddress
(
StringUtils
.
split
(
remoteAddr
,
":"
)[
0
]);
accessControl
.
setTopic
(
extFields
.
get
(
"topic"
));
}
return
accessControl
;
}
}
return
accessControl
;
}
@Override
public
void
validate
(
AccessResource
accessResource
)
{
AuthenticationResult
authenticationResult
=
aclPlugEngine
.
eachCheckAuthentication
((
AccessControl
)
accessResource
);
@Override
public
void
validate
(
AccessResource
accessResource
)
{
AuthenticationResult
authenticationResult
=
aclPlugEngine
.
eachCheckAuthentication
((
AccessControl
)
accessResource
);
if
(
authenticationResult
.
getException
()
!=
null
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"eachCheck the inspection appear exception, accessControl data is %s"
,
accessResource
.
toString
()),
authenticationResult
.
getException
());
}
if
(
authenticationResult
.
getAccessControl
()
==
null
||
!
authenticationResult
.
isSucceed
())
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"%s accessControl data is %s"
,
authenticationResult
.
getResultString
(),
accessResource
.
toString
()));
}
}
}
}
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/engine/AclPlugEngine.java
浏览文件 @
c6297003
...
...
@@ -30,8 +30,8 @@ public interface AclPlugEngine {
public
void
deleteLoginInfo
(
String
remoteAddr
);
public
AuthenticationResult
eachCheckLoginAndAuthentication
(
AccessControl
accessControl
);
public
AuthenticationResult
eachCheckAuthentication
(
AccessControl
accessControl
);
public
AuthenticationResult
eachCheckAuthentication
(
AccessControl
accessControl
);
public
void
initialize
();
}
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/engine/AuthenticationInfoManagementAclPlugEngine.java
浏览文件 @
c6297003
...
...
@@ -20,6 +20,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.rocketmq.acl.plug.AccessContralAnalysis
;
import
org.apache.rocketmq.acl.plug.Authentication
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
...
...
@@ -61,10 +62,10 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
accessControlMap
.
put
(
accessControl
.
getAccount
(),
accessControlAddressList
);
}
AuthenticationInfo
authenticationInfo
=
new
AuthenticationInfo
(
accessContralAnalysis
.
analysis
(
accessControl
),
accessControl
,
netaddressStrategy
);
accessControlAddressList
.
add
(
authenticationInfo
);
accessControlAddressList
.
add
(
authenticationInfo
);
log
.
info
(
"authenticationInfo is {}"
,
authenticationInfo
.
toString
());
}
catch
(
Exception
e
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"Exception info %s %s"
,
e
.
getMessage
()
,
accessControl
.
toString
()),
e
);
throw
new
AclPlugRuntimeException
(
String
.
format
(
"Exception info %s %s"
,
e
.
getMessage
()
,
accessControl
.
toString
()),
e
);
}
}
...
...
@@ -90,11 +91,11 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
}
else
{
List
<
AuthenticationInfo
>
accessControlAddressList
=
accessControlMap
.
get
(
accessControl
.
getAccount
());
if
(
accessControlAddressList
!=
null
)
{
for
(
AuthenticationInfo
ai
:
accessControlAddressList
)
{
if
(
ai
.
getNetaddressStrategy
().
match
(
accessControl
)&&
ai
.
getAccessControl
().
getPassword
().
equals
(
accessControl
.
getPassword
()))
{
return
ai
;
}
}
for
(
AuthenticationInfo
ai
:
accessControlAddressList
)
{
if
(
ai
.
getNetaddressStrategy
().
match
(
accessControl
)
&&
ai
.
getAccessControl
().
getPassword
().
equals
(
accessControl
.
getPassword
()))
{
return
ai
;
}
}
}
}
return
null
;
...
...
@@ -115,19 +116,20 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
}
return
authenticationResult
;
}
public
AuthenticationResult
eachCheckAuthentication
(
AccessControl
accessControl
)
{
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
AuthenticationInfo
authenticationInfo
=
getAccessControl
(
accessControl
);
if
(
authenticationInfo
!=
null
)
{
boolean
boo
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
authenticationResult
.
setSucceed
(
boo
);
}
else
{
authenticationResult
.
setResultString
(
"accessControl is null, Please check login, password, IP\""
);
}
return
authenticationResult
;
public
AuthenticationResult
eachCheckAuthentication
(
AccessControl
accessControl
)
{
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
AuthenticationInfo
authenticationInfo
=
getAccessControl
(
accessControl
);
if
(
authenticationInfo
!=
null
)
{
boolean
boo
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
authenticationResult
.
setSucceed
(
boo
);
authenticationResult
.
setAccessControl
(
authenticationInfo
.
getAccessControl
());
}
else
{
authenticationResult
.
setResultString
(
"accessControl is null, Please check login, password, IP\""
);
}
return
authenticationResult
;
}
void
setBorkerAccessControlTransport
(
BorkerAccessControlTransport
transport
)
{
...
...
@@ -146,5 +148,5 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
}
protected
abstract
AuthenticationInfo
getAuthenticationInfo
(
AccessControl
accessControl
,
AuthenticationResult
authenticationResult
);
AuthenticationResult
authenticationResult
);
}
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/engine/LoginInfoAclPlugEngine.java
浏览文件 @
c6297003
...
...
@@ -18,6 +18,7 @@ package org.apache.rocketmq.acl.plug.engine;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.entity.AuthenticationInfo
;
import
org.apache.rocketmq.acl.plug.entity.AuthenticationResult
;
...
...
@@ -53,7 +54,7 @@ public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagemen
}
protected
AuthenticationInfo
getAuthenticationInfo
(
AccessControl
accessControl
,
AuthenticationResult
authenticationResult
)
{
AuthenticationResult
authenticationResult
)
{
LoginInfo
loginInfo
=
getLoginInfo
(
accessControl
);
if
(
loginInfo
!=
null
&&
loginInfo
.
getAuthenticationInfo
()
!=
null
)
{
return
loginInfo
.
getAuthenticationInfo
();
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngine.java
浏览文件 @
c6297003
...
...
@@ -16,18 +16,19 @@
*/
package
org.apache.rocketmq.acl.plug.engine
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport
;
import
org.apache.rocketmq.acl.plug.entity.ControllerParameters
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.yaml.snakeyaml.Yaml
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
public
class
PlainAclPlugEngine
extends
LoginInfoAclPlugEngine
{
public
PlainAclPlugEngine
(
ControllerParameters
controllerParameters
)
throws
AclPlugRuntimeException
{
ControllerParameters
controllerParameters
)
throws
AclPlugRuntimeException
{
super
(
controllerParameters
);
}
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/AccessControl.java
浏览文件 @
c6297003
...
...
@@ -18,7 +18,7 @@ package org.apache.rocketmq.acl.plug.entity;
import
org.apache.rocketmq.acl.AccessResource
;
public
class
AccessControl
implements
AccessResource
{
public
class
AccessControl
implements
AccessResource
{
private
String
account
;
...
...
@@ -87,8 +87,8 @@ public class AccessControl implements AccessResource{
public
String
toString
()
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"AccessControl [account="
).
append
(
account
).
append
(
", password="
).
append
(
password
)
.
append
(
", netaddress="
).
append
(
netaddress
).
append
(
", recognition="
).
append
(
recognition
)
.
append
(
", code="
).
append
(
code
).
append
(
", topic="
).
append
(
topic
).
append
(
"]"
);
.
append
(
", netaddress="
).
append
(
netaddress
).
append
(
", recognition="
).
append
(
recognition
)
.
append
(
", code="
).
append
(
code
).
append
(
", topic="
).
append
(
topic
).
append
(
"]"
);
return
builder
.
toString
();
}
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/AuthenticationInfo.java
浏览文件 @
c6297003
...
...
@@ -16,10 +16,11 @@
*/
package
org.apache.rocketmq.acl.plug.entity
;
import
org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy
;
public
class
AuthenticationInfo
{
...
...
@@ -30,7 +31,7 @@ public class AuthenticationInfo {
private
Map
<
Integer
,
Boolean
>
authority
;
public
AuthenticationInfo
(
Map
<
Integer
,
Boolean
>
authority
,
AccessControl
accessControl
,
NetaddressStrategy
netaddressStrategy
)
{
NetaddressStrategy
netaddressStrategy
)
{
super
();
this
.
authority
=
authority
;
this
.
accessControl
=
accessControl
;
...
...
@@ -65,7 +66,7 @@ public class AuthenticationInfo {
public
String
toString
()
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"AuthenticationInfo [accessControl="
).
append
(
accessControl
).
append
(
", netaddressStrategy="
)
.
append
(
netaddressStrategy
).
append
(
", authority={"
);
.
append
(
netaddressStrategy
).
append
(
", authority={"
);
Iterator
<
Entry
<
Integer
,
Boolean
>>
it
=
authority
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
Entry
<
Integer
,
Boolean
>
e
=
it
.
next
();
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/BorkerAccessControl.java
浏览文件 @
c6297003
...
...
@@ -556,8 +556,8 @@ public class BorkerAccessControl extends AccessControl {
public
String
toString
()
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"BorkerAccessControl [permitSendTopic="
).
append
(
permitSendTopic
).
append
(
", noPermitSendTopic="
)
.
append
(
noPermitSendTopic
).
append
(
", permitPullTopic="
).
append
(
permitPullTopic
)
.
append
(
", noPermitPullTopic="
).
append
(
noPermitPullTopic
);
.
append
(
noPermitSendTopic
).
append
(
", permitPullTopic="
).
append
(
permitPullTopic
)
.
append
(
", noPermitPullTopic="
).
append
(
noPermitPullTopic
);
if
(!!
sendMessage
)
builder
.
append
(
", sendMessage="
).
append
(
sendMessage
);
if
(!!
sendMessageV2
)
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/ControllerParameters.java
浏览文件 @
c6297003
...
...
@@ -45,7 +45,7 @@ public class ControllerParameters {
public
String
toString
()
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"ControllerParametersEntity [fileHome="
).
append
(
fileHome
).
append
(
", accessContralAnalysisClass="
)
.
append
(
accessContralAnalysisClass
).
append
(
"]"
);
.
append
(
accessContralAnalysisClass
).
append
(
"]"
);
return
builder
.
toString
();
}
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/entity/LoginInfo.java
浏览文件 @
c6297003
...
...
@@ -74,8 +74,8 @@ public class LoginInfo {
public
String
toString
()
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"LoginInfo [recognition="
).
append
(
recognition
).
append
(
", loginTime="
).
append
(
loginTime
)
.
append
(
", operationTime="
).
append
(
operationTime
).
append
(
", clear="
).
append
(
clear
)
.
append
(
", authenticationInfo="
).
append
(
authenticationInfo
).
append
(
"]"
);
.
append
(
", operationTime="
).
append
(
operationTime
).
append
(
", clear="
).
append
(
clear
)
.
append
(
", authenticationInfo="
).
append
(
authenticationInfo
).
append
(
"]"
);
return
builder
.
toString
();
}
...
...
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/strategy/NetaddressStrategyFactory.java
浏览文件 @
c6297003
...
...
@@ -16,13 +16,14 @@
*/
package
org.apache.rocketmq.acl.plug.strategy
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.acl.plug.AclUtils
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
java.util.HashSet
;
import
java.util.Set
;
public
class
NetaddressStrategyFactory
{
public
static
final
NullNetaddressStrategy
NULL_NET_ADDRESS_STRATEGY
=
new
NullNetaddressStrategy
();
...
...
acl-plug/src/test/java/org/apache/rocketmq/acl/plug/AclRemotingServiceTest.java
浏览文件 @
c6297003
...
...
@@ -15,23 +15,23 @@ import org.junit.Test;;
public
class
AclRemotingServiceTest
{
AclRemotingService
defaultAclService
;
AccessValidator
accessValidator
;
AccessControl
accessControl
;
AclRemotingService
defaultAclService
;
AccessValidator
accessValidator
;
AccessControl
accessControl
;
AccessControl
accessControlTwo
;
@Before
public
void
init
()
{
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
DefaultAclRemotingServiceImpl
aclRemotingServiceImpl
=
new
DefaultAclRemotingServiceImpl
();
defaultAclService
=
aclRemotingServiceImpl
;
accessValidator
=
aclRemotingServiceImpl
;
accessControl
=
new
BorkerAccessControl
();
@Before
public
void
init
()
{
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
DefaultAclRemotingServiceImpl
aclRemotingServiceImpl
=
new
DefaultAclRemotingServiceImpl
();
defaultAclService
=
aclRemotingServiceImpl
;
accessValidator
=
aclRemotingServiceImpl
;
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"RocketMQ"
);
accessControl
.
setPassword
(
"1234567"
);
accessControl
.
setNetaddress
(
"192.0.0.1"
);
...
...
@@ -42,91 +42,90 @@ public class AclRemotingServiceTest {
accessControlTwo
.
setPassword
(
"1234567"
);
accessControlTwo
.
setNetaddress
(
"192.0.2.1"
);
accessControlTwo
.
setRecognition
(
"127.0.0.1:2"
);
}
@Test
public
void
defaultConstructorTest
()
{
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
AclRemotingService
defaultAclService
=
new
DefaultAclRemotingServiceImpl
();
Assert
.
assertNotNull
(
defaultAclService
);
}
@Test
public
void
parseTest
()
{
RemotingCommand
remotingCommand
=
RemotingCommand
.
createResponseCommand
(
34
,
""
);
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"account"
,
"RocketMQ"
);
map
.
put
(
"password"
,
"123456"
);
map
.
put
(
"topic"
,
"test"
);
remotingCommand
.
setExtFields
(
map
);
AccessResource
accessResource
=
accessValidator
.
parse
(
remotingCommand
,
"127.0.0.1:123"
);
AccessControl
accessControl
=
(
AccessControl
)
accessResource
;
AccessControl
newAccessControl
=
new
AccessControl
();
newAccessControl
.
setAccount
(
"RocketMQ"
);
newAccessControl
.
setPassword
(
"123456"
);
newAccessControl
.
setTopic
(
"test"
);
newAccessControl
.
setCode
(
34
);
newAccessControl
.
setNetaddress
(
"127.0.0.1"
);
newAccessControl
.
setRecognition
(
"127.0.0.1:123"
);
Assert
.
assertEquals
(
accessControl
.
toString
(),
newAccessControl
.
toString
());
}
@Test
public
void
checkTest
()
{
accessControl
.
setCode
(
34
);
AuthenticationResult
authenticationResult
=
defaultAclService
.
check
(
accessControl
);
Assert
.
assertTrue
(
authenticationResult
.
isSucceed
());
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
checkAccessExceptionTest
()
{
accessControl
.
setCode
(
34
);
accessControl
.
setAccount
(
"Rocketmq"
);
defaultAclService
.
check
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
checkPasswordTest
()
{
accessControl
.
setCode
(
34
);
accessControl
.
setPassword
(
"123123123"
);
defaultAclService
.
check
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
checkCodeTest
()
{
accessControl
.
setCode
(
14434
);
accessControl
.
setPassword
(
"123123123"
);
defaultAclService
.
check
(
accessControl
);
}
@Test
public
void
validateTest
()
{
accessControl
.
setCode
(
34
);
accessValidator
.
validate
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
validateAccessExceptionTest
()
{
accessControl
.
setCode
(
34
);
accessControl
.
setAccount
(
"Rocketmq"
);
accessValidator
.
validate
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
validatePasswordTest
()
{
accessControl
.
setCode
(
34
);
accessControl
.
setPassword
(
"123123123"
);
accessValidator
.
validate
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
validateCodeTest
()
{
accessControl
.
setCode
(
14434
);
accessControl
.
setPassword
(
"123123123"
);
accessValidator
.
validate
(
accessControl
);
}
}
@Test
public
void
defaultConstructorTest
()
{
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
AclRemotingService
defaultAclService
=
new
DefaultAclRemotingServiceImpl
();
Assert
.
assertNotNull
(
defaultAclService
);
}
@Test
public
void
parseTest
()
{
RemotingCommand
remotingCommand
=
RemotingCommand
.
createResponseCommand
(
34
,
""
);
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"account"
,
"RocketMQ"
);
map
.
put
(
"password"
,
"123456"
);
map
.
put
(
"topic"
,
"test"
);
remotingCommand
.
setExtFields
(
map
);
AccessResource
accessResource
=
accessValidator
.
parse
(
remotingCommand
,
"127.0.0.1:123"
);
AccessControl
accessControl
=
(
AccessControl
)
accessResource
;
AccessControl
newAccessControl
=
new
AccessControl
();
newAccessControl
.
setAccount
(
"RocketMQ"
);
newAccessControl
.
setPassword
(
"123456"
);
newAccessControl
.
setTopic
(
"test"
);
newAccessControl
.
setCode
(
34
);
newAccessControl
.
setNetaddress
(
"127.0.0.1"
);
newAccessControl
.
setRecognition
(
"127.0.0.1:123"
);
Assert
.
assertEquals
(
accessControl
.
toString
(),
newAccessControl
.
toString
());
}
@Test
public
void
checkTest
()
{
accessControl
.
setCode
(
34
);
AuthenticationResult
authenticationResult
=
defaultAclService
.
check
(
accessControl
);
Assert
.
assertTrue
(
authenticationResult
.
isSucceed
());
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
checkAccessExceptionTest
()
{
accessControl
.
setCode
(
34
);
accessControl
.
setAccount
(
"Rocketmq"
);
defaultAclService
.
check
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
checkPasswordTest
()
{
accessControl
.
setCode
(
34
);
accessControl
.
setPassword
(
"123123123"
);
defaultAclService
.
check
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
checkCodeTest
()
{
accessControl
.
setCode
(
14434
);
accessControl
.
setPassword
(
"123123123"
);
defaultAclService
.
check
(
accessControl
);
}
@Test
public
void
validateTest
()
{
accessControl
.
setCode
(
34
);
accessValidator
.
validate
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
validateAccessExceptionTest
()
{
accessControl
.
setCode
(
34
);
accessControl
.
setAccount
(
"Rocketmq"
);
accessValidator
.
validate
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
validatePasswordTest
()
{
accessControl
.
setCode
(
34
);
accessControl
.
setPassword
(
"123123123"
);
accessValidator
.
validate
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
validateCodeTest
()
{
accessControl
.
setCode
(
14434
);
accessControl
.
setPassword
(
"123123123"
);
accessValidator
.
validate
(
accessControl
);
}
}
acl-plug/src/test/java/org/apache/rocketmq/acl/plug/AclUtilsTest.java
浏览文件 @
c6297003
...
...
@@ -18,13 +18,12 @@ package org.apache.rocketmq.acl.plug;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.junit.MockitoJUnitRunner
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
AclUtilsTest
{
@Test
...
...
acl-plug/src/test/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java
浏览文件 @
c6297003
...
...
@@ -57,46 +57,14 @@ public class PlainAclPlugEngineTest {
@Before
public
void
init
()
throws
NoSuchFieldException
,
SecurityException
,
IOException
{
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
ControllerParameters
controllerParametersEntity
=
new
ControllerParameters
();
Yaml
ymal
=
new
Yaml
();
String
home
=
System
.
getProperty
(
MixAll
.
ROCKETMQ_HOME_PROPERTY
,
System
.
getenv
(
MixAll
.
ROCKETMQ_HOME_ENV
));
InputStream
fis
=
null
;
if
(
home
==
null
)
{
URL
url
=
PlainAclPlugEngineTest
.
class
.
getResource
(
"/"
);
home
=
url
.
toString
();
home
=
home
.
substring
(
0
,
home
.
length
()
-
1
).
replace
(
"file:/"
,
""
).
replace
(
"target/test-classes"
,
""
);
home
=
home
+
"src/test/resources"
;
if
(!
new
File
(
home
+
"/conf/transport.yml"
).
exists
())
{
home
=
"/home/travis/build/githublaohu/rocketmq/acl-plug/src/test/resources"
;
}
}
String
filePath
=
home
+
"/conf/transport.yml"
;
try
{
fis
=
new
FileInputStream
(
new
File
(
filePath
));
transport
=
ymal
.
loadAs
(
fis
,
BorkerAccessControlTransport
.
class
);
}
catch
(
Exception
e
)
{
AccessControl
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"onlyNetAddress"
);
accessControl
.
setPassword
(
"aliyun11"
);
accessControl
.
setNetaddress
(
"127.0.0.1"
);
accessControl
.
setRecognition
(
"127.0.0.1:1"
);
AccessControl
accessControlTwo
=
new
BorkerAccessControl
();
accessControlTwo
.
setAccount
(
"listTransport"
);
accessControlTwo
.
setPassword
(
"aliyun1"
);
accessControlTwo
.
setNetaddress
(
"127.0.0.1"
);
accessControlTwo
.
setRecognition
(
"127.0.0.1:2"
);
transport
=
new
BorkerAccessControlTransport
();
transport
.
setOnlyNetAddress
((
BorkerAccessControl
)
accessControl
);
}
ControllerParameters
controllerParametersEntity
=
new
ControllerParameters
();
controllerParametersEntity
.
setFileHome
(
null
);
try
{
plainAclPlugEngine
=
new
PlainAclPlugEngine
(
controllerParametersEntity
);
plainAclPlugEngine
.
initialize
();
}
catch
(
Exception
e
)
{
transport
=
ymal
.
loadAs
(
new
FileInputStream
(
new
File
(
controllerParametersEntity
.
getFileHome
()+
"/conf/transport.yml"
)),
BorkerAccessControlTransport
.
class
);
plainAclPlugEngine
=
new
PlainAclPlugEngine
(
controllerParametersEntity
);
plainAclPlugEngine
.
initialize
();
}
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"rokcetmq"
);
...
...
@@ -142,6 +110,7 @@ public class PlainAclPlugEngineTest {
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
testPlainAclPlugEngineInit
()
{
ControllerParameters
controllerParametersEntity
=
new
ControllerParameters
();
controllerParametersEntity
.
setFileHome
(
""
);
new
PlainAclPlugEngine
(
controllerParametersEntity
).
initialize
();
}
...
...
broker/pom.xml
浏览文件 @
c6297003
...
...
@@ -50,7 +50,7 @@
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
rocketmq-acl
-plug
</artifactId>
<artifactId>
rocketmq-acl
</artifactId>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
...
...
broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java
浏览文件 @
c6297003
...
...
@@ -32,7 +32,6 @@ import java.util.concurrent.ScheduledExecutorService;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.rocketmq.acl.AccessValidator
;
import
org.apache.rocketmq.acl.plug.AclPlugController
;
import
org.apache.rocketmq.broker.client.ClientHousekeepingService
;
import
org.apache.rocketmq.broker.client.ConsumerIdsChangeListener
;
import
org.apache.rocketmq.broker.client.ConsumerManager
;
...
...
pom.xml
浏览文件 @
c6297003
...
...
@@ -525,7 +525,7 @@
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
rocketmq-acl
-plug
</artifactId>
<artifactId>
rocketmq-acl
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录