Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sureness
Sureness
提交
1dbca7f3
Sureness
项目概览
sureness
/
Sureness
大约 1 年 前同步成功
通知
32
Star
813
Fork
161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Sureness
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1dbca7f3
编写于
5月 03, 2019
作者:
sinat_25235033
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改tree匹配bug
上级
eca58dbf
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
119 addition
and
16 deletion
+119
-16
core/pom.xml
core/pom.xml
+12
-0
core/src/main/java/com/usthe/sureness/HaTest.java
core/src/main/java/com/usthe/sureness/HaTest.java
+29
-1
core/src/main/java/com/usthe/sureness/matcher/DefaultPathRoleMatcher.java
...va/com/usthe/sureness/matcher/DefaultPathRoleMatcher.java
+1
-1
core/src/main/java/com/usthe/sureness/matcher/TreePathRoleMatcher.java
.../java/com/usthe/sureness/matcher/TreePathRoleMatcher.java
+0
-5
core/src/main/java/com/usthe/sureness/matcher/util/TirePathTreeUtil.java
...ava/com/usthe/sureness/matcher/util/TirePathTreeUtil.java
+16
-7
core/src/main/java/com/usthe/sureness/processor/support/JwtProcessor.java
...va/com/usthe/sureness/processor/support/JwtProcessor.java
+1
-1
core/src/main/java/com/usthe/sureness/subject/support/DefaultSubjectFactory.java
...usthe/sureness/subject/support/DefaultSubjectFactory.java
+1
-1
core/src/test/java/com/usthe/sureness/matcher/util/TirePathTreeUtilTest.java
...com/usthe/sureness/matcher/util/TirePathTreeUtilTest.java
+59
-0
未找到文件。
core/pom.xml
浏览文件 @
1dbca7f3
...
...
@@ -16,6 +16,12 @@
<jjwt.version>
0.9.0
</jjwt.version>
</properties>
<dependencies>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<version>
3.1.0
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
...
...
@@ -32,6 +38,12 @@
<artifactId>
jaxb-api
</artifactId>
<version>
2.3.0
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.12
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
core/src/main/java/com/usthe/sureness/HaTest.java
浏览文件 @
1dbca7f3
package
com.usthe.sureness
;
import
com.sun.tools.javac.util.StringUtils
;
import
com.usthe.sureness.matcher.util.TirePathTreeUtil
;
import
javax.servlet.http.HttpServletRequest
;
import
java.net.http.HttpRequest
;
import
java.util.HashSet
;
import
java.util.Random
;
import
java.util.Scanner
;
import
java.util.Set
;
/**
...
...
@@ -15,10 +18,15 @@ public class HaTest {
public
static
void
main
(
String
[]
args
)
{
String
[]
ps
=
"/"
.
split
(
"/"
);
for
(
String
temp
:
ps
)
{
System
.
out
.
println
(
temp
);
}
TirePathTreeUtil
.
Node
root
=
new
TirePathTreeUtil
.
Node
(
"root"
);
Set
<
String
>
paths
=
new
HashSet
<>();
paths
.
add
(
"/===post===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v2/host===post===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v2/host===get===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v2/host===delete===jwt[role2,role3,role4]"
);
...
...
@@ -45,4 +53,24 @@ public class HaTest {
// System.out.println(ss[0] + ss[1] + ss[2]);
}
public
static
void
ddmain
(
String
[]
args
){
double
x
,
y
,
r
;
Scanner
sc
=
new
Scanner
(
System
.
in
);
long
seed
=
sc
.
nextLong
();
Random
s
=
new
Random
(
seed
);
int
n
=
sc
.
nextInt
();
int
m
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++){
x
=
s
.
nextDouble
()
*
2
-
1
;
// x= x/(double) n;
y
=
s
.
nextDouble
()
*
2
-
1
;
// y = y/(double) n;
if
(
Math
.
sqrt
(
Math
.
pow
(
x
,
2
)
+
Math
.
pow
(
y
,
2
))
<
1
)
{
m
++;
}
}
r
=
4
*
(
double
)
m
/(
double
)
n
;
System
.
out
.
println
(
r
);
}
}
core/src/main/java/com/usthe/sureness/matcher/DefaultPathRoleMatcher.java
浏览文件 @
1dbca7f3
...
...
@@ -16,7 +16,7 @@ import java.util.Set;
*/
public
class
DefaultPathRoleMatcher
implements
TreePathRoleMatcher
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
DefaultPathRoleMatcher
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
DefaultPathRoleMatcher
.
class
);
/**
...
...
core/src/main/java/com/usthe/sureness/matcher/TreePathRoleMatcher.java
浏览文件 @
1dbca7f3
...
...
@@ -9,11 +9,6 @@ import com.usthe.sureness.subject.SubjectAuToken;
*/
public
interface
TreePathRoleMatcher
{
/**
* description 通过targetUri 在树种匹配出所支持的roles
*
*/
/**
* description : 通过auToken中的 targetUri 在树种匹配出所支持的roles 填充到token中
* TODO 抛出定制的异常
...
...
core/src/main/java/com/usthe/sureness/matcher/util/TirePathTreeUtil.java
浏览文件 @
1dbca7f3
package
com.usthe.sureness.matcher.util
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
...
...
@@ -16,27 +17,32 @@ public class TirePathTreeUtil {
private
static
final
String
NODE_TYPE_PATH_END
=
"isPathEnd"
;
private
static
final
String
NODE_TYPE_METHOD
=
"methodNode"
;
private
static
final
String
NODE_TYPE_FILTER_ROLES
=
"filterRolesNode"
;
private
static
final
String
URL_PATH_SPLIT
=
"/"
;
private
static
final
int
PATH_NODE_NUM_3
=
3
;
private
static
final
int
PATH_NODE_NUM_2
=
2
;
/**
* description 插入节点
*
* @param path path = /api/v1/host/detail===GET===jwt[role2,role3,role4]
*/
private
static
void
insertNode
(
String
path
,
Node
root
)
{
if
(
path
==
null
||
""
.
equals
(
path
))
{
if
(
path
==
null
||
""
.
equals
(
path
)
||
!
path
.
startsWith
(
URL_PATH_SPLIT
)
)
{
return
;
}
String
[]
tmp
=
path
.
split
(
"==="
);
if
(
tmp
.
length
!=
PATH_NODE_NUM_3
)
{
return
;
}
String
[]
urlPac
=
tmp
[
0
].
split
(
"/"
);
String
[]
urlPac
=
tmp
[
0
].
split
(
URL_PATH_SPLIT
);
if
(
urlPac
.
length
>
1
)
{
// 去除第一位的空 ""
urlPac
=
Arrays
.
copyOfRange
(
urlPac
,
1
,
urlPac
.
length
);
}
String
method
=
tmp
[
1
];
String
filterRoles
=
tmp
[
2
];
Node
current
=
root
;
...
...
@@ -67,7 +73,7 @@ public class TirePathTreeUtil {
*/
public
static
void
buildTree
(
Set
<
String
>
paths
,
Node
root
)
{
for
(
String
path
:
paths
)
{
insertNode
(
path
,
root
);
insertNode
(
path
,
root
);
}
}
...
...
@@ -95,7 +101,7 @@ public class TirePathTreeUtil {
* @return java.lang.String
*/
public
static
String
searchPathFilterRoles
(
String
path
,
Node
root
)
{
if
(
path
==
null
||
""
.
equals
(
path
))
{
if
(
path
==
null
||
""
.
equals
(
path
)
||
!
path
.
startsWith
(
URL_PATH_SPLIT
)
)
{
return
null
;
}
String
[]
tmp
=
path
.
split
(
"==="
);
...
...
@@ -103,6 +109,9 @@ public class TirePathTreeUtil {
return
null
;
}
String
[]
urlPac
=
tmp
[
0
].
split
(
"/"
);
if
(
urlPac
.
length
>
1
)
{
urlPac
=
Arrays
.
copyOfRange
(
urlPac
,
1
,
urlPac
.
length
);
}
String
method
=
tmp
[
1
];
Node
current
=
root
;
//支持基于ant的模式匹配
...
...
@@ -171,7 +180,7 @@ public class TirePathTreeUtil {
public
static
class
Node
{
p
ublic
Node
(
String
data
,
String
nodeType
)
{
p
rivate
Node
(
String
data
,
String
nodeType
)
{
this
.
data
=
data
;
this
.
nodeType
=
nodeType
;
}
...
...
@@ -190,7 +199,7 @@ public class TirePathTreeUtil {
/**
* 孩子节点
*/
private
Map
<
String
,
Node
>
children
=
new
HashMap
<
String
,
Node
>();
private
Map
<
String
,
Node
>
children
=
new
HashMap
<>();
public
void
insertChild
(
String
data
)
{
this
.
children
.
put
(
data
,
new
Node
(
data
));
...
...
core/src/main/java/com/usthe/sureness/processor/support/JwtProcessor.java
浏览文件 @
1dbca7f3
...
...
@@ -77,7 +77,7 @@ public class JwtProcessor extends BaseProcessor {
List
<
String
>
ownRoles
=
(
List
<
String
>)
var
.
getOwnRoles
();
List
<
String
>
supportRoles
=
(
List
<
String
>)
var
.
getSupportRoles
();
return
supportRoles
==
null
||
supportRoles
.
isEmpty
()
||
supportRoles
.
stream
().
anyMatch
(
role
->
ownRoles
.
contains
(
role
)
);
||
supportRoles
.
stream
().
anyMatch
(
ownRoles:
:
contains
);
}
@Override
...
...
core/src/main/java/com/usthe/sureness/subject/support/DefaultSubjectFactory.java
浏览文件 @
1dbca7f3
...
...
@@ -16,7 +16,7 @@ import java.util.List;
*/
public
class
DefaultSubjectFactory
implements
SubjectFactory
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
SurenessSecurityManager
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SurenessSecurityManager
.
class
);
private
boolean
initFlag
=
false
;
...
...
core/src/test/java/com/usthe/sureness/matcher/util/TirePathTreeUtilTest.java
0 → 100644
浏览文件 @
1dbca7f3
package
com.usthe.sureness.matcher.util
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.util.HashSet
;
import
java.util.Set
;
/**
* @author tomsun28
* @date 12:22 2019-04-09
*/
public
class
TirePathTreeUtilTest
{
private
static
TirePathTreeUtil
.
Node
root
=
null
;
@BeforeClass
public
static
void
setUp
()
throws
Exception
{
root
=
new
TirePathTreeUtil
.
Node
(
"root"
);
}
@AfterClass
public
static
void
tearDown
()
throws
Exception
{
root
=
null
;
}
@Test
public
void
buildTree
()
{
Set
<
String
>
paths
=
new
HashSet
<>();
paths
.
add
(
"/api/v2/host===post===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v2/host===get===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v2/host===delete===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v2/host===put===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v1/host===put===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v3/host===put===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v2/detail===put===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/v2/mom===put===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/*/mom/ha===put===jwt[role2,role3,role4]"
);
paths
.
add
(
"/api/mi/**===put===jwt[role2,role3,role4]"
);
TirePathTreeUtil
.
buildTree
(
paths
,
root
);
Assert
.
assertEquals
(
root
.
getChildren
().
size
(),
1
);
}
@Test
public
void
reBuildTree
()
{
}
@Test
public
void
clearTree
()
{
}
@Test
public
void
searchPathFilterRoles
()
{
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录