Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sureness
Sureness
提交
0550f26d
Sureness
项目概览
sureness
/
Sureness
9 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
0550f26d
编写于
2月 22, 2021
作者:
sinat_25235033
提交者:
GitHub
2月 22, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement authorized default in BaseProcessor (#68)
上级
233800e0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
13 addition
and
41 deletion
+13
-41
core/src/main/java/com/usthe/sureness/processor/BaseProcessor.java
...main/java/com/usthe/sureness/processor/BaseProcessor.java
+12
-1
core/src/main/java/com/usthe/sureness/processor/support/DigestProcessor.java
...com/usthe/sureness/processor/support/DigestProcessor.java
+0
-12
core/src/main/java/com/usthe/sureness/processor/support/JwtProcessor.java
...va/com/usthe/sureness/processor/support/JwtProcessor.java
+0
-13
core/src/main/java/com/usthe/sureness/processor/support/PasswordProcessor.java
...m/usthe/sureness/processor/support/PasswordProcessor.java
+0
-14
sample-tom/src/main/java/com/usthe/sureness/sample/tom/sureness/processor/CustomTokenProcessor.java
...s/sample/tom/sureness/processor/CustomTokenProcessor.java
+1
-1
未找到文件。
core/src/main/java/com/usthe/sureness/processor/BaseProcessor.java
浏览文件 @
0550f26d
...
@@ -2,9 +2,12 @@ package com.usthe.sureness.processor;
...
@@ -2,9 +2,12 @@ package com.usthe.sureness.processor;
import
com.usthe.sureness.processor.exception.SurenessAuthenticationException
;
import
com.usthe.sureness.processor.exception.SurenessAuthenticationException
;
import
com.usthe.sureness.processor.exception.SurenessAuthorizationException
;
import
com.usthe.sureness.processor.exception.SurenessAuthorizationException
;
import
com.usthe.sureness.processor.exception.UnauthorizedException
;
import
com.usthe.sureness.subject.SubjectSum
;
import
com.usthe.sureness.subject.SubjectSum
;
import
com.usthe.sureness.subject.Subject
;
import
com.usthe.sureness.subject.Subject
;
import
java.util.List
;
/**
/**
* abstract processor
* abstract processor
* @author tomsun28
* @author tomsun28
...
@@ -48,5 +51,13 @@ public abstract class BaseProcessor implements Processor{
...
@@ -48,5 +51,13 @@ public abstract class BaseProcessor implements Processor{
* @param var subject
* @param var subject
* @throws SurenessAuthorizationException when authorize error
* @throws SurenessAuthorizationException when authorize error
*/
*/
public
abstract
void
authorized
(
Subject
var
)
throws
SurenessAuthorizationException
;
@SuppressWarnings
(
"unchecked"
)
public
void
authorized
(
Subject
var
)
throws
SurenessAuthorizationException
{
List
<
String
>
ownRoles
=
(
List
<
String
>)
var
.
getOwnRoles
();
List
<
String
>
supportRoles
=
(
List
<
String
>)
var
.
getSupportRoles
();
if
(
supportRoles
==
null
||
supportRoles
.
isEmpty
()
||
supportRoles
.
stream
().
anyMatch
(
ownRoles:
:
contains
))
{
return
;
}
throw
new
UnauthorizedException
(
"do not have the role to access resource"
);
}
}
}
core/src/main/java/com/usthe/sureness/processor/support/DigestProcessor.java
浏览文件 @
0550f26d
...
@@ -12,7 +12,6 @@ import org.slf4j.LoggerFactory;
...
@@ -12,7 +12,6 @@ import org.slf4j.LoggerFactory;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.List
;
/**
/**
* process digest auth - DigestSubject
* process digest auth - DigestSubject
...
@@ -88,17 +87,6 @@ public class DigestProcessor extends BaseProcessor {
...
@@ -88,17 +87,6 @@ public class DigestProcessor extends BaseProcessor {
.
build
();
.
build
();
}
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
void
authorized
(
Subject
var
)
throws
SurenessAuthorizationException
{
List
<
String
>
ownRoles
=
(
List
<
String
>)
var
.
getOwnRoles
();
List
<
String
>
supportRoles
=
(
List
<
String
>)
var
.
getSupportRoles
();
if
(
supportRoles
==
null
||
supportRoles
.
isEmpty
()
||
supportRoles
.
stream
().
anyMatch
(
ownRoles:
:
contains
))
{
return
;
}
throw
new
UnauthorizedException
(
"do not have the role to access resource"
);
}
private
String
getAuthenticate
(){
private
String
getAuthenticate
(){
String
nonce
=
calcDigest
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
String
nonce
=
calcDigest
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
return
"Digest "
+
"realm="
+
realm
+
",nonce="
+
nonce
+
",qop="
+
qop
;
return
"Digest "
+
"realm="
+
realm
+
",nonce="
+
nonce
+
",qop="
+
qop
;
...
...
core/src/main/java/com/usthe/sureness/processor/support/JwtProcessor.java
浏览文件 @
0550f26d
...
@@ -4,8 +4,6 @@ import com.usthe.sureness.processor.BaseProcessor;
...
@@ -4,8 +4,6 @@ import com.usthe.sureness.processor.BaseProcessor;
import
com.usthe.sureness.processor.exception.ExpiredCredentialsException
;
import
com.usthe.sureness.processor.exception.ExpiredCredentialsException
;
import
com.usthe.sureness.processor.exception.IncorrectCredentialsException
;
import
com.usthe.sureness.processor.exception.IncorrectCredentialsException
;
import
com.usthe.sureness.processor.exception.SurenessAuthenticationException
;
import
com.usthe.sureness.processor.exception.SurenessAuthenticationException
;
import
com.usthe.sureness.processor.exception.SurenessAuthorizationException
;
import
com.usthe.sureness.processor.exception.UnauthorizedException
;
import
com.usthe.sureness.subject.PrincipalMap
;
import
com.usthe.sureness.subject.PrincipalMap
;
import
com.usthe.sureness.subject.Subject
;
import
com.usthe.sureness.subject.Subject
;
import
com.usthe.sureness.subject.support.JwtSubject
;
import
com.usthe.sureness.subject.support.JwtSubject
;
...
@@ -80,15 +78,4 @@ public class JwtProcessor extends BaseProcessor {
...
@@ -80,15 +78,4 @@ public class JwtProcessor extends BaseProcessor {
return
builder
.
build
();
return
builder
.
build
();
}
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
void
authorized
(
Subject
var
)
throws
SurenessAuthorizationException
{
List
<
String
>
ownRoles
=
(
List
<
String
>)
var
.
getOwnRoles
();
List
<
String
>
supportRoles
=
(
List
<
String
>)
var
.
getSupportRoles
();
if
(
supportRoles
==
null
||
supportRoles
.
isEmpty
()
||
supportRoles
.
stream
().
anyMatch
(
ownRoles:
:
contains
))
{
return
;
}
throw
new
UnauthorizedException
(
"do not have the role to access resource"
);
}
}
}
core/src/main/java/com/usthe/sureness/processor/support/PasswordProcessor.java
浏览文件 @
0550f26d
...
@@ -5,8 +5,6 @@ import com.usthe.sureness.processor.exception.DisabledAccountException;
...
@@ -5,8 +5,6 @@ import com.usthe.sureness.processor.exception.DisabledAccountException;
import
com.usthe.sureness.processor.exception.ExcessiveAttemptsException
;
import
com.usthe.sureness.processor.exception.ExcessiveAttemptsException
;
import
com.usthe.sureness.processor.exception.IncorrectCredentialsException
;
import
com.usthe.sureness.processor.exception.IncorrectCredentialsException
;
import
com.usthe.sureness.processor.exception.SurenessAuthenticationException
;
import
com.usthe.sureness.processor.exception.SurenessAuthenticationException
;
import
com.usthe.sureness.processor.exception.SurenessAuthorizationException
;
import
com.usthe.sureness.processor.exception.UnauthorizedException
;
import
com.usthe.sureness.processor.exception.UnknownAccountException
;
import
com.usthe.sureness.processor.exception.UnknownAccountException
;
import
com.usthe.sureness.provider.SurenessAccount
;
import
com.usthe.sureness.provider.SurenessAccount
;
import
com.usthe.sureness.provider.SurenessAccountProvider
;
import
com.usthe.sureness.provider.SurenessAccountProvider
;
...
@@ -16,7 +14,6 @@ import com.usthe.sureness.util.Md5Util;
...
@@ -16,7 +14,6 @@ import com.usthe.sureness.util.Md5Util;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
/**
/**
* the processor support username password - PasswordSubject
* the processor support username password - PasswordSubject
...
@@ -75,17 +72,6 @@ public class PasswordProcessor extends BaseProcessor {
...
@@ -75,17 +72,6 @@ public class PasswordProcessor extends BaseProcessor {
.
build
();
.
build
();
}
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
void
authorized
(
Subject
var
)
throws
SurenessAuthorizationException
{
List
<
String
>
ownRoles
=
(
List
<
String
>)
var
.
getOwnRoles
();
List
<
String
>
supportRoles
=
(
List
<
String
>)
var
.
getSupportRoles
();
if
(
supportRoles
==
null
||
supportRoles
.
isEmpty
()
||
supportRoles
.
stream
().
anyMatch
(
ownRoles:
:
contains
))
{
return
;
}
throw
new
UnauthorizedException
(
"do not have the role to access resource"
);
}
public
void
setAccountProvider
(
SurenessAccountProvider
provider
)
{
public
void
setAccountProvider
(
SurenessAccountProvider
provider
)
{
this
.
accountProvider
=
provider
;
this
.
accountProvider
=
provider
;
}
}
...
...
sample-tom/src/main/java/com/usthe/sureness/sample/tom/sureness/processor/CustomTokenProcessor.java
浏览文件 @
0550f26d
...
@@ -86,7 +86,7 @@ public class CustomTokenProcessor extends BaseProcessor {
...
@@ -86,7 +86,7 @@ public class CustomTokenProcessor extends BaseProcessor {
if
(
supportRoles
==
null
||
supportRoles
.
isEmpty
()
||
supportRoles
.
stream
().
anyMatch
(
ownRoles:
:
contains
))
{
if
(
supportRoles
==
null
||
supportRoles
.
isEmpty
()
||
supportRoles
.
stream
().
anyMatch
(
ownRoles:
:
contains
))
{
return
;
return
;
}
}
throw
new
UnauthorizedException
(
"do not have the role to access resource"
);
throw
new
UnauthorizedException
(
"
custom authorized:
do not have the role to access resource"
);
}
}
public
void
setAccountProvider
(
SurenessAccountProvider
accountProvider
)
{
public
void
setAccountProvider
(
SurenessAccountProvider
accountProvider
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录