Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
48c51f72
R
Rocketmq
项目概览
小五666\n哈哈
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
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看板
提交
48c51f72
编写于
11月 21, 2018
作者:
L
laohu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean
上级
1d576076
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
631 addition
and
836 deletion
+631
-836
acl/src/main/java/org/apache/rocketmq/acl/PlainAccessValidator.java
...in/java/org/apache/rocketmq/acl/PlainAccessValidator.java
+6
-8
acl/src/main/java/org/apache/rocketmq/acl/plug/AccessControl.java
...main/java/org/apache/rocketmq/acl/plug/AccessControl.java
+3
-3
acl/src/main/java/org/apache/rocketmq/acl/plug/AclPlugRuntimeException.java
...org/apache/rocketmq/acl/plug/AclPlugRuntimeException.java
+1
-1
acl/src/main/java/org/apache/rocketmq/acl/plug/AclUtils.java
acl/src/main/java/org/apache/rocketmq/acl/plug/AclUtils.java
+18
-21
acl/src/main/java/org/apache/rocketmq/acl/plug/AuthenticationInfo.java
...java/org/apache/rocketmq/acl/plug/AuthenticationInfo.java
+3
-5
acl/src/main/java/org/apache/rocketmq/acl/plug/AuthenticationResult.java
...va/org/apache/rocketmq/acl/plug/AuthenticationResult.java
+1
-1
acl/src/main/java/org/apache/rocketmq/acl/plug/BorkerAccessControl.java
...ava/org/apache/rocketmq/acl/plug/BorkerAccessControl.java
+3
-3
acl/src/main/java/org/apache/rocketmq/acl/plug/NetaddressStrategy.java
...java/org/apache/rocketmq/acl/plug/NetaddressStrategy.java
+1
-3
acl/src/main/java/org/apache/rocketmq/acl/plug/NetaddressStrategyFactory.java
...g/apache/rocketmq/acl/plug/NetaddressStrategyFactory.java
+2
-6
acl/src/main/java/org/apache/rocketmq/acl/plug/PlainAclPlugEngine.java
...java/org/apache/rocketmq/acl/plug/PlainAclPlugEngine.java
+268
-0
acl/src/main/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngine.java
...g/apache/rocketmq/acl/plug/engine/PlainAclPlugEngine.java
+0
-279
acl/src/test/java/org/apache/rocketmq/acl/plug/AccessContralAnalysisTest.java
...g/apache/rocketmq/acl/plug/AccessContralAnalysisTest.java
+0
-63
acl/src/test/java/org/apache/rocketmq/acl/plug/AclUtilsTest.java
.../test/java/org/apache/rocketmq/acl/plug/AclUtilsTest.java
+4
-2
acl/src/test/java/org/apache/rocketmq/acl/plug/AuthenticationTest.java
...java/org/apache/rocketmq/acl/plug/AuthenticationTest.java
+0
-141
acl/src/test/java/org/apache/rocketmq/acl/plug/NetaddressStrategyTest.java
.../org/apache/rocketmq/acl/plug/NetaddressStrategyTest.java
+1
-3
acl/src/test/java/org/apache/rocketmq/acl/plug/PlainAclPlugEngineTest.java
.../org/apache/rocketmq/acl/plug/PlainAclPlugEngineTest.java
+320
-0
acl/src/test/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java
...ache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java
+0
-297
未找到文件。
acl/src/main/java/org/apache/rocketmq/acl/PlainAccessValidator.java
浏览文件 @
48c51f72
...
...
@@ -17,21 +17,19 @@
package
org.apache.rocketmq.acl
;
import
java.util.HashMap
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.acl.plug.
engine.PlainAclPlugEngine
;
import
org.apache.rocketmq.acl.plug.
entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.
entity.
AuthenticationResult
;
import
org.apache.rocketmq.acl.plug.
exception.AclPlugRuntimeException
;
import
org.apache.rocketmq.acl.plug.
AccessControl
;
import
org.apache.rocketmq.acl.plug.
AclPlugRuntimeException
;
import
org.apache.rocketmq.acl.plug.AuthenticationResult
;
import
org.apache.rocketmq.acl.plug.
PlainAclPlugEngine
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
public
class
PlainAccessValidator
implements
AccessValidator
{
public
class
PlainAccessValidator
implements
AccessValidator
{
private
PlainAclPlugEngine
aclPlugEngine
;
public
PlainAccessValidator
()
{
aclPlugEngine
=
new
PlainAclPlugEngine
();
aclPlugEngine
=
new
PlainAclPlugEngine
();
}
@Override
...
...
acl/src/main/java/org/apache/rocketmq/acl/plug/
entity/
AccessControl.java
→
acl/src/main/java/org/apache/rocketmq/acl/plug/AccessControl.java
浏览文件 @
48c51f72
...
...
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.acl.plug
.entity
;
package
org.apache.rocketmq.acl.plug
;
import
org.apache.rocketmq.acl.AccessResource
;
...
...
@@ -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/src/main/java/org/apache/rocketmq/acl/plug/
exception/
AclPlugRuntimeException.java
→
acl/src/main/java/org/apache/rocketmq/acl/plug/AclPlugRuntimeException.java
浏览文件 @
48c51f72
...
...
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.acl.plug
.exception
;
package
org.apache.rocketmq.acl.plug
;
public
class
AclPlugRuntimeException
extends
RuntimeException
{
...
...
acl/src/main/java/org/apache/rocketmq/acl/plug/AclUtils.java
浏览文件 @
48c51f72
...
...
@@ -19,9 +19,7 @@ package org.apache.rocketmq.acl.plug;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.yaml.snakeyaml.Yaml
;
public
class
AclUtils
{
...
...
@@ -84,24 +82,23 @@ public class AclUtils {
return
minus
.
indexOf
(
'-'
)
>
-
1
;
}
public
static
<
T
>
T
getYamlDataObject
(
String
path
,
Class
<
T
>
clazz
)
{
Yaml
ymal
=
new
Yaml
();
FileInputStream
fis
=
null
;
try
{
fis
=
new
FileInputStream
(
new
File
(
path
));
return
ymal
.
loadAs
(
fis
,
clazz
);
}
catch
(
Exception
e
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"The transport.yml file for Plain mode was not found , paths %s"
,
path
),
e
);
}
finally
{
if
(
fis
!=
null
)
{
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
throw
new
AclPlugRuntimeException
(
"close transport fileInputStream Exception"
,
e
);
}
}
}
public
static
<
T
>
T
getYamlDataObject
(
String
path
,
Class
<
T
>
clazz
)
{
Yaml
ymal
=
new
Yaml
();
FileInputStream
fis
=
null
;
try
{
fis
=
new
FileInputStream
(
new
File
(
path
));
return
ymal
.
loadAs
(
fis
,
clazz
);
}
catch
(
Exception
e
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"The transport.yml file for Plain mode was not found , paths %s"
,
path
),
e
);
}
finally
{
if
(
fis
!=
null
)
{
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
throw
new
AclPlugRuntimeException
(
"close transport fileInputStream Exception"
,
e
);
}
}
}
}
}
acl/src/main/java/org/apache/rocketmq/acl/plug/
entity/
AuthenticationInfo.java
→
acl/src/main/java/org/apache/rocketmq/acl/plug/AuthenticationInfo.java
浏览文件 @
48c51f72
...
...
@@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.acl.plug.entity
;
import
org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy
;
package
org.apache.rocketmq.acl.plug
;
import
java.util.Iterator
;
import
java.util.Map
;
...
...
@@ -31,7 +29,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
;
...
...
@@ -66,7 +64,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/src/main/java/org/apache/rocketmq/acl/plug/
entity/
AuthenticationResult.java
→
acl/src/main/java/org/apache/rocketmq/acl/plug/AuthenticationResult.java
浏览文件 @
48c51f72
...
...
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.acl.plug
.entity
;
package
org.apache.rocketmq.acl.plug
;
public
class
AuthenticationResult
{
...
...
acl/src/main/java/org/apache/rocketmq/acl/plug/
entity/
BorkerAccessControl.java
→
acl/src/main/java/org/apache/rocketmq/acl/plug/BorkerAccessControl.java
浏览文件 @
48c51f72
...
...
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.acl.plug
.entity
;
package
org.apache.rocketmq.acl.plug
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -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/src/main/java/org/apache/rocketmq/acl/plug/
strategy/
NetaddressStrategy.java
→
acl/src/main/java/org/apache/rocketmq/acl/plug/NetaddressStrategy.java
浏览文件 @
48c51f72
...
...
@@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.acl.plug.strategy
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
package
org.apache.rocketmq.acl.plug
;
public
interface
NetaddressStrategy
{
...
...
acl/src/main/java/org/apache/rocketmq/acl/plug/
strategy/
NetaddressStrategyFactory.java
→
acl/src/main/java/org/apache/rocketmq/acl/plug/NetaddressStrategyFactory.java
浏览文件 @
48c51f72
...
...
@@ -14,15 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.acl.plug.strategy
;
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
;
package
org.apache.rocketmq.acl.plug
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.apache.commons.lang3.StringUtils
;
public
class
NetaddressStrategyFactory
{
...
...
acl/src/main/java/org/apache/rocketmq/acl/plug/PlainAclPlugEngine.java
0 → 100644
浏览文件 @
48c51f72
/*
* 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.plug
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
public
class
PlainAclPlugEngine
{
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
ACL_PLUG_LOGGER_NAME
);
private
String
fileHome
=
System
.
getProperty
(
MixAll
.
ROCKETMQ_HOME_PROPERTY
,
System
.
getenv
(
MixAll
.
ROCKETMQ_HOME_ENV
));
private
Map
<
String
/** account **/
,
List
<
AuthenticationInfo
>>
accessControlMap
=
new
HashMap
<>();
private
AuthenticationInfo
authenticationInfo
;
private
NetaddressStrategyFactory
netaddressStrategyFactory
=
new
NetaddressStrategyFactory
();
private
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
private
Class
<?>
accessContralAnalysisClass
=
RequestCode
.
class
;
public
PlainAclPlugEngine
()
{
initialize
();
}
public
void
initialize
()
{
BorkerAccessControlTransport
accessControlTransport
=
AclUtils
.
getYamlDataObject
(
fileHome
+
"/conf/transport.yml"
,
BorkerAccessControlTransport
.
class
);
if
(
accessControlTransport
==
null
)
{
throw
new
AclPlugRuntimeException
(
"transport.yml file is no data"
);
}
accessContralAnalysis
.
analysisClass
(
accessContralAnalysisClass
);
setBorkerAccessControlTransport
(
accessControlTransport
);
}
public
void
setAccessControl
(
AccessControl
accessControl
)
throws
AclPlugRuntimeException
{
if
(
accessControl
.
getAccount
()
==
null
||
accessControl
.
getPassword
()
==
null
||
accessControl
.
getAccount
().
length
()
<=
6
||
accessControl
.
getPassword
().
length
()
<=
6
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"The account password cannot be null and is longer than 6, account is %s password is %s"
,
accessControl
.
getAccount
(),
accessControl
.
getPassword
()));
}
try
{
NetaddressStrategy
netaddressStrategy
=
netaddressStrategyFactory
.
getNetaddressStrategy
(
accessControl
);
List
<
AuthenticationInfo
>
accessControlAddressList
=
accessControlMap
.
get
(
accessControl
.
getAccount
());
if
(
accessControlAddressList
==
null
)
{
accessControlAddressList
=
new
ArrayList
<>();
accessControlMap
.
put
(
accessControl
.
getAccount
(),
accessControlAddressList
);
}
AuthenticationInfo
authenticationInfo
=
new
AuthenticationInfo
(
accessContralAnalysis
.
analysis
(
accessControl
),
accessControl
,
netaddressStrategy
);
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
);
}
}
public
void
setAccessControlList
(
List
<
AccessControl
>
accessControlList
)
throws
AclPlugRuntimeException
{
for
(
AccessControl
accessControl
:
accessControlList
)
{
setAccessControl
(
accessControl
);
}
}
public
void
setNetaddressAccessControl
(
AccessControl
accessControl
)
throws
AclPlugRuntimeException
{
try
{
authenticationInfo
=
new
AuthenticationInfo
(
accessContralAnalysis
.
analysis
(
accessControl
),
accessControl
,
netaddressStrategyFactory
.
getNetaddressStrategy
(
accessControl
));
log
.
info
(
"default authenticationInfo is {}"
,
authenticationInfo
.
toString
());
}
catch
(
Exception
e
)
{
throw
new
AclPlugRuntimeException
(
accessControl
.
toString
(),
e
);
}
}
public
AuthenticationInfo
getAccessControl
(
AccessControl
accessControl
)
{
if
(
accessControl
.
getAccount
()
==
null
&&
authenticationInfo
!=
null
)
{
return
authenticationInfo
.
getNetaddressStrategy
().
match
(
accessControl
)
?
authenticationInfo
:
null
;
}
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
;
}
}
}
}
return
null
;
}
public
AuthenticationResult
eachCheckAuthentication
(
AccessControl
accessControl
)
{
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
AuthenticationInfo
authenticationInfo
=
getAccessControl
(
accessControl
);
if
(
authenticationInfo
!=
null
)
{
boolean
boo
=
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
)
{
if
(
transport
.
getOnlyNetAddress
()
==
null
&&
(
transport
.
getList
()
==
null
||
transport
.
getList
().
size
()
==
0
))
{
throw
new
AclPlugRuntimeException
(
"onlyNetAddress and list can't be all empty"
);
}
if
(
transport
.
getOnlyNetAddress
()
!=
null
)
{
this
.
setNetaddressAccessControl
(
transport
.
getOnlyNetAddress
());
}
if
(
transport
.
getList
()
!=
null
||
transport
.
getList
().
size
()
>
0
)
{
for
(
AccessControl
accessControl
:
transport
.
getList
())
{
this
.
setAccessControl
(
accessControl
);
}
}
}
public
boolean
authentication
(
AuthenticationInfo
authenticationInfo
,
AccessControl
accessControl
,
AuthenticationResult
authenticationResult
)
{
int
code
=
accessControl
.
getCode
();
if
(!
authenticationInfo
.
getAuthority
().
get
(
code
))
{
authenticationResult
.
setResultString
(
String
.
format
(
"code is %d Authentication failed"
,
code
));
return
false
;
}
if
(!(
authenticationInfo
.
getAccessControl
()
instanceof
BorkerAccessControl
))
{
return
true
;
}
BorkerAccessControl
borker
=
(
BorkerAccessControl
)
authenticationInfo
.
getAccessControl
();
String
topicName
=
accessControl
.
getTopic
();
if
(
code
==
10
||
code
==
310
||
code
==
320
)
{
if
(
borker
.
getPermitSendTopic
().
contains
(
topicName
))
{
return
true
;
}
if
(
borker
.
getNoPermitSendTopic
().
contains
(
topicName
))
{
authenticationResult
.
setResultString
(
String
.
format
(
"noPermitSendTopic include %s"
,
topicName
));
return
false
;
}
return
borker
.
getPermitSendTopic
().
isEmpty
()
?
true
:
false
;
}
else
if
(
code
==
11
)
{
if
(
borker
.
getPermitPullTopic
().
contains
(
topicName
))
{
return
true
;
}
if
(
borker
.
getNoPermitPullTopic
().
contains
(
topicName
))
{
authenticationResult
.
setResultString
(
String
.
format
(
"noPermitPullTopic include %s"
,
topicName
));
return
false
;
}
return
borker
.
getPermitPullTopic
().
isEmpty
()
?
true
:
false
;
}
return
true
;
}
public
static
class
AccessContralAnalysis
{
private
Map
<
Class
<?>,
Map
<
Integer
,
Field
>>
classTocodeAndMentod
=
new
HashMap
<>();
private
Map
<
String
,
Integer
>
fieldNameAndCode
=
new
HashMap
<>();
public
void
analysisClass
(
Class
<?>
clazz
)
{
Field
[]
fields
=
clazz
.
getDeclaredFields
();
try
{
for
(
Field
field
:
fields
)
{
if
(
field
.
getType
().
equals
(
int
.
class
))
{
String
name
=
StringUtils
.
replace
(
field
.
getName
(),
"_"
,
""
).
toLowerCase
();
fieldNameAndCode
.
put
(
name
,
(
Integer
)
field
.
get
(
null
));
}
}
}
catch
(
IllegalArgumentException
|
IllegalAccessException
e
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"analysis on failure Class is %s"
,
clazz
.
getName
()),
e
);
}
}
public
Map
<
Integer
,
Boolean
>
analysis
(
AccessControl
accessControl
)
{
Class
<?
extends
AccessControl
>
clazz
=
accessControl
.
getClass
();
Map
<
Integer
,
Field
>
codeAndField
=
classTocodeAndMentod
.
get
(
clazz
);
if
(
codeAndField
==
null
)
{
codeAndField
=
new
HashMap
<>();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
if
(!
field
.
getType
().
equals
(
boolean
.
class
))
continue
;
Integer
code
=
fieldNameAndCode
.
get
(
field
.
getName
().
toLowerCase
());
if
(
code
==
null
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"field nonexistent in code fieldName is %s"
,
field
.
getName
()));
}
field
.
setAccessible
(
true
);
codeAndField
.
put
(
code
,
field
);
}
if
(
codeAndField
.
isEmpty
())
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"AccessControl nonexistent code , name %s"
,
accessControl
.
getClass
().
getName
()));
}
classTocodeAndMentod
.
put
(
clazz
,
codeAndField
);
}
Iterator
<
Entry
<
Integer
,
Field
>>
it
=
codeAndField
.
entrySet
().
iterator
();
Map
<
Integer
,
Boolean
>
authority
=
new
HashMap
<>();
try
{
while
(
it
.
hasNext
())
{
Entry
<
Integer
,
Field
>
e
=
it
.
next
();
authority
.
put
(
e
.
getKey
(),
(
Boolean
)
e
.
getValue
().
get
(
accessControl
));
}
}
catch
(
IllegalArgumentException
|
IllegalAccessException
e
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"analysis on failure AccessControl is %s"
,
AccessControl
.
class
.
getName
()),
e
);
}
return
authority
;
}
}
public
static
class
BorkerAccessControlTransport
{
private
BorkerAccessControl
onlyNetAddress
;
private
List
<
BorkerAccessControl
>
list
;
public
BorkerAccessControl
getOnlyNetAddress
()
{
return
onlyNetAddress
;
}
public
void
setOnlyNetAddress
(
BorkerAccessControl
onlyNetAddress
)
{
this
.
onlyNetAddress
=
onlyNetAddress
;
}
public
List
<
BorkerAccessControl
>
getList
()
{
return
list
;
}
public
void
setList
(
List
<
BorkerAccessControl
>
list
)
{
this
.
list
=
list
;
}
@Override
public
String
toString
()
{
return
"BorkerAccessControlTransport [onlyNetAddress="
+
onlyNetAddress
+
", list="
+
list
+
"]"
;
}
}
}
acl/src/main/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngine.java
已删除
100644 → 0
浏览文件 @
1d576076
/*
* 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.plug.engine
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
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.entity.AuthenticationInfo
;
import
org.apache.rocketmq.acl.plug.entity.AuthenticationResult
;
import
org.apache.rocketmq.acl.plug.entity.BorkerAccessControl
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy
;
import
org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
public
class
PlainAclPlugEngine
{
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
ACL_PLUG_LOGGER_NAME
);
private
String
fileHome
=
System
.
getProperty
(
MixAll
.
ROCKETMQ_HOME_PROPERTY
,
System
.
getenv
(
MixAll
.
ROCKETMQ_HOME_ENV
));
private
Map
<
String
/** account **/
,
List
<
AuthenticationInfo
>>
accessControlMap
=
new
HashMap
<>();
private
AuthenticationInfo
authenticationInfo
;
private
NetaddressStrategyFactory
netaddressStrategyFactory
=
new
NetaddressStrategyFactory
();
private
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
private
Class
<?>
accessContralAnalysisClass
=
RequestCode
.
class
;
public
PlainAclPlugEngine
()
{
initialize
();
}
public
void
initialize
()
{
BorkerAccessControlTransport
accessControlTransport
=
AclUtils
.
getYamlDataObject
(
fileHome
+
"/conf/transport.yml"
,
BorkerAccessControlTransport
.
class
);
if
(
accessControlTransport
==
null
)
{
throw
new
AclPlugRuntimeException
(
"transport.yml file is no data"
);
}
accessContralAnalysis
.
analysisClass
(
accessContralAnalysisClass
);
setBorkerAccessControlTransport
(
accessControlTransport
);
}
public
void
setAccessControl
(
AccessControl
accessControl
)
throws
AclPlugRuntimeException
{
if
(
accessControl
.
getAccount
()
==
null
||
accessControl
.
getPassword
()
==
null
||
accessControl
.
getAccount
().
length
()
<=
6
||
accessControl
.
getPassword
().
length
()
<=
6
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"The account password cannot be null and is longer than 6, account is %s password is %s"
,
accessControl
.
getAccount
(),
accessControl
.
getPassword
()));
}
try
{
NetaddressStrategy
netaddressStrategy
=
netaddressStrategyFactory
.
getNetaddressStrategy
(
accessControl
);
List
<
AuthenticationInfo
>
accessControlAddressList
=
accessControlMap
.
get
(
accessControl
.
getAccount
());
if
(
accessControlAddressList
==
null
)
{
accessControlAddressList
=
new
ArrayList
<>();
accessControlMap
.
put
(
accessControl
.
getAccount
(),
accessControlAddressList
);
}
AuthenticationInfo
authenticationInfo
=
new
AuthenticationInfo
(
accessContralAnalysis
.
analysis
(
accessControl
),
accessControl
,
netaddressStrategy
);
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
);
}
}
public
void
setAccessControlList
(
List
<
AccessControl
>
accessControlList
)
throws
AclPlugRuntimeException
{
for
(
AccessControl
accessControl
:
accessControlList
)
{
setAccessControl
(
accessControl
);
}
}
public
void
setNetaddressAccessControl
(
AccessControl
accessControl
)
throws
AclPlugRuntimeException
{
try
{
authenticationInfo
=
new
AuthenticationInfo
(
accessContralAnalysis
.
analysis
(
accessControl
),
accessControl
,
netaddressStrategyFactory
.
getNetaddressStrategy
(
accessControl
));
log
.
info
(
"default authenticationInfo is {}"
,
authenticationInfo
.
toString
());
}
catch
(
Exception
e
)
{
throw
new
AclPlugRuntimeException
(
accessControl
.
toString
(),
e
);
}
}
public
AuthenticationInfo
getAccessControl
(
AccessControl
accessControl
)
{
if
(
accessControl
.
getAccount
()
==
null
&&
authenticationInfo
!=
null
)
{
return
authenticationInfo
.
getNetaddressStrategy
().
match
(
accessControl
)
?
authenticationInfo
:
null
;
}
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
;
}
}
}
}
return
null
;
}
public
AuthenticationResult
eachCheckAuthentication
(
AccessControl
accessControl
)
{
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
AuthenticationInfo
authenticationInfo
=
getAccessControl
(
accessControl
);
if
(
authenticationInfo
!=
null
)
{
boolean
boo
=
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
)
{
if
(
transport
.
getOnlyNetAddress
()
==
null
&&
(
transport
.
getList
()
==
null
||
transport
.
getList
().
size
()
==
0
))
{
throw
new
AclPlugRuntimeException
(
"onlyNetAddress and list can't be all empty"
);
}
if
(
transport
.
getOnlyNetAddress
()
!=
null
)
{
this
.
setNetaddressAccessControl
(
transport
.
getOnlyNetAddress
());
}
if
(
transport
.
getList
()
!=
null
||
transport
.
getList
().
size
()
>
0
)
{
for
(
AccessControl
accessControl
:
transport
.
getList
())
{
this
.
setAccessControl
(
accessControl
);
}
}
}
public
boolean
authentication
(
AuthenticationInfo
authenticationInfo
,
AccessControl
accessControl
,
AuthenticationResult
authenticationResult
)
{
int
code
=
accessControl
.
getCode
();
if
(!
authenticationInfo
.
getAuthority
().
get
(
code
))
{
authenticationResult
.
setResultString
(
String
.
format
(
"code is %d Authentication failed"
,
code
));
return
false
;
}
if
(!(
authenticationInfo
.
getAccessControl
()
instanceof
BorkerAccessControl
))
{
return
true
;
}
BorkerAccessControl
borker
=
(
BorkerAccessControl
)
authenticationInfo
.
getAccessControl
();
String
topicName
=
accessControl
.
getTopic
();
if
(
code
==
10
||
code
==
310
||
code
==
320
)
{
if
(
borker
.
getPermitSendTopic
().
contains
(
topicName
))
{
return
true
;
}
if
(
borker
.
getNoPermitSendTopic
().
contains
(
topicName
))
{
authenticationResult
.
setResultString
(
String
.
format
(
"noPermitSendTopic include %s"
,
topicName
));
return
false
;
}
return
borker
.
getPermitSendTopic
().
isEmpty
()
?
true
:
false
;
}
else
if
(
code
==
11
)
{
if
(
borker
.
getPermitPullTopic
().
contains
(
topicName
))
{
return
true
;
}
if
(
borker
.
getNoPermitPullTopic
().
contains
(
topicName
))
{
authenticationResult
.
setResultString
(
String
.
format
(
"noPermitPullTopic include %s"
,
topicName
));
return
false
;
}
return
borker
.
getPermitPullTopic
().
isEmpty
()
?
true
:
false
;
}
return
true
;
}
public
static
class
AccessContralAnalysis
{
private
Map
<
Class
<?>,
Map
<
Integer
,
Field
>>
classTocodeAndMentod
=
new
HashMap
<>();
private
Map
<
String
,
Integer
>
fieldNameAndCode
=
new
HashMap
<>();
public
void
analysisClass
(
Class
<?>
clazz
)
{
Field
[]
fields
=
clazz
.
getDeclaredFields
();
try
{
for
(
Field
field
:
fields
)
{
if
(
field
.
getType
().
equals
(
int
.
class
))
{
String
name
=
StringUtils
.
replace
(
field
.
getName
(),
"_"
,
""
).
toLowerCase
();
fieldNameAndCode
.
put
(
name
,
(
Integer
)
field
.
get
(
null
));
}
}
}
catch
(
IllegalArgumentException
|
IllegalAccessException
e
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"analysis on failure Class is %s"
,
clazz
.
getName
()),
e
);
}
}
public
Map
<
Integer
,
Boolean
>
analysis
(
AccessControl
accessControl
)
{
Class
<?
extends
AccessControl
>
clazz
=
accessControl
.
getClass
();
Map
<
Integer
,
Field
>
codeAndField
=
classTocodeAndMentod
.
get
(
clazz
);
if
(
codeAndField
==
null
)
{
codeAndField
=
new
HashMap
<>();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
if
(!
field
.
getType
().
equals
(
boolean
.
class
))
continue
;
Integer
code
=
fieldNameAndCode
.
get
(
field
.
getName
().
toLowerCase
());
if
(
code
==
null
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"field nonexistent in code fieldName is %s"
,
field
.
getName
()));
}
field
.
setAccessible
(
true
);
codeAndField
.
put
(
code
,
field
);
}
if
(
codeAndField
.
isEmpty
())
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"AccessControl nonexistent code , name %s"
,
accessControl
.
getClass
().
getName
()));
}
classTocodeAndMentod
.
put
(
clazz
,
codeAndField
);
}
Iterator
<
Entry
<
Integer
,
Field
>>
it
=
codeAndField
.
entrySet
().
iterator
();
Map
<
Integer
,
Boolean
>
authority
=
new
HashMap
<>();
try
{
while
(
it
.
hasNext
())
{
Entry
<
Integer
,
Field
>
e
=
it
.
next
();
authority
.
put
(
e
.
getKey
(),
(
Boolean
)
e
.
getValue
().
get
(
accessControl
));
}
}
catch
(
IllegalArgumentException
|
IllegalAccessException
e
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"analysis on failure AccessControl is %s"
,
AccessControl
.
class
.
getName
()),
e
);
}
return
authority
;
}
}
public
static
class
BorkerAccessControlTransport
{
private
BorkerAccessControl
onlyNetAddress
;
private
List
<
BorkerAccessControl
>
list
;
public
BorkerAccessControl
getOnlyNetAddress
()
{
return
onlyNetAddress
;
}
public
void
setOnlyNetAddress
(
BorkerAccessControl
onlyNetAddress
)
{
this
.
onlyNetAddress
=
onlyNetAddress
;
}
public
List
<
BorkerAccessControl
>
getList
()
{
return
list
;
}
public
void
setList
(
List
<
BorkerAccessControl
>
list
)
{
this
.
list
=
list
;
}
@Override
public
String
toString
()
{
return
"BorkerAccessControlTransport [onlyNetAddress="
+
onlyNetAddress
+
", list="
+
list
+
"]"
;
}
}
}
acl/src/test/java/org/apache/rocketmq/acl/plug/AccessContralAnalysisTest.java
已删除
100644 → 0
浏览文件 @
1d576076
/*
* 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.plug
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.entity.BorkerAccessControl
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
public
class
AccessContralAnalysisTest
{
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
@Before
public
void
init
()
{
accessContralAnalysis
.
analysisClass
(
RequestCode
.
class
);
}
@Test
public
void
analysisTest
()
{
BorkerAccessControl
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setSendMessage
(
false
);
Map
<
Integer
,
Boolean
>
map
=
accessContralAnalysis
.
analysis
(
accessControl
);
Iterator
<
Entry
<
Integer
,
Boolean
>>
it
=
map
.
entrySet
().
iterator
();
long
num
=
0
;
while
(
it
.
hasNext
())
{
Entry
<
Integer
,
Boolean
>
e
=
it
.
next
();
if
(!
e
.
getValue
())
{
Assert
.
assertEquals
(
e
.
getKey
(),
Integer
.
valueOf
(
10
));
num
++;
}
}
Assert
.
assertEquals
(
num
,
1
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
analysisExceptionTest
()
{
AccessControl
accessControl
=
new
AccessControl
();
accessContralAnalysis
.
analysis
(
accessControl
);
}
}
acl/src/test/java/org/apache/rocketmq/acl/plug/AclUtilsTest.java
浏览文件 @
48c51f72
...
...
@@ -18,12 +18,10 @@ 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
;
public
class
AclUtilsTest
{
@Test
...
...
@@ -125,4 +123,8 @@ public class AclUtilsTest {
isMinus
=
AclUtils
.
isMinus
(
"*"
);
Assert
.
assertFalse
(
isMinus
);
}
public
void
getYamlDataObjectTest
()
{
}
}
acl/src/test/java/org/apache/rocketmq/acl/plug/AuthenticationTest.java
已删除
100644 → 0
浏览文件 @
1d576076
/*
* 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.plug
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.entity.AuthenticationInfo
;
import
org.apache.rocketmq.acl.plug.entity.AuthenticationResult
;
import
org.apache.rocketmq.acl.plug.entity.BorkerAccessControl
;
import
org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
public
class
AuthenticationTest
{
Authentication
authentication
=
new
Authentication
();
AuthenticationInfo
authenticationInfo
;
BorkerAccessControl
borkerAccessControl
;
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
AccessControl
accessControl
=
new
AccessControl
();
@Before
public
void
init
()
{
borkerAccessControl
=
new
BorkerAccessControl
();
//321
borkerAccessControl
.
setQueryConsumeQueue
(
false
);
Set
<
String
>
permitSendTopic
=
new
HashSet
<>();
permitSendTopic
.
add
(
"permitSendTopic"
);
borkerAccessControl
.
setPermitSendTopic
(
permitSendTopic
);
Set
<
String
>
noPermitSendTopic
=
new
HashSet
<>();
noPermitSendTopic
.
add
(
"noPermitSendTopic"
);
borkerAccessControl
.
setNoPermitSendTopic
(
noPermitSendTopic
);
Set
<
String
>
permitPullTopic
=
new
HashSet
<>();
permitPullTopic
.
add
(
"permitPullTopic"
);
borkerAccessControl
.
setPermitPullTopic
(
permitPullTopic
);
Set
<
String
>
noPermitPullTopic
=
new
HashSet
<>();
noPermitPullTopic
.
add
(
"noPermitPullTopic"
);
borkerAccessControl
.
setNoPermitPullTopic
(
noPermitPullTopic
);
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
accessContralAnalysis
.
analysisClass
(
RequestCode
.
class
);
Map
<
Integer
,
Boolean
>
map
=
accessContralAnalysis
.
analysis
(
borkerAccessControl
);
authenticationInfo
=
new
AuthenticationInfo
(
map
,
borkerAccessControl
,
NetaddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
}
@Test
public
void
authenticationTest
()
{
accessControl
.
setCode
(
317
);
boolean
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
321
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setCode
(
10
);
accessControl
.
setTopic
(
"permitSendTopic"
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
310
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
320
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setTopic
(
"noPermitSendTopic"
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setTopic
(
"nopermitSendTopic"
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setCode
(
11
);
accessControl
.
setTopic
(
"permitPullTopic"
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setTopic
(
"noPermitPullTopic"
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setTopic
(
"nopermitPullTopic"
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
}
@Test
public
void
isEmptyTest
()
{
accessControl
.
setCode
(
10
);
accessControl
.
setTopic
(
"absentTopic"
);
boolean
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
Set
<
String
>
permitSendTopic
=
new
HashSet
<>();
borkerAccessControl
.
setPermitSendTopic
(
permitSendTopic
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
11
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
borkerAccessControl
.
setPermitPullTopic
(
permitSendTopic
);
isReturn
=
authentication
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
}
}
acl/src/test/java/org/apache/rocketmq/acl/plug/
strategy/
NetaddressStrategyTest.java
→
acl/src/test/java/org/apache/rocketmq/acl/plug/NetaddressStrategyTest.java
浏览文件 @
48c51f72
...
...
@@ -14,10 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.acl.plug
.strategy
;
package
org.apache.rocketmq.acl.plug
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
acl/src/test/java/org/apache/rocketmq/acl/plug/PlainAclPlugEngineTest.java
0 → 100644
浏览文件 @
48c51f72
/*
* 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.plug
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
org.apache.rocketmq.acl.plug.PlainAclPlugEngine.AccessContralAnalysis
;
import
org.apache.rocketmq.acl.plug.PlainAclPlugEngine.BorkerAccessControlTransport
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.junit.MockitoJUnitRunner
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
PlainAclPlugEngineTest
{
PlainAclPlugEngine
plainAclPlugEngine
;
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
AccessControl
accessControl
;
AccessControl
accessControlTwo
;
AuthenticationInfo
authenticationInfo
;
BorkerAccessControl
borkerAccessControl
;
@Before
public
void
init
()
throws
NoSuchFieldException
,
SecurityException
,
IOException
{
accessContralAnalysis
.
analysisClass
(
RequestCode
.
class
);
borkerAccessControl
=
new
BorkerAccessControl
();
// 321
borkerAccessControl
.
setQueryConsumeQueue
(
false
);
Set
<
String
>
permitSendTopic
=
new
HashSet
<>();
permitSendTopic
.
add
(
"permitSendTopic"
);
borkerAccessControl
.
setPermitSendTopic
(
permitSendTopic
);
Set
<
String
>
noPermitSendTopic
=
new
HashSet
<>();
noPermitSendTopic
.
add
(
"noPermitSendTopic"
);
borkerAccessControl
.
setNoPermitSendTopic
(
noPermitSendTopic
);
Set
<
String
>
permitPullTopic
=
new
HashSet
<>();
permitPullTopic
.
add
(
"permitPullTopic"
);
borkerAccessControl
.
setPermitPullTopic
(
permitPullTopic
);
Set
<
String
>
noPermitPullTopic
=
new
HashSet
<>();
noPermitPullTopic
.
add
(
"noPermitPullTopic"
);
borkerAccessControl
.
setNoPermitPullTopic
(
noPermitPullTopic
);
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
accessContralAnalysis
.
analysisClass
(
RequestCode
.
class
);
Map
<
Integer
,
Boolean
>
map
=
accessContralAnalysis
.
analysis
(
borkerAccessControl
);
authenticationInfo
=
new
AuthenticationInfo
(
map
,
borkerAccessControl
,
NetaddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
plainAclPlugEngine
=
new
PlainAclPlugEngine
();
plainAclPlugEngine
.
initialize
();
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"rokcetmq"
);
accessControl
.
setPassword
(
"aliyun11"
);
accessControl
.
setNetaddress
(
"127.0.0.1"
);
accessControl
.
setRecognition
(
"127.0.0.1:1"
);
accessControlTwo
=
new
BorkerAccessControl
();
accessControlTwo
.
setAccount
(
"rokcet1"
);
accessControlTwo
.
setPassword
(
"aliyun1"
);
accessControlTwo
.
setNetaddress
(
"127.0.0.1"
);
accessControlTwo
.
setRecognition
(
"127.0.0.1:2"
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
accountNullTest
()
{
accessControl
.
setAccount
(
null
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
accountThanTest
()
{
accessControl
.
setAccount
(
"123"
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
passWordtNullTest
()
{
accessControl
.
setAccount
(
null
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
passWordThanTest
()
{
accessControl
.
setAccount
(
"123"
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
testPlainAclPlugEngineInit
()
{
System
.
setProperty
(
"rocketmq.home.dir"
,
""
);
new
PlainAclPlugEngine
().
initialize
();
}
@Test
public
void
authenticationInfoOfSetAccessControl
()
{
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
AuthenticationInfo
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
AccessControl
getAccessControl
=
authenticationInfo
.
getAccessControl
();
Assert
.
assertEquals
(
accessControl
,
getAccessControl
);
AccessControl
testAccessControl
=
new
AccessControl
();
testAccessControl
.
setAccount
(
"rokcetmq"
);
testAccessControl
.
setPassword
(
"aliyun11"
);
testAccessControl
.
setNetaddress
(
"127.0.0.1"
);
testAccessControl
.
setRecognition
(
"127.0.0.1:1"
);
testAccessControl
.
setAccount
(
"rokcetmq1"
);
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
testAccessControl
);
Assert
.
assertNull
(
authenticationInfo
);
testAccessControl
.
setAccount
(
"rokcetmq"
);
testAccessControl
.
setPassword
(
"1234567"
);
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
testAccessControl
);
Assert
.
assertNull
(
authenticationInfo
);
testAccessControl
.
setNetaddress
(
"127.0.0.2"
);
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
testAccessControl
);
Assert
.
assertNull
(
authenticationInfo
);
}
@Test
public
void
setAccessControlList
()
{
List
<
AccessControl
>
accessControlList
=
new
ArrayList
<>();
accessControlList
.
add
(
accessControl
);
accessControlList
.
add
(
accessControlTwo
);
plainAclPlugEngine
.
setAccessControlList
(
accessControlList
);
AuthenticationInfo
newAccessControl
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
Assert
.
assertEquals
(
accessControl
,
newAccessControl
.
getAccessControl
());
newAccessControl
=
plainAclPlugEngine
.
getAccessControl
(
accessControlTwo
);
Assert
.
assertEquals
(
accessControlTwo
,
newAccessControl
.
getAccessControl
());
}
@Test
public
void
setNetaddressAccessControl
()
{
AccessControl
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"RocketMQ"
);
accessControl
.
setPassword
(
"RocketMQ"
);
accessControl
.
setNetaddress
(
"127.0.0.1"
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
plainAclPlugEngine
.
setNetaddressAccessControl
(
accessControl
);
AuthenticationInfo
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
AccessControl
getAccessControl
=
authenticationInfo
.
getAccessControl
();
Assert
.
assertEquals
(
accessControl
,
getAccessControl
);
accessControl
.
setNetaddress
(
"127.0.0.2"
);
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
Assert
.
assertNull
(
authenticationInfo
);
}
public
void
eachCheckLoginAndAuthentication
()
{
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
borkerAccessControlTransportTestNull
()
{
BorkerAccessControlTransport
accessControlTransport
=
new
BorkerAccessControlTransport
();
plainAclPlugEngine
.
setBorkerAccessControlTransport
(
accessControlTransport
);
}
@Test
public
void
borkerAccessControlTransportTest
()
{
BorkerAccessControlTransport
accessControlTransport
=
new
BorkerAccessControlTransport
();
List
<
BorkerAccessControl
>
list
=
new
ArrayList
<>();
list
.
add
((
BorkerAccessControl
)
this
.
accessControlTwo
);
accessControlTransport
.
setOnlyNetAddress
((
BorkerAccessControl
)
this
.
accessControl
);
accessControlTransport
.
setList
(
list
);
plainAclPlugEngine
.
setBorkerAccessControlTransport
(
accessControlTransport
);
AccessControl
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"RocketMQ"
);
accessControl
.
setPassword
(
"RocketMQ"
);
accessControl
.
setNetaddress
(
"127.0.0.1"
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
AuthenticationInfo
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
Assert
.
assertNotNull
(
authenticationInfo
.
getAccessControl
());
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControlTwo
);
Assert
.
assertEquals
(
accessControlTwo
,
authenticationInfo
.
getAccessControl
());
}
@Test
public
void
authenticationTest
()
{
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
accessControl
.
setCode
(
317
);
boolean
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
321
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setCode
(
10
);
accessControl
.
setTopic
(
"permitSendTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
310
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
320
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setTopic
(
"noPermitSendTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setTopic
(
"nopermitSendTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setCode
(
11
);
accessControl
.
setTopic
(
"permitPullTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setTopic
(
"noPermitPullTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setTopic
(
"nopermitPullTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
}
@Test
public
void
isEmptyTest
()
{
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
accessControl
.
setCode
(
10
);
accessControl
.
setTopic
(
"absentTopic"
);
boolean
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
Set
<
String
>
permitSendTopic
=
new
HashSet
<>();
borkerAccessControl
.
setPermitSendTopic
(
permitSendTopic
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
11
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
borkerAccessControl
.
setPermitPullTopic
(
permitSendTopic
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
}
@Test
public
void
analysisTest
()
{
BorkerAccessControl
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setSendMessage
(
false
);
Map
<
Integer
,
Boolean
>
map
=
accessContralAnalysis
.
analysis
(
accessControl
);
Iterator
<
Entry
<
Integer
,
Boolean
>>
it
=
map
.
entrySet
().
iterator
();
long
num
=
0
;
while
(
it
.
hasNext
())
{
Entry
<
Integer
,
Boolean
>
e
=
it
.
next
();
if
(!
e
.
getValue
())
{
Assert
.
assertEquals
(
e
.
getKey
(),
Integer
.
valueOf
(
10
));
num
++;
}
}
Assert
.
assertEquals
(
num
,
1
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
analysisExceptionTest
()
{
AccessControl
accessControl
=
new
AccessControl
();
accessContralAnalysis
.
analysis
(
accessControl
);
}
}
acl/src/test/java/org/apache/rocketmq/acl/plug/engine/PlainAclPlugEngineTest.java
已删除
100644 → 0
浏览文件 @
1d576076
/*
* 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.plug.engine
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.rocketmq.acl.plug.AccessContralAnalysis
;
import
org.apache.rocketmq.acl.plug.engine.PlainAclPlugEngine.BorkerAccessControlTransport
;
import
org.apache.rocketmq.acl.plug.entity.AccessControl
;
import
org.apache.rocketmq.acl.plug.entity.AuthenticationInfo
;
import
org.apache.rocketmq.acl.plug.entity.AuthenticationResult
;
import
org.apache.rocketmq.acl.plug.entity.BorkerAccessControl
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.junit.MockitoJUnitRunner
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
PlainAclPlugEngineTest
{
PlainAclPlugEngine
plainAclPlugEngine
;
AccessControl
accessControl
;
AccessControl
accessControlTwo
;
AuthenticationInfo
authenticationInfo
;
BorkerAccessControl
borkerAccessControl
;
@Before
public
void
init
()
throws
NoSuchFieldException
,
SecurityException
,
IOException
{
borkerAccessControl
=
new
BorkerAccessControl
();
// 321
borkerAccessControl
.
setQueryConsumeQueue
(
false
);
Set
<
String
>
permitSendTopic
=
new
HashSet
<>();
permitSendTopic
.
add
(
"permitSendTopic"
);
borkerAccessControl
.
setPermitSendTopic
(
permitSendTopic
);
Set
<
String
>
noPermitSendTopic
=
new
HashSet
<>();
noPermitSendTopic
.
add
(
"noPermitSendTopic"
);
borkerAccessControl
.
setNoPermitSendTopic
(
noPermitSendTopic
);
Set
<
String
>
permitPullTopic
=
new
HashSet
<>();
permitPullTopic
.
add
(
"permitPullTopic"
);
borkerAccessControl
.
setPermitPullTopic
(
permitPullTopic
);
Set
<
String
>
noPermitPullTopic
=
new
HashSet
<>();
noPermitPullTopic
.
add
(
"noPermitPullTopic"
);
borkerAccessControl
.
setNoPermitPullTopic
(
noPermitPullTopic
);
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
accessContralAnalysis
.
analysisClass
(
RequestCode
.
class
);
Map
<
Integer
,
Boolean
>
map
=
accessContralAnalysis
.
analysis
(
borkerAccessControl
);
authenticationInfo
=
new
AuthenticationInfo
(
map
,
borkerAccessControl
,
NetaddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
plainAclPlugEngine
=
new
PlainAclPlugEngine
();
plainAclPlugEngine
.
initialize
();
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"rokcetmq"
);
accessControl
.
setPassword
(
"aliyun11"
);
accessControl
.
setNetaddress
(
"127.0.0.1"
);
accessControl
.
setRecognition
(
"127.0.0.1:1"
);
accessControlTwo
=
new
BorkerAccessControl
();
accessControlTwo
.
setAccount
(
"rokcet1"
);
accessControlTwo
.
setPassword
(
"aliyun1"
);
accessControlTwo
.
setNetaddress
(
"127.0.0.1"
);
accessControlTwo
.
setRecognition
(
"127.0.0.1:2"
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
accountNullTest
()
{
accessControl
.
setAccount
(
null
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
accountThanTest
()
{
accessControl
.
setAccount
(
"123"
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
passWordtNullTest
()
{
accessControl
.
setAccount
(
null
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
passWordThanTest
()
{
accessControl
.
setAccount
(
"123"
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
testPlainAclPlugEngineInit
()
{
System
.
setProperty
(
"rocketmq.home.dir"
,
""
);
new
PlainAclPlugEngine
().
initialize
();
}
@Test
public
void
authenticationInfoOfSetAccessControl
()
{
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
AuthenticationInfo
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
AccessControl
getAccessControl
=
authenticationInfo
.
getAccessControl
();
Assert
.
assertEquals
(
accessControl
,
getAccessControl
);
AccessControl
testAccessControl
=
new
AccessControl
();
testAccessControl
.
setAccount
(
"rokcetmq"
);
testAccessControl
.
setPassword
(
"aliyun11"
);
testAccessControl
.
setNetaddress
(
"127.0.0.1"
);
testAccessControl
.
setRecognition
(
"127.0.0.1:1"
);
testAccessControl
.
setAccount
(
"rokcetmq1"
);
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
testAccessControl
);
Assert
.
assertNull
(
authenticationInfo
);
testAccessControl
.
setAccount
(
"rokcetmq"
);
testAccessControl
.
setPassword
(
"1234567"
);
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
testAccessControl
);
Assert
.
assertNull
(
authenticationInfo
);
testAccessControl
.
setNetaddress
(
"127.0.0.2"
);
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
testAccessControl
);
Assert
.
assertNull
(
authenticationInfo
);
}
@Test
public
void
setAccessControlList
()
{
List
<
AccessControl
>
accessControlList
=
new
ArrayList
<>();
accessControlList
.
add
(
accessControl
);
accessControlList
.
add
(
accessControlTwo
);
plainAclPlugEngine
.
setAccessControlList
(
accessControlList
);
AuthenticationInfo
newAccessControl
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
Assert
.
assertEquals
(
accessControl
,
newAccessControl
.
getAccessControl
());
newAccessControl
=
plainAclPlugEngine
.
getAccessControl
(
accessControlTwo
);
Assert
.
assertEquals
(
accessControlTwo
,
newAccessControl
.
getAccessControl
());
}
@Test
public
void
setNetaddressAccessControl
()
{
AccessControl
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"RocketMQ"
);
accessControl
.
setPassword
(
"RocketMQ"
);
accessControl
.
setNetaddress
(
"127.0.0.1"
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
plainAclPlugEngine
.
setNetaddressAccessControl
(
accessControl
);
AuthenticationInfo
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
AccessControl
getAccessControl
=
authenticationInfo
.
getAccessControl
();
Assert
.
assertEquals
(
accessControl
,
getAccessControl
);
accessControl
.
setNetaddress
(
"127.0.0.2"
);
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
Assert
.
assertNull
(
authenticationInfo
);
}
public
void
eachCheckLoginAndAuthentication
()
{
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
borkerAccessControlTransportTestNull
()
{
BorkerAccessControlTransport
accessControlTransport
=
new
BorkerAccessControlTransport
();
plainAclPlugEngine
.
setBorkerAccessControlTransport
(
accessControlTransport
);
}
@Test
public
void
borkerAccessControlTransportTest
()
{
BorkerAccessControlTransport
accessControlTransport
=
new
BorkerAccessControlTransport
();
List
<
BorkerAccessControl
>
list
=
new
ArrayList
<>();
list
.
add
((
BorkerAccessControl
)
this
.
accessControlTwo
);
accessControlTransport
.
setOnlyNetAddress
((
BorkerAccessControl
)
this
.
accessControl
);
accessControlTransport
.
setList
(
list
);
plainAclPlugEngine
.
setBorkerAccessControlTransport
(
accessControlTransport
);
AccessControl
accessControl
=
new
BorkerAccessControl
();
accessControl
.
setAccount
(
"RocketMQ"
);
accessControl
.
setPassword
(
"RocketMQ"
);
accessControl
.
setNetaddress
(
"127.0.0.1"
);
plainAclPlugEngine
.
setAccessControl
(
accessControl
);
AuthenticationInfo
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControl
);
Assert
.
assertNotNull
(
authenticationInfo
.
getAccessControl
());
authenticationInfo
=
plainAclPlugEngine
.
getAccessControl
(
accessControlTwo
);
Assert
.
assertEquals
(
accessControlTwo
,
authenticationInfo
.
getAccessControl
());
}
@Test
public
void
authenticationTest
()
{
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
accessControl
.
setCode
(
317
);
boolean
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
321
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setCode
(
10
);
accessControl
.
setTopic
(
"permitSendTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
310
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
320
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setTopic
(
"noPermitSendTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setTopic
(
"nopermitSendTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setCode
(
11
);
accessControl
.
setTopic
(
"permitPullTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setTopic
(
"noPermitPullTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
accessControl
.
setTopic
(
"nopermitPullTopic"
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
}
@Test
public
void
isEmptyTest
()
{
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
accessControl
.
setCode
(
10
);
accessControl
.
setTopic
(
"absentTopic"
);
boolean
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
Set
<
String
>
permitSendTopic
=
new
HashSet
<>();
borkerAccessControl
.
setPermitSendTopic
(
permitSendTopic
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
accessControl
.
setCode
(
11
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
borkerAccessControl
.
setPermitPullTopic
(
permitSendTopic
);
isReturn
=
plainAclPlugEngine
.
authentication
(
authenticationInfo
,
accessControl
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录