Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
87d85991
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看板
提交
87d85991
编写于
12月 03, 2018
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename some files in acl
上级
5d253f58
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
152 addition
and
144 deletion
+152
-144
acl/src/main/java/org/apache/rocketmq/acl/plain/AclPlugRuntimeException.java
...rg/apache/rocketmq/acl/plain/AclPlugRuntimeException.java
+4
-0
acl/src/main/java/org/apache/rocketmq/acl/plain/AuthenticationInfo.java
...ava/org/apache/rocketmq/acl/plain/AuthenticationInfo.java
+10
-9
acl/src/main/java/org/apache/rocketmq/acl/plain/AuthenticationResult.java
...a/org/apache/rocketmq/acl/plain/AuthenticationResult.java
+2
-0
acl/src/main/java/org/apache/rocketmq/acl/plain/BrokerAccessControl.java
...va/org/apache/rocketmq/acl/plain/BrokerAccessControl.java
+1
-0
acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java
...a/org/apache/rocketmq/acl/plain/PlainAccessValidator.java
+2
-2
acl/src/main/java/org/apache/rocketmq/acl/plain/PlainPermissionLoader.java
.../org/apache/rocketmq/acl/plain/PlainPermissionLoader.java
+9
-9
acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategy.java
.../org/apache/rocketmq/acl/plain/RemoteAddressStrategy.java
+1
-1
acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
...ache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
+17
-17
acl/src/test/java/org/apache/rocketmq/acl/plain/PlainAclPlugEngineTest.java
...org/apache/rocketmq/acl/plain/PlainAclPlugEngineTest.java
+59
-59
acl/src/test/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
.../apache/rocketmq/acl/plain/RemoteAddressStrategyTest.java
+47
-47
未找到文件。
acl/src/main/java/org/apache/rocketmq/acl/plain/AclPlugRuntimeException.java
浏览文件 @
87d85991
...
...
@@ -16,6 +16,10 @@
*/
package
org.apache.rocketmq.acl.plain
;
/**
* Use AclException instead
*/
@Deprecated
public
class
AclPlugRuntimeException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
6062101368637228900L
;
...
...
acl/src/main/java/org/apache/rocketmq/acl/plain/AuthenticationInfo.java
浏览文件 @
87d85991
...
...
@@ -20,20 +20,21 @@ import java.util.Iterator;
import
java.util.Map
;
import
java.util.Map.Entry
;
@Deprecated
public
class
AuthenticationInfo
{
private
PlainAccessResource
plainAccessResource
;
private
NetaddressStrategy
neta
ddressStrategy
;
private
RemoteAddressStrategy
remoteA
ddressStrategy
;
private
Map
<
Integer
,
Boolean
>
authority
;
public
AuthenticationInfo
(
Map
<
Integer
,
Boolean
>
authority
,
PlainAccessResource
plainAccessResource
,
NetaddressStrategy
neta
ddressStrategy
)
{
RemoteAddressStrategy
remoteA
ddressStrategy
)
{
super
();
this
.
authority
=
authority
;
this
.
plainAccessResource
=
plainAccessResource
;
this
.
netaddressStrategy
=
neta
ddressStrategy
;
this
.
remoteAddressStrategy
=
remoteA
ddressStrategy
;
}
public
PlainAccessResource
getPlainAccessResource
()
{
...
...
@@ -44,12 +45,12 @@ public class AuthenticationInfo {
this
.
plainAccessResource
=
plainAccessResource
;
}
public
NetaddressStrategy
getNeta
ddressStrategy
()
{
return
neta
ddressStrategy
;
public
RemoteAddressStrategy
getRemoteA
ddressStrategy
()
{
return
remoteA
ddressStrategy
;
}
public
void
set
NetaddressStrategy
(
NetaddressStrategy
neta
ddressStrategy
)
{
this
.
netaddressStrategy
=
neta
ddressStrategy
;
public
void
set
RemoteAddressStrategy
(
RemoteAddressStrategy
remoteA
ddressStrategy
)
{
this
.
remoteAddressStrategy
=
remoteA
ddressStrategy
;
}
public
Map
<
Integer
,
Boolean
>
getAuthority
()
{
...
...
@@ -63,8 +64,8 @@ public class AuthenticationInfo {
@Override
public
String
toString
()
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"AuthenticationInfo [plainAccessResource="
).
append
(
plainAccessResource
).
append
(
",
neta
ddressStrategy="
)
.
append
(
neta
ddressStrategy
).
append
(
", authority={"
);
builder
.
append
(
"AuthenticationInfo [plainAccessResource="
).
append
(
plainAccessResource
).
append
(
",
remoteA
ddressStrategy="
)
.
append
(
remoteA
ddressStrategy
).
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/plain/AuthenticationResult.java
浏览文件 @
87d85991
...
...
@@ -16,6 +16,8 @@
*/
package
org.apache.rocketmq.acl.plain
;
@Deprecated
public
class
AuthenticationResult
{
private
PlainAccessResource
plainAccessResource
;
...
...
acl/src/main/java/org/apache/rocketmq/acl/plain/BrokerAccessControl.java
浏览文件 @
87d85991
...
...
@@ -19,6 +19,7 @@ package org.apache.rocketmq.acl.plain;
import
java.util.HashSet
;
import
java.util.Set
;
@Deprecated
public
class
BrokerAccessControl
extends
PlainAccessResource
{
private
boolean
admin
;
...
...
acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java
浏览文件 @
87d85991
...
...
@@ -38,10 +38,10 @@ import static org.apache.rocketmq.acl.plain.PlainAccessResource.getRetryTopic;
public
class
PlainAccessValidator
implements
AccessValidator
{
private
Plain
AclPlugEngine
aclPlugEngine
;
private
Plain
PermissionLoader
aclPlugEngine
;
public
PlainAccessValidator
()
{
aclPlugEngine
=
new
Plain
AclPlugEngine
();
aclPlugEngine
=
new
Plain
PermissionLoader
();
}
@Override
...
...
acl/src/main/java/org/apache/rocketmq/acl/plain/Plain
AclPlugEngine
.java
→
acl/src/main/java/org/apache/rocketmq/acl/plain/Plain
PermissionLoader
.java
浏览文件 @
87d85991
...
...
@@ -40,7 +40,7 @@ import org.apache.rocketmq.common.protocol.RequestCode;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
public
class
Plain
AclPlugEngine
{
public
class
Plain
PermissionLoader
{
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
ACL_PLUG_LOGGER_NAME
);
...
...
@@ -51,7 +51,7 @@ public class PlainAclPlugEngine {
private
AuthenticationInfo
authenticationInfo
;
private
NetaddressStrategyFactory
netaddressStrategyFactory
=
new
Neta
ddressStrategyFactory
();
private
RemoteAddressStrategyFactory
remoteAddressStrategyFactory
=
new
RemoteA
ddressStrategyFactory
();
private
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
...
...
@@ -59,7 +59,7 @@ public class PlainAclPlugEngine {
private
boolean
isWatchStart
;
public
Plain
AclPlugEngine
()
{
public
Plain
PermissionLoader
()
{
initialize
();
watch
();
}
...
...
@@ -98,7 +98,7 @@ public class PlainAclPlugEngine {
if
(
"transport.yml"
.
equals
(
event
.
context
().
toString
())
&&
(
StandardWatchEventKinds
.
ENTRY_MODIFY
.
equals
(
event
.
kind
())
||
StandardWatchEventKinds
.
ENTRY_CREATE
.
equals
(
event
.
kind
())))
{
log
.
info
(
"transprot.yml make a difference change is : "
,
event
.
toString
());
Plain
AclPlugEngine
.
this
.
cleanAuthenticationInfo
();
Plain
PermissionLoader
.
this
.
cleanAuthenticationInfo
();
initialize
();
}
}
...
...
@@ -151,14 +151,14 @@ public class PlainAclPlugEngine {
}
try
{
handleAccessControl
(
plainAccessResource
);
NetaddressStrategy
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
RemoteAddressStrategy
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
List
<
AuthenticationInfo
>
accessControlAddressList
=
accessControlMap
.
get
(
plainAccessResource
.
getAccessKey
());
if
(
accessControlAddressList
==
null
)
{
accessControlAddressList
=
new
ArrayList
<>();
accessControlMap
.
put
(
plainAccessResource
.
getAccessKey
(),
accessControlAddressList
);
}
AuthenticationInfo
authenticationInfo
=
new
AuthenticationInfo
(
accessContralAnalysis
.
analysis
(
plainAccessResource
),
plainAccessResource
,
neta
ddressStrategy
);
accessContralAnalysis
.
analysis
(
plainAccessResource
),
plainAccessResource
,
remoteA
ddressStrategy
);
accessControlAddressList
.
add
(
authenticationInfo
);
log
.
info
(
"authenticationInfo is {}"
,
authenticationInfo
.
toString
());
}
catch
(
Exception
e
)
{
...
...
@@ -175,7 +175,7 @@ public class PlainAclPlugEngine {
public
void
setNetaddressAccessControl
(
PlainAccessResource
plainAccessResource
)
throws
AclPlugRuntimeException
{
try
{
authenticationInfo
=
new
AuthenticationInfo
(
accessContralAnalysis
.
analysis
(
plainAccessResource
),
plainAccessResource
,
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
));
authenticationInfo
=
new
AuthenticationInfo
(
accessContralAnalysis
.
analysis
(
plainAccessResource
),
plainAccessResource
,
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
));
log
.
info
(
"default authenticationInfo is {}"
,
authenticationInfo
.
toString
());
}
catch
(
Exception
e
)
{
throw
new
AclPlugRuntimeException
(
plainAccessResource
.
toString
(),
e
);
...
...
@@ -185,12 +185,12 @@ public class PlainAclPlugEngine {
public
AuthenticationInfo
getAccessControl
(
PlainAccessResource
plainAccessResource
)
{
if
(
plainAccessResource
.
getAccessKey
()
==
null
&&
authenticationInfo
!=
null
)
{
return
authenticationInfo
.
get
Neta
ddressStrategy
().
match
(
plainAccessResource
)
?
authenticationInfo
:
null
;
return
authenticationInfo
.
get
RemoteA
ddressStrategy
().
match
(
plainAccessResource
)
?
authenticationInfo
:
null
;
}
else
{
List
<
AuthenticationInfo
>
accessControlAddressList
=
accessControlMap
.
get
(
plainAccessResource
.
getAccessKey
());
if
(
accessControlAddressList
!=
null
)
{
for
(
AuthenticationInfo
ai
:
accessControlAddressList
)
{
if
(
ai
.
get
Neta
ddressStrategy
().
match
(
plainAccessResource
)
&&
ai
.
getPlainAccessResource
().
getSignature
().
equals
(
plainAccessResource
.
getSignature
()))
{
if
(
ai
.
get
RemoteA
ddressStrategy
().
match
(
plainAccessResource
)
&&
ai
.
getPlainAccessResource
().
getSignature
().
equals
(
plainAccessResource
.
getSignature
()))
{
return
ai
;
}
}
...
...
acl/src/main/java/org/apache/rocketmq/acl/plain/
Neta
ddressStrategy.java
→
acl/src/main/java/org/apache/rocketmq/acl/plain/
RemoteA
ddressStrategy.java
浏览文件 @
87d85991
...
...
@@ -16,7 +16,7 @@
*/
package
org.apache.rocketmq.acl.plain
;
public
interface
Neta
ddressStrategy
{
public
interface
RemoteA
ddressStrategy
{
public
boolean
match
(
PlainAccessResource
plainAccessResource
);
}
acl/src/main/java/org/apache/rocketmq/acl/plain/
Neta
ddressStrategyFactory.java
→
acl/src/main/java/org/apache/rocketmq/acl/plain/
RemoteA
ddressStrategyFactory.java
浏览文件 @
87d85991
...
...
@@ -21,11 +21,11 @@ import java.util.Set;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.acl.common.AclUtils
;
public
class
Neta
ddressStrategyFactory
{
public
class
RemoteA
ddressStrategyFactory
{
public
static
final
Null
NetaddressStrategy
NULL_NET_ADDRESS_STRATEGY
=
new
NullNeta
ddressStrategy
();
public
static
final
Null
RemoteAddressStrategy
NULL_NET_ADDRESS_STRATEGY
=
new
NullRemoteA
ddressStrategy
();
public
Neta
ddressStrategy
getNetaddressStrategy
(
PlainAccessResource
plainAccessResource
)
{
public
RemoteA
ddressStrategy
getNetaddressStrategy
(
PlainAccessResource
plainAccessResource
)
{
String
netaddress
=
plainAccessResource
.
getRemoteAddr
();
if
(
StringUtils
.
isBlank
(
netaddress
)
||
"*"
.
equals
(
netaddress
))
{
return
NULL_NET_ADDRESS_STRATEGY
;
...
...
@@ -34,19 +34,19 @@ public class NetaddressStrategyFactory {
String
[]
strArray
=
StringUtils
.
split
(
netaddress
,
"."
);
String
four
=
strArray
[
3
];
if
(!
four
.
startsWith
(
"{"
))
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"Multiple
Neta
ddressStrategy netaddress examine scope Exception netaddress"
,
netaddress
));
throw
new
AclPlugRuntimeException
(
String
.
format
(
"Multiple
RemoteA
ddressStrategy netaddress examine scope Exception netaddress"
,
netaddress
));
}
return
new
Multiple
Neta
ddressStrategy
(
AclUtils
.
getAddreeStrArray
(
netaddress
,
four
));
return
new
Multiple
RemoteA
ddressStrategy
(
AclUtils
.
getAddreeStrArray
(
netaddress
,
four
));
}
else
if
(
AclUtils
.
isColon
(
netaddress
))
{
return
new
Multiple
Neta
ddressStrategy
(
StringUtils
.
split
(
netaddress
,
","
));
return
new
Multiple
RemoteA
ddressStrategy
(
StringUtils
.
split
(
netaddress
,
","
));
}
else
if
(
AclUtils
.
isAsterisk
(
netaddress
)
||
AclUtils
.
isMinus
(
netaddress
))
{
return
new
Range
Neta
ddressStrategy
(
netaddress
);
return
new
Range
RemoteA
ddressStrategy
(
netaddress
);
}
return
new
One
Neta
ddressStrategy
(
netaddress
);
return
new
One
RemoteA
ddressStrategy
(
netaddress
);
}
public
static
class
Null
NetaddressStrategy
implements
Neta
ddressStrategy
{
public
static
class
Null
RemoteAddressStrategy
implements
RemoteA
ddressStrategy
{
@Override
public
boolean
match
(
PlainAccessResource
plainAccessResource
)
{
return
true
;
...
...
@@ -54,11 +54,11 @@ public class NetaddressStrategyFactory {
}
public
static
class
Multiple
NetaddressStrategy
implements
Neta
ddressStrategy
{
public
static
class
Multiple
RemoteAddressStrategy
implements
RemoteA
ddressStrategy
{
private
final
Set
<
String
>
multipleSet
=
new
HashSet
<>();
public
Multiple
Neta
ddressStrategy
(
String
[]
strArray
)
{
public
Multiple
RemoteA
ddressStrategy
(
String
[]
strArray
)
{
for
(
String
netaddress
:
strArray
)
{
AclUtils
.
verify
(
netaddress
,
4
);
multipleSet
.
add
(
netaddress
);
...
...
@@ -72,11 +72,11 @@ public class NetaddressStrategyFactory {
}
public
static
class
One
NetaddressStrategy
implements
Neta
ddressStrategy
{
public
static
class
One
RemoteAddressStrategy
implements
RemoteA
ddressStrategy
{
private
String
netaddress
;
public
One
Neta
ddressStrategy
(
String
netaddress
)
{
public
One
RemoteA
ddressStrategy
(
String
netaddress
)
{
this
.
netaddress
=
netaddress
;
AclUtils
.
verify
(
netaddress
,
4
);
}
...
...
@@ -88,7 +88,7 @@ public class NetaddressStrategyFactory {
}
public
static
class
Range
NetaddressStrategy
implements
Neta
ddressStrategy
{
public
static
class
Range
RemoteAddressStrategy
implements
RemoteA
ddressStrategy
{
private
String
head
;
...
...
@@ -98,7 +98,7 @@ public class NetaddressStrategyFactory {
private
int
index
;
public
Range
Neta
ddressStrategy
(
String
netaddress
)
{
public
Range
RemoteA
ddressStrategy
(
String
netaddress
)
{
String
[]
strArray
=
StringUtils
.
split
(
netaddress
,
"."
);
if
(
analysis
(
strArray
,
2
)
||
analysis
(
strArray
,
3
))
{
AclUtils
.
verify
(
netaddress
,
index
-
1
);
...
...
@@ -117,14 +117,14 @@ public class NetaddressStrategyFactory {
setValue
(
0
,
255
);
}
else
if
(
AclUtils
.
isMinus
(
value
))
{
if
(
value
.
indexOf
(
"-"
)
==
0
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"Range
Neta
ddressStrategy netaddress examine scope Exception value %s "
,
value
));
throw
new
AclPlugRuntimeException
(
String
.
format
(
"Range
RemoteA
ddressStrategy netaddress examine scope Exception value %s "
,
value
));
}
String
[]
valueArray
=
StringUtils
.
split
(
value
,
"-"
);
this
.
start
=
Integer
.
valueOf
(
valueArray
[
0
]);
this
.
end
=
Integer
.
valueOf
(
valueArray
[
1
]);
if
(!(
AclUtils
.
isScope
(
end
)
&&
AclUtils
.
isScope
(
start
)
&&
start
<=
end
))
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"Range
Neta
ddressStrategy netaddress examine scope Exception start is %s , end is %s"
,
start
,
end
));
throw
new
AclPlugRuntimeException
(
String
.
format
(
"Range
RemoteA
ddressStrategy netaddress examine scope Exception start is %s , end is %s"
,
start
,
end
));
}
}
return
this
.
end
>
0
?
true
:
false
;
...
...
acl/src/test/java/org/apache/rocketmq/acl/plain/PlainAclPlugEngineTest.java
浏览文件 @
87d85991
...
...
@@ -26,8 +26,8 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
org.apache.rocketmq.acl.plain.Plain
AclPlugEngine
.AccessContralAnalysis
;
import
org.apache.rocketmq.acl.plain.Plain
AclPlugEngine
.BrokerAccessControlTransport
;
import
org.apache.rocketmq.acl.plain.Plain
PermissionLoader
.AccessContralAnalysis
;
import
org.apache.rocketmq.acl.plain.Plain
PermissionLoader
.BrokerAccessControlTransport
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.junit.Assert
;
import
org.junit.Before
;
...
...
@@ -38,7 +38,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
PlainAclPlugEngineTest
{
Plain
AclPlugEngine
plainAclPlugEngine
;
Plain
PermissionLoader
plainPermissionLoader
;
AccessContralAnalysis
accessContralAnalysis
=
new
AccessContralAnalysis
();
...
...
@@ -91,10 +91,10 @@ public class PlainAclPlugEngineTest {
accessContralAnalysis
.
analysisClass
(
RequestCode
.
class
);
Map
<
Integer
,
Boolean
>
map
=
accessContralAnalysis
.
analysis
(
brokerAccessControl
);
authenticationInfo
=
new
AuthenticationInfo
(
map
,
brokerAccessControl
,
Neta
ddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
authenticationInfo
=
new
AuthenticationInfo
(
map
,
brokerAccessControl
,
RemoteA
ddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
System
.
setProperty
(
"rocketmq.home.dir"
,
"src/test/resources"
);
plain
AclPlugEngine
=
new
PlainAclPlugEngine
();
plain
PermissionLoader
=
new
PlainPermissionLoader
();
plainAccessResource
=
new
BrokerAccessControl
();
plainAccessResource
.
setAccessKey
(
"rokcetmq"
);
...
...
@@ -113,38 +113,38 @@ public class PlainAclPlugEngineTest {
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
accountNullTest
()
{
plainAccessResource
.
setAccessKey
(
null
);
plain
AclPlugEngine
.
setAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setAccessControl
(
plainAccessResource
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
accountThanTest
()
{
plainAccessResource
.
setAccessKey
(
"123"
);
plain
AclPlugEngine
.
setAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setAccessControl
(
plainAccessResource
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
passWordtNullTest
()
{
plainAccessResource
.
setAccessKey
(
null
);
plain
AclPlugEngine
.
setAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setAccessControl
(
plainAccessResource
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
passWordThanTest
()
{
plainAccessResource
.
setAccessKey
(
"123"
);
plain
AclPlugEngine
.
setAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setAccessControl
(
plainAccessResource
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
testPlainAclPlugEngineInit
()
{
System
.
setProperty
(
"rocketmq.home.dir"
,
""
);
new
Plain
AclPlugEngine
().
initialize
();
new
Plain
PermissionLoader
().
initialize
();
}
@Test
public
void
authenticationInfoOfSetAccessControl
()
{
plain
AclPlugEngine
.
setAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setAccessControl
(
plainAccessResource
);
AuthenticationInfo
authenticationInfo
=
plain
AclPlugEngine
.
getAccessControl
(
plainAccessResource
);
AuthenticationInfo
authenticationInfo
=
plain
PermissionLoader
.
getAccessControl
(
plainAccessResource
);
PlainAccessResource
getPlainAccessResource
=
authenticationInfo
.
getPlainAccessResource
();
Assert
.
assertEquals
(
plainAccessResource
,
getPlainAccessResource
);
...
...
@@ -156,16 +156,16 @@ public class PlainAclPlugEngineTest {
testPlainAccessResource
.
setRecognition
(
"127.0.0.1:1"
);
testPlainAccessResource
.
setAccessKey
(
"rokcetmq1"
);
authenticationInfo
=
plain
AclPlugEngine
.
getAccessControl
(
testPlainAccessResource
);
authenticationInfo
=
plain
PermissionLoader
.
getAccessControl
(
testPlainAccessResource
);
Assert
.
assertNull
(
authenticationInfo
);
testPlainAccessResource
.
setAccessKey
(
"rokcetmq"
);
testPlainAccessResource
.
setSignature
(
"1234567"
);
authenticationInfo
=
plain
AclPlugEngine
.
getAccessControl
(
testPlainAccessResource
);
authenticationInfo
=
plain
PermissionLoader
.
getAccessControl
(
testPlainAccessResource
);
Assert
.
assertNull
(
authenticationInfo
);
testPlainAccessResource
.
setRemoteAddr
(
"127.0.0.2"
);
authenticationInfo
=
plain
AclPlugEngine
.
getAccessControl
(
testPlainAccessResource
);
authenticationInfo
=
plain
PermissionLoader
.
getAccessControl
(
testPlainAccessResource
);
Assert
.
assertNull
(
authenticationInfo
);
}
...
...
@@ -176,12 +176,12 @@ public class PlainAclPlugEngineTest {
plainAccessResourceList
.
add
(
plainAccessResourceTwo
);
plain
AclPlugEngine
.
setAccessControlList
(
plainAccessResourceList
);
plain
PermissionLoader
.
setAccessControlList
(
plainAccessResourceList
);
AuthenticationInfo
newAccessControl
=
plain
AclPlugEngine
.
getAccessControl
(
plainAccessResource
);
AuthenticationInfo
newAccessControl
=
plain
PermissionLoader
.
getAccessControl
(
plainAccessResource
);
Assert
.
assertEquals
(
plainAccessResource
,
newAccessControl
.
getPlainAccessResource
());
newAccessControl
=
plain
AclPlugEngine
.
getAccessControl
(
plainAccessResourceTwo
);
newAccessControl
=
plain
PermissionLoader
.
getAccessControl
(
plainAccessResourceTwo
);
Assert
.
assertEquals
(
plainAccessResourceTwo
,
newAccessControl
.
getPlainAccessResource
());
}
...
...
@@ -192,16 +192,16 @@ public class PlainAclPlugEngineTest {
plainAccessResource
.
setAccessKey
(
"RocketMQ"
);
plainAccessResource
.
setSignature
(
"RocketMQ"
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1"
);
plain
AclPlugEngine
.
setAccessControl
(
plainAccessResource
);
plain
AclPlugEngine
.
setNetaddressAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setNetaddressAccessControl
(
plainAccessResource
);
AuthenticationInfo
authenticationInfo
=
plain
AclPlugEngine
.
getAccessControl
(
plainAccessResource
);
AuthenticationInfo
authenticationInfo
=
plain
PermissionLoader
.
getAccessControl
(
plainAccessResource
);
PlainAccessResource
getPlainAccessResource
=
authenticationInfo
.
getPlainAccessResource
();
Assert
.
assertEquals
(
plainAccessResource
,
getPlainAccessResource
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.2"
);
authenticationInfo
=
plain
AclPlugEngine
.
getAccessControl
(
plainAccessResource
);
authenticationInfo
=
plain
PermissionLoader
.
getAccessControl
(
plainAccessResource
);
Assert
.
assertNull
(
authenticationInfo
);
}
...
...
@@ -212,7 +212,7 @@ public class PlainAclPlugEngineTest {
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
BrokerAccessControlTransportTestNull
()
{
BrokerAccessControlTransport
accessControlTransport
=
new
BrokerAccessControlTransport
();
plain
AclPlugEngine
.
setBrokerAccessControlTransport
(
accessControlTransport
);
plain
PermissionLoader
.
setBrokerAccessControlTransport
(
accessControlTransport
);
}
@Test
...
...
@@ -222,17 +222,17 @@ public class PlainAclPlugEngineTest {
list
.
add
((
BrokerAccessControl
)
this
.
plainAccessResourceTwo
);
accessControlTransport
.
setOnlyNetAddress
((
BrokerAccessControl
)
this
.
plainAccessResource
);
accessControlTransport
.
setList
(
list
);
plain
AclPlugEngine
.
setBrokerAccessControlTransport
(
accessControlTransport
);
plain
PermissionLoader
.
setBrokerAccessControlTransport
(
accessControlTransport
);
PlainAccessResource
plainAccessResource
=
new
BrokerAccessControl
();
plainAccessResource
.
setAccessKey
(
"RocketMQ"
);
plainAccessResource
.
setSignature
(
"RocketMQ"
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1"
);
plain
AclPlugEngine
.
setAccessControl
(
plainAccessResource
);
AuthenticationInfo
authenticationInfo
=
plain
AclPlugEngine
.
getAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setAccessControl
(
plainAccessResource
);
AuthenticationInfo
authenticationInfo
=
plain
PermissionLoader
.
getAccessControl
(
plainAccessResource
);
Assert
.
assertNotNull
(
authenticationInfo
.
getPlainAccessResource
());
authenticationInfo
=
plain
AclPlugEngine
.
getAccessControl
(
plainAccessResourceTwo
);
authenticationInfo
=
plain
PermissionLoader
.
getAccessControl
(
plainAccessResourceTwo
);
Assert
.
assertEquals
(
plainAccessResourceTwo
,
authenticationInfo
.
getPlainAccessResource
());
}
...
...
@@ -242,45 +242,45 @@ public class PlainAclPlugEngineTest {
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
plainAccessResource
.
setRequestCode
(
317
);
boolean
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
boolean
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
plainAccessResource
.
setRequestCode
(
321
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
plainAccessResource
.
setRequestCode
(
10
);
plainAccessResource
.
setTopic
(
"permitSendTopic"
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
plainAccessResource
.
setRequestCode
(
310
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
plainAccessResource
.
setRequestCode
(
320
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
plainAccessResource
.
setTopic
(
"noPermitSendTopic"
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
plainAccessResource
.
setTopic
(
"nopermitSendTopic"
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
plainAccessResource
.
setRequestCode
(
11
);
plainAccessResource
.
setTopic
(
"permitPullTopic"
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
plainAccessResource
.
setTopic
(
"noPermitPullTopic"
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
plainAccessResource
.
setTopic
(
"nopermitPullTopic"
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
}
...
...
@@ -290,20 +290,20 @@ public class PlainAclPlugEngineTest {
AuthenticationResult
authenticationResult
=
new
AuthenticationResult
();
plainAccessResource
.
setRequestCode
(
10
);
plainAccessResource
.
setTopic
(
"absentTopic"
);
boolean
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
boolean
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
Set
<
String
>
permitSendTopic
=
new
HashSet
<>();
brokerAccessControl
.
setPermitSendTopic
(
permitSendTopic
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
plainAccessResource
.
setRequestCode
(
11
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertFalse
(
isReturn
);
brokerAccessControl
.
setPermitPullTopic
(
permitSendTopic
);
isReturn
=
plain
AclPlugEngine
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
isReturn
=
plain
PermissionLoader
.
authentication
(
authenticationInfo
,
plainAccessResource
,
authenticationResult
);
Assert
.
assertTrue
(
isReturn
);
}
...
...
@@ -313,11 +313,11 @@ public class PlainAclPlugEngineTest {
admin
.
setAccessKey
(
"adminTest"
);
admin
.
setSignature
(
"adminTest"
);
admin
.
setRemoteAddr
(
"127.0.0.1"
);
plain
AclPlugEngine
.
setAccessControl
(
admin
);
plain
PermissionLoader
.
setAccessControl
(
admin
);
Assert
.
assertFalse
(
admin
.
isUpdateAndCreateTopic
());
admin
.
setAdmin
(
true
);
plain
AclPlugEngine
.
setAccessControl
(
admin
);
plain
PermissionLoader
.
setAccessControl
(
admin
);
Assert
.
assertTrue
(
admin
.
isUpdateAndCreateTopic
());
}
...
...
@@ -327,41 +327,41 @@ public class PlainAclPlugEngineTest {
accessControl
.
setAccessKey
(
"RocketMQ1"
);
accessControl
.
setSignature
(
"1234567"
);
accessControl
.
setRemoteAddr
(
"127.0.0.1"
);
plain
AclPlugEngine
.
setAccessControl
(
accessControl
);
plain
PermissionLoader
.
setAccessControl
(
accessControl
);
for
(
Integer
code
:
adminCode
)
{
accessControl
.
setRequestCode
(
code
);
AuthenticationResult
authenticationResult
=
plain
AclPlugEngine
.
eachCheckAuthentication
(
accessControl
);
AuthenticationResult
authenticationResult
=
plain
PermissionLoader
.
eachCheckAuthentication
(
accessControl
);
Assert
.
assertFalse
(
authenticationResult
.
isSucceed
());
}
plain
AclPlugEngine
.
cleanAuthenticationInfo
();
plain
PermissionLoader
.
cleanAuthenticationInfo
();
accessControl
.
setAdmin
(
true
);
plain
AclPlugEngine
.
setAccessControl
(
accessControl
);
plain
PermissionLoader
.
setAccessControl
(
accessControl
);
for
(
Integer
code
:
adminCode
)
{
accessControl
.
setRequestCode
(
code
);
AuthenticationResult
authenticationResult
=
plain
AclPlugEngine
.
eachCheckAuthentication
(
accessControl
);
AuthenticationResult
authenticationResult
=
plain
PermissionLoader
.
eachCheckAuthentication
(
accessControl
);
Assert
.
assertTrue
(
authenticationResult
.
isSucceed
());
}
}
@Test
public
void
cleanAuthenticationInfoTest
()
{
plain
AclPlugEngine
.
setAccessControl
(
plainAccessResource
);
plain
PermissionLoader
.
setAccessControl
(
plainAccessResource
);
plainAccessResource
.
setRequestCode
(
202
);
AuthenticationResult
authenticationResult
=
plain
AclPlugEngine
.
eachCheckAuthentication
(
plainAccessResource
);
AuthenticationResult
authenticationResult
=
plain
PermissionLoader
.
eachCheckAuthentication
(
plainAccessResource
);
Assert
.
assertTrue
(
authenticationResult
.
isSucceed
());
plain
AclPlugEngine
.
cleanAuthenticationInfo
();
authenticationResult
=
plain
AclPlugEngine
.
eachCheckAuthentication
(
plainAccessResource
);
plain
PermissionLoader
.
cleanAuthenticationInfo
();
authenticationResult
=
plain
PermissionLoader
.
eachCheckAuthentication
(
plainAccessResource
);
Assert
.
assertFalse
(
authenticationResult
.
isSucceed
());
}
@Test
public
void
isWatchStartTest
()
{
Plain
AclPlugEngine
plainAclPlugEngine
=
new
PlainAclPlugEngine
();
Assert
.
assertTrue
(
plain
AclPlugEngine
.
isWatchStart
());
Plain
PermissionLoader
plainPermissionLoader
=
new
PlainPermissionLoader
();
Assert
.
assertTrue
(
plain
PermissionLoader
.
isWatchStart
());
System
.
setProperty
(
"java.version"
,
"1.6.11"
);
plain
AclPlugEngine
=
new
PlainAclPlugEngine
();
Assert
.
assertFalse
(
plain
AclPlugEngine
.
isWatchStart
());
plain
PermissionLoader
=
new
PlainPermissionLoader
();
Assert
.
assertFalse
(
plain
PermissionLoader
.
isWatchStart
());
}
@Test
...
...
@@ -379,9 +379,9 @@ public class PlainAclPlugEngineTest {
writer
.
write
(
" netaddress: 127.0.0.1\r\n"
);
writer
.
flush
();
writer
.
close
();
Plain
AclPlugEngine
plainAclPlugEngine
=
new
PlainAclPlugEngine
();
Plain
PermissionLoader
plainPermissionLoader
=
new
PlainPermissionLoader
();
plainAccessResource
.
setRequestCode
(
203
);
AuthenticationResult
authenticationResult
=
plain
AclPlugEngine
.
eachCheckAuthentication
(
plainAccessResource
);
AuthenticationResult
authenticationResult
=
plain
PermissionLoader
.
eachCheckAuthentication
(
plainAccessResource
);
Assert
.
assertTrue
(
authenticationResult
.
isSucceed
());
writer
=
new
FileWriter
(
new
File
(
"src/test/resources/watch/conf/transport.yml"
),
true
);
...
...
@@ -397,7 +397,7 @@ public class PlainAclPlugEngineTest {
e
.
printStackTrace
();
}
plainAccessResourceTwo
.
setRequestCode
(
203
);
authenticationResult
=
plain
AclPlugEngine
.
eachCheckAuthentication
(
plainAccessResourceTwo
);
authenticationResult
=
plain
PermissionLoader
.
eachCheckAuthentication
(
plainAccessResourceTwo
);
Assert
.
assertTrue
(
authenticationResult
.
isSucceed
());
transport
.
delete
();
...
...
acl/src/test/java/org/apache/rocketmq/acl/plain/
Neta
ddressStrategyTest.java
→
acl/src/test/java/org/apache/rocketmq/acl/plain/
RemoteA
ddressStrategyTest.java
浏览文件 @
87d85991
...
...
@@ -19,74 +19,74 @@ package org.apache.rocketmq.acl.plain;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
Neta
ddressStrategyTest
{
public
class
RemoteA
ddressStrategyTest
{
NetaddressStrategyFactory
netaddressStrategyFactory
=
new
Neta
ddressStrategyFactory
();
RemoteAddressStrategyFactory
remoteAddressStrategyFactory
=
new
RemoteA
ddressStrategyFactory
();
@Test
public
void
NetaddressStrategyFactoryTest
()
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
NetaddressStrategy
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
netaddressStrategy
,
Neta
ddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
RemoteAddressStrategy
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
,
RemoteA
ddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
plainAccessResource
.
setRemoteAddr
(
"*"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
netaddressStrategy
,
Neta
ddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
,
RemoteA
ddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
netaddressStrategy
.
getClass
(),
NetaddressStrategyFactory
.
OneNeta
ddressStrategy
.
class
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
.
getClass
(),
RemoteAddressStrategyFactory
.
OneRemoteA
ddressStrategy
.
class
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1,127.0.0.2,127.0.0.3"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
netaddressStrategy
.
getClass
(),
NetaddressStrategyFactory
.
MultipleNeta
ddressStrategy
.
class
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
.
getClass
(),
RemoteAddressStrategyFactory
.
MultipleRemoteA
ddressStrategy
.
class
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.{1,2,3}"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
netaddressStrategy
.
getClass
(),
NetaddressStrategyFactory
.
MultipleNeta
ddressStrategy
.
class
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
.
getClass
(),
RemoteAddressStrategyFactory
.
MultipleRemoteA
ddressStrategy
.
class
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1-200"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
netaddressStrategy
.
getClass
(),
NetaddressStrategyFactory
.
RangeNeta
ddressStrategy
.
class
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
.
getClass
(),
RemoteAddressStrategyFactory
.
RangeRemoteA
ddressStrategy
.
class
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.*"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
netaddressStrategy
.
getClass
(),
NetaddressStrategyFactory
.
RangeNeta
ddressStrategy
.
class
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
.
getClass
(),
RemoteAddressStrategyFactory
.
RangeRemoteA
ddressStrategy
.
class
);
plainAccessResource
.
setRemoteAddr
(
"127.0.1-20.*"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
netaddressStrategy
.
getClass
(),
NetaddressStrategyFactory
.
RangeNeta
ddressStrategy
.
class
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
Assert
.
assertEquals
(
remoteAddressStrategy
.
getClass
(),
RemoteAddressStrategyFactory
.
RangeRemoteA
ddressStrategy
.
class
);
}
@Test
(
expected
=
AclPlugRuntimeException
.
class
)
public
void
verifyTest
()
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1"
);
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
plainAccessResource
.
setRemoteAddr
(
"256.0.0.1"
);
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
}
@Test
public
void
nullNetaddressStrategyTest
()
{
boolean
isMatch
=
Neta
ddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
.
match
(
new
PlainAccessResource
());
boolean
isMatch
=
RemoteA
ddressStrategyFactory
.
NULL_NET_ADDRESS_STRATEGY
.
match
(
new
PlainAccessResource
());
Assert
.
assertTrue
(
isMatch
);
}
public
void
oneNetaddressStrategyTest
()
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1"
);
NetaddressStrategy
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
RemoteAddressStrategy
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
plainAccessResource
.
setRemoteAddr
(
""
);
boolean
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
boolean
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
Assert
.
assertFalse
(
match
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.2"
);
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
Assert
.
assertFalse
(
match
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1"
);
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
Assert
.
assertTrue
(
match
);
}
...
...
@@ -94,12 +94,12 @@ public class NetaddressStrategyTest {
public
void
multipleNetaddressStrategyTest
()
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1,127.0.0.2,127.0.0.3"
);
NetaddressStrategy
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
multipleNetaddressStrategyTest
(
neta
ddressStrategy
);
RemoteAddressStrategy
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
multipleNetaddressStrategyTest
(
remoteA
ddressStrategy
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.{1,2,3}"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
multipleNetaddressStrategyTest
(
neta
ddressStrategy
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
multipleNetaddressStrategyTest
(
remoteA
ddressStrategy
);
}
...
...
@@ -107,29 +107,29 @@ public class NetaddressStrategyTest {
public
void
multipleNetaddressStrategyExceptionTest
()
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1,2,3}"
);
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
}
private
void
multipleNetaddressStrategyTest
(
NetaddressStrategy
neta
ddressStrategy
)
{
private
void
multipleNetaddressStrategyTest
(
RemoteAddressStrategy
remoteA
ddressStrategy
)
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1"
);
boolean
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
boolean
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
Assert
.
assertTrue
(
match
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.2"
);
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
Assert
.
assertTrue
(
match
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.3"
);
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
Assert
.
assertTrue
(
match
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.4"
);
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
Assert
.
assertFalse
(
match
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.0"
);
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
Assert
.
assertFalse
(
match
);
}
...
...
@@ -139,23 +139,23 @@ public class NetaddressStrategyTest {
String
head
=
"127.0.0."
;
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
setRemoteAddr
(
"127.0.0.1-200"
);
NetaddressStrategy
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
rangeNetaddressStrategyTest
(
neta
ddressStrategy
,
head
,
1
,
200
,
true
);
RemoteAddressStrategy
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
rangeNetaddressStrategyTest
(
remoteA
ddressStrategy
,
head
,
1
,
200
,
true
);
plainAccessResource
.
setRemoteAddr
(
"127.0.0.*"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
rangeNetaddressStrategyTest
(
neta
ddressStrategy
,
head
,
0
,
255
,
true
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
rangeNetaddressStrategyTest
(
remoteA
ddressStrategy
,
head
,
0
,
255
,
true
);
plainAccessResource
.
setRemoteAddr
(
"127.0.1-200.*"
);
netaddressStrategy
=
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
rangeNetaddressStrategyThirdlyTest
(
neta
ddressStrategy
,
head
,
1
,
200
);
remoteAddressStrategy
=
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
rangeNetaddressStrategyThirdlyTest
(
remoteA
ddressStrategy
,
head
,
1
,
200
);
}
private
void
rangeNetaddressStrategyTest
(
NetaddressStrategy
neta
ddressStrategy
,
String
head
,
int
start
,
int
end
,
private
void
rangeNetaddressStrategyTest
(
RemoteAddressStrategy
remoteA
ddressStrategy
,
String
head
,
int
start
,
int
end
,
boolean
isFalse
)
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
for
(
int
i
=
-
10
;
i
<
300
;
i
++)
{
plainAccessResource
.
setRemoteAddr
(
head
+
i
);
boolean
match
=
neta
ddressStrategy
.
match
(
plainAccessResource
);
boolean
match
=
remoteA
ddressStrategy
.
match
(
plainAccessResource
);
if
(
isFalse
&&
i
>=
start
&&
i
<=
end
)
{
Assert
.
assertTrue
(
match
);
continue
;
...
...
@@ -165,13 +165,13 @@ public class NetaddressStrategyTest {
}
}
private
void
rangeNetaddressStrategyThirdlyTest
(
NetaddressStrategy
neta
ddressStrategy
,
String
head
,
int
start
,
private
void
rangeNetaddressStrategyThirdlyTest
(
RemoteAddressStrategy
remoteA
ddressStrategy
,
String
head
,
int
start
,
int
end
)
{
String
newHead
;
for
(
int
i
=
-
10
;
i
<
300
;
i
++)
{
newHead
=
head
+
i
;
if
(
i
>=
start
&&
i
<=
end
)
{
rangeNetaddressStrategyTest
(
neta
ddressStrategy
,
newHead
,
0
,
255
,
false
);
rangeNetaddressStrategyTest
(
remoteA
ddressStrategy
,
newHead
,
0
,
255
,
false
);
}
}
}
...
...
@@ -194,7 +194,7 @@ public class NetaddressStrategyTest {
private
void
rangeNetaddressStrategyExceptionTest
(
String
netaddress
)
{
PlainAccessResource
plainAccessResource
=
new
PlainAccessResource
();
plainAccessResource
.
setRemoteAddr
(
netaddress
);
neta
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
remoteA
ddressStrategyFactory
.
getNetaddressStrategy
(
plainAccessResource
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录