Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sh-ds
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李良停
sh-ds
Commits
c848a42d
Commit
c848a42d
authored
Apr 28, 2022
by
wangsong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add auth config logic
parent
06e66f4f
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
920 additions
and
0 deletions
+920
-0
pom.xml
eden-authcenter-agent/pom.xml
+6
-0
AdminUser.java
...m/chineseall/eden/authcenter/agent/account/AdminUser.java
+15
-0
AuthConfigController.java
...den/authcenter/agent/controller/AuthConfigController.java
+126
-0
LoginController.java
...all/eden/authcenter/agent/controller/LoginController.java
+56
-0
ApiInterceptor.java
...all/eden/authcenter/agent/interceptor/ApiInterceptor.java
+57
-0
ApiInterceptorConfig.java
...en/authcenter/agent/interceptor/ApiInterceptorConfig.java
+19
-0
ResponseCode.java
...chineseall/eden/authcenter/agent/result/ResponseCode.java
+129
-0
ResultModel.java
.../chineseall/eden/authcenter/agent/result/ResultModel.java
+83
-0
JwtUtils.java
.../com/chineseall/eden/authcenter/agent/utils/JwtUtils.java
+72
-0
bootstrap.yml
eden-authcenter-agent/src/main/resources/bootstrap.yml
+4
-0
authclient_list.html
.../src/main/resources/templates/config/authclient_list.html
+0
-0
authsource_list.html
.../src/main/resources/templates/config/authsource_list.html
+0
-0
index.html
...nter-agent/src/main/resources/templates/config/index.html
+0
-0
index.html
...enter-agent/src/main/resources/templates/login/index.html
+0
-0
AuthClientDao.java
.../chineseall/eden/authcenter/config/dao/AuthClientDao.java
+30
-0
AuthSourceDao.java
.../chineseall/eden/authcenter/config/dao/AuthSourceDao.java
+30
-0
AuthClient.java
.../chineseall/eden/authcenter/config/entity/AuthClient.java
+50
-0
AuthSource.java
.../chineseall/eden/authcenter/config/entity/AuthSource.java
+58
-0
AuthClientService.java
...all/eden/authcenter/config/service/AuthClientService.java
+18
-0
AuthSourceService.java
...all/eden/authcenter/config/service/AuthSourceService.java
+19
-0
AuthClientServiceImpl.java
...authcenter/config/service/impl/AuthClientServiceImpl.java
+71
-0
AuthSourceServiceImpl.java
...authcenter/config/service/impl/AuthSourceServiceImpl.java
+77
-0
No files found.
eden-authcenter-agent/pom.xml
View file @
c848a42d
...
...
@@ -71,6 +71,12 @@
<systemPath>
${project.basedir}/lib/alpha-framework-core-2.0.6.0014.jar
</systemPath>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
<version>
0.7.0
</version>
</dependency>
<!--因配置外部TOMCAT 而配置-->
<dependency>
...
...
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/account/AdminUser.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
account
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
@Getter
@Setter
@Component
@ConfigurationProperties
(
"admin-user"
)
public
class
AdminUser
{
private
String
account
;
private
String
password
;
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/AuthConfigController.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
com.chineseall.eden.authcenter.agent.result.ResponseCode
;
import
com.chineseall.eden.authcenter.agent.result.ResultModel
;
import
com.chineseall.eden.authcenter.config.entity.AuthClient
;
import
com.chineseall.eden.authcenter.config.entity.AuthSource
;
import
com.chineseall.eden.authcenter.config.service.AuthClientService
;
import
com.chineseall.eden.authcenter.config.service.AuthSourceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
@Controller
@RequestMapping
(
"/config"
)
public
class
AuthConfigController
{
@Autowired
private
AuthSourceService
authSourceService
;
@Autowired
private
AuthClientService
authClientService
;
@GetMapping
(
"index"
)
public
String
index
(){
return
"config/index"
;
}
/**
* 认证源列表
* @param model
* @return
*/
@GetMapping
(
"authsource/list"
)
public
String
authSourceList
(
Model
model
){
List
<
AuthSource
>
dataList
=
authSourceService
.
listAll
();
model
.
addAttribute
(
"dataList"
,
dataList
);
return
"config/authsource_list"
;
}
@PostMapping
(
"authsource/save"
)
@ResponseBody
public
ResultModel
<
Boolean
>
saveAuthSource
(
@RequestBody
AuthSource
data
){
return
ResultModel
.
success
(
authSourceService
.
saveAuthSource
(
data
));
}
@GetMapping
(
"authsource/detail"
)
@ResponseBody
public
ResultModel
<
AuthSource
>
authSourceDetail
(
@RequestParam
(
"key"
)
String
key
){
if
(
StringUtils
.
isBlank
(
key
)){
return
ResultModel
.
error
(
ResponseCode
.
ParamsNull
);
}
AuthSource
data
=
authSourceService
.
getAuthSourceByKey
(
key
);
if
(
data
==
null
){
return
ResultModel
.
error
(
ResponseCode
.
RecordNotExist
);
}
return
ResultModel
.
success
(
data
);
}
@GetMapping
(
"authsource/changestatus"
)
@ResponseBody
public
ResultModel
<
Boolean
>
changeAuthSourceStatus
(
@RequestParam
(
"key"
)
String
key
,
@RequestParam
(
"status"
)
Integer
status
){
if
(
StringUtils
.
isBlank
(
key
)
||
status
==
null
){
return
ResultModel
.
error
(
ResponseCode
.
ParamsNull
);
}
return
ResultModel
.
success
(
authSourceService
.
changeStatus
(
key
,
status
));
}
/**
* 认证源列表
* @param model
* @return
*/
@GetMapping
(
"authclient/list"
)
public
String
authClientList
(
Model
model
){
List
<
AuthClient
>
dataList
=
authClientService
.
listAll
();
model
.
addAttribute
(
"dataList"
,
dataList
);
return
"config/authclient_list"
;
}
@PostMapping
(
"authclient/save"
)
@ResponseBody
public
ResultModel
<
Boolean
>
saveAuthClient
(
@RequestBody
AuthClient
data
){
return
ResultModel
.
success
(
authClientService
.
saveAuthClient
(
data
));
}
@GetMapping
(
"authclient/detail"
)
@ResponseBody
public
ResultModel
<
AuthClient
>
authClientDetail
(
@RequestParam
(
"key"
)
String
key
){
if
(
StringUtils
.
isBlank
(
key
)){
return
ResultModel
.
error
(
ResponseCode
.
ParamsNull
);
}
AuthClient
data
=
authClientService
.
getAuthClientByKey
(
key
);
if
(
data
==
null
){
return
ResultModel
.
error
(
ResponseCode
.
RecordNotExist
);
}
return
ResultModel
.
success
(
data
);
}
@GetMapping
(
"authclient/changestatus"
)
@ResponseBody
public
ResultModel
<
Boolean
>
changeAuthClientStatus
(
@RequestParam
(
"key"
)
String
key
,
@RequestParam
(
"status"
)
Integer
status
){
if
(
StringUtils
.
isBlank
(
key
)
||
status
==
null
){
return
ResultModel
.
error
(
ResponseCode
.
ParamsNull
);
}
return
ResultModel
.
success
(
authClientService
.
changeStatus
(
key
,
status
));
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/LoginController.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
com.chineseall.eden.authcenter.agent.account.AdminUser
;
import
com.chineseall.eden.authcenter.agent.utils.JwtUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
@Controller
@RequestMapping
(
"/login"
)
public
class
LoginController
{
@Autowired
private
AdminUser
adminUser
;
@GetMapping
(
"index"
)
public
String
index
(){
return
"login_page"
;
}
@PostMapping
(
"login"
)
public
String
login
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestBody
AdminUser
loginInfo
){
if
(
loginInfo
==
null
){
return
"/login/index"
;
}
if
(
Objects
.
equals
(
adminUser
.
getAccount
(),
loginInfo
.
getAccount
())
&&
Objects
.
equals
(
adminUser
.
getPassword
(),
loginInfo
.
getPassword
())){
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"account"
,
loginInfo
.
getAccount
());
map
.
put
(
"password"
,
loginInfo
.
getPassword
());
Cookie
cookie
=
new
Cookie
(
"sign"
,
JwtUtils
.
createJWT
(
map
));
cookie
.
setMaxAge
(
24
*
60
*
60
);
cookie
.
setPath
(
"/"
);
response
.
addCookie
(
cookie
);
return
"/config/index"
;
}
else
{
return
"/login/index"
;
}
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/interceptor/ApiInterceptor.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
interceptor
;
import
cn.sh.chineseall.framework.core.util.MapUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.chineseall.eden.authcenter.agent.utils.JwtUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
@Service
public
class
ApiInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
o
)
throws
Exception
{
Cookie
[]
cookies
=
request
.
getCookies
();
boolean
checkResult
=
false
;
if
(
cookies
!=
null
&&
cookies
.
length
>
0
){
Cookie
signCookie
=
Arrays
.
stream
(
cookies
).
filter
(
p
->
Objects
.
equals
(
p
.
getName
(),
"sign"
)).
findFirst
().
orElse
(
null
);
if
(
signCookie
!=
null
){
String
sign
=
signCookie
.
getValue
();
Map
<
String
,
Object
>
userInfo
=
JwtUtils
.
parseJWT
(
sign
);
if
(
MapUtils
.
isNotEmpty
(
userInfo
))
{
checkResult
=
true
;
}
}
}
if
(!
checkResult
){
response
.
sendRedirect
(
"redirect:"
+
request
.
getContextPath
()
+
"/login/index"
);
}
return
checkResult
;
}
@Override
public
void
postHandle
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
,
Object
o
,
ModelAndView
modelAndView
)
throws
Exception
{
}
@Override
public
void
afterCompletion
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
,
Object
o
,
Exception
e
)
throws
Exception
{
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/interceptor/ApiInterceptorConfig.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
interceptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistration
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
@Configuration
public
class
ApiInterceptorConfig
extends
WebMvcConfigurerAdapter
{
@Autowired
ApiInterceptor
apiInterceptor
;
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
//注册TestInterceptor拦截器
InterceptorRegistration
registration
=
registry
.
addInterceptor
(
apiInterceptor
);
registration
.
addPathPatterns
(
"/config/**"
);
//
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/result/ResponseCode.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
result
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
java.util.Arrays
;
/**
* 状态码
*
*/
@AllArgsConstructor
@Getter
public
enum
ResponseCode
{
/**
* 所有失败的操作均指定为999,未知错误
*/
Error
(
999
,
"失败"
),
/**
* 令牌不合法
*/
TokenUnValidate
(
998
,
"令牌不合法"
),
/**
* 签名不合法
*/
SignUnValidate
(
997
,
"签名不合法"
),
/**
* 签名丢失
*/
SignHeaderMiss
(
996
,
"必须传递签名"
),
/**
* 用户类型缺失
*/
UserTypeMiss
(
990
,
"必须传递用户类型"
),
AppIdMiss
(
993
,
"缺少APPID"
),
/**
* 签名时间不正确
*/
SignTimeOver
(
995
,
"签名时间不正确"
),
/**
* 用户名或者密码不正确
*/
ErrorUserNameOrPassword
(
994
,
"用户名或者密码不正确"
),
UserNameInvalid
(
9941
,
"用户名无效"
),
PasswordIncorrect
(
9942
,
"密码不正确"
),
AccountDisabled
(
9943
,
"账户已冻结"
),
NoLogin
(
9945
,
"请登录后在操作"
),
/**
* 签名时间错误
*/
DeviceLocalTimeError
(
991
,
"签名时间错误"
),
/**
* 成功
*/
Success
(
1
,
"成功"
),
/**
* 数据库操作失败
*/
DBError
(
1015
,
"数据库操作错误"
),
/**
* 参数不全
*/
ParamsNull
(
1002
,
"参数不全"
),
/**
* 不支持的HTTP方法
*/
MethodNotSupport
(
1001
,
"不支持的HTTP方法"
),
NoHandlerFoundException
(
1003
,
"请求的方法不存在"
),
/**
* 请求数据错误
*/
DataInvalid
(
1500
,
"请求数据无效"
),
/**
* 验证码无效
*/
VerifyCodeError
(
2001
,
"验证码错误"
),
RecordNotExist
(
2002
,
"数据不存在"
),
RecordAlreadyExist
(
2000
,
"数据已存在"
),
RecordAlreadyProcess
(
2003
,
"数据已处理"
),
HasNoRight
(
2004
,
"您无权进行操作"
),
/**
* 未进行初始化
*/
NotInitialized
(
3001
,
"未进行初始化"
),
/**
* 不支持
*/
UnSupport
(
99999
,
"不支持"
),
;
public
final
Integer
code
;
public
final
String
desc
;
public
static
ResponseCode
of
(
Integer
code
)
{
return
Arrays
.
stream
(
values
()).
filter
(
i
->
i
.
code
.
equals
(
code
)).
findFirst
().
orElse
(
Error
);
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/result/ResultModel.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
result
;
import
cn.sh.chineseall.framework.core.repackaged.org.apache.commons.lang3.StringUtils
;
import
lombok.Data
;
import
java.util.Objects
;
/**
* 返回数据模型定义
* @param <T>
*/
@Data
public
class
ResultModel
<
T
>
{
private
Integer
code
;
private
String
msg
;
private
T
data
;
public
ResultModel
(){
}
public
boolean
isSuccess
(){
return
Objects
.
equals
(
getCode
(),
ResponseCode
.
Success
.
getCode
());
}
public
ResultModel
(
ResponseCode
responseCode
){
this
.
setCode
(
responseCode
.
code
);
this
.
setMsg
(
responseCode
.
desc
);
}
public
ResultModel
(
ResponseCode
responseCode
,
String
msg
){
this
.
setCode
(
responseCode
.
code
);
this
.
setMsg
(
StringUtils
.
isNotBlank
(
msg
)?
msg
:
responseCode
.
desc
);
}
public
ResultModel
(
Integer
code
,
String
msg
){
this
.
setCode
(
code
);
this
.
setMsg
(
msg
);
}
public
static
<
T
>
ResultModel
<
T
>
success
(){
return
success
(
null
);
}
public
static
<
T
>
ResultModel
<
T
>
ok
(){
return
success
();
}
public
static
<
T
>
ResultModel
<
T
>
ok
(
T
data
){
return
success
(
data
);
}
public
static
<
T
>
ResultModel
<
T
>
success
(
T
data
){
ResultModel
<
T
>
model
=
new
ResultModel
<
T
>();
model
.
setCode
(
1
);
model
.
setMsg
(
"成功"
);
model
.
setData
(
data
);
return
model
;
}
public
static
<
T
>
ResultModel
<
T
>
error
(){
return
error
(
ResponseCode
.
Error
);
}
public
static
<
T
>
ResultModel
<
T
>
error
(
ResponseCode
responseCode
){
return
new
ResultModel
<>(
responseCode
);
}
public
static
<
T
>
ResultModel
<
T
>
error
(
String
msg
){
return
new
ResultModel
<>(
ResponseCode
.
Error
,
msg
);
}
public
static
<
T
>
ResultModel
<
T
>
error
(
ResponseCode
responseCode
,
String
msg
){
return
new
ResultModel
<>(
responseCode
,
msg
);
}
public
static
<
T
>
ResultModel
<
T
>
error
(
Integer
code
,
String
msg
){
return
new
ResultModel
<>(
code
,
msg
);
}
}
\ No newline at end of file
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/utils/JwtUtils.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
utils
;
import
cn.sh.chineseall.framework.api.random.RandomUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
com.alibaba.fastjson.JSON
;
import
io.jsonwebtoken.*
;
import
org.apache.xerces.impl.dv.util.Base64
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.util.Date
;
import
java.util.Map
;
public
class
JwtUtils
{
private
static
final
String
JWT_SECRET
=
"or00RX0XnUfDVr5w"
;
private
static
long
TOKEN_TIMEOUT_MILLIS
=
1
*
24
*
60
*
60
*
1000
;
/**
* 签发JWT
*
* @return String
*
*/
public
static
String
createJWT
(
Map
<
String
,
Object
>
dataMap
)
{
SignatureAlgorithm
signatureAlgorithm
=
SignatureAlgorithm
.
HS256
;
long
nowMillis
=
System
.
currentTimeMillis
();
Date
now
=
new
Date
(
nowMillis
);
SecretKey
secretKey
=
generalKey
();
String
jsonString
=
JSON
.
toJSONString
(
dataMap
);
JwtBuilder
builder
=
Jwts
.
builder
().
setId
(
String
.
valueOf
(
nowMillis
)).
setSubject
(
jsonString
)
// 主题
.
setIssuer
(
"user"
)
// 签发者
.
setIssuedAt
(
now
)
// 签发时间
.
signWith
(
signatureAlgorithm
,
secretKey
);
// 签名算法以及密匙
long
expMillis
=
nowMillis
+
TOKEN_TIMEOUT_MILLIS
;
Date
expDate
=
new
Date
(
expMillis
);
builder
.
setExpiration
(
expDate
);
// 过期时间
return
builder
.
compact
();
}
private
static
SecretKey
generalKey
()
{
byte
[]
encodedKey
=
Base64
.
decode
(
JWT_SECRET
);
SecretKey
key
=
new
SecretKeySpec
(
encodedKey
,
0
,
encodedKey
.
length
,
"AES"
);
return
key
;
}
/**
*
* 解析JWT字符串
*
* @param jwt
* @return
* @throws Exception
*/
public
static
Map
<
String
,
Object
>
parseJWT
(
String
jwt
)
{
SecretKey
secretKey
=
generalKey
();
try
{
Claims
claims
=
Jwts
.
parser
().
setSigningKey
(
secretKey
).
parseClaimsJws
(
jwt
).
getBody
();
if
(
claims
!=
null
){
String
subject
=
claims
.
getSubject
();
if
(
subject
!=
null
){
return
(
Map
<
String
,
Object
>)
JSON
.
parseObject
(
subject
,
Map
.
class
);
}
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
null
;
}
}
eden-authcenter-agent/src/main/resources/bootstrap.yml
View file @
c848a42d
...
...
@@ -176,5 +176,9 @@ oauthclient:
clientId
:
adaptive-learning
clientSecret
:
adaptive-learningSecret
admin-user
:
account
:
ac_admin
password
:
AC_PWD_2022
eden-authcenter-agent/src/main/resources/templates/config/authclient_list.html
0 → 100644
View file @
c848a42d
eden-authcenter-agent/src/main/resources/templates/config/authsource_list.html
0 → 100644
View file @
c848a42d
eden-authcenter-agent/src/main/resources/templates/config/index.html
0 → 100644
View file @
c848a42d
eden-authcenter-agent/src/main/resources/templates/login/index.html
0 → 100644
View file @
c848a42d
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/dao/AuthClientDao.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
config
.
dao
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.dao.core.hql.Criteria
;
import
cn.sh.chineseall.framework.dao.core.hql.Query
;
import
cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao
;
import
com.chineseall.eden.authcenter.config.entity.AuthClient
;
import
com.chineseall.eden.authcenter.config.entity.AuthSource
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
@Component
public
class
AuthClientDao
extends
StaticCacheDimensionDocumentMongoDao
<
AuthClient
,
String
>
{
public
List
<
AuthClient
>
loadAll
(){
Criteria
criteria
=
Criteria
.
where
(
"deleted"
).
is
(
false
);
return
query
(
new
Query
(
criteria
));
}
public
AuthClient
loadByKey
(
String
key
){
if
(
StringUtils
.
isBlank
(
key
)){
return
null
;
}
Criteria
criteria
=
Criteria
.
where
(
"key"
).
is
(
key
).
and
(
"deleted"
).
is
(
false
);
return
query
(
new
Query
(
criteria
)).
stream
().
findFirst
().
orElse
(
null
);
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/dao/AuthSourceDao.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
config
.
dao
;
import
cn.sh.chineseall.framework.cache.core.annotation.CacheMethod
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.dao.core.hql.Criteria
;
import
cn.sh.chineseall.framework.dao.core.hql.Query
;
import
cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao
;
import
com.chineseall.eden.authcenter.config.entity.AuthSource
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
@Component
public
class
AuthSourceDao
extends
StaticCacheDimensionDocumentMongoDao
<
AuthSource
,
String
>
{
public
List
<
AuthSource
>
loadAll
(){
Criteria
criteria
=
Criteria
.
where
(
"deleted"
).
is
(
false
);
return
query
(
new
Query
(
criteria
));
}
public
AuthSource
loadByKey
(
String
key
){
if
(
StringUtils
.
isBlank
(
key
)){
return
null
;
}
Criteria
criteria
=
Criteria
.
where
(
"key"
).
is
(
key
).
and
(
"deleted"
).
is
(
false
);
return
query
(
new
Query
(
criteria
)).
stream
().
findFirst
().
orElse
(
null
);
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/entity/AuthClient.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
config
.
entity
;
import
cn.sh.chineseall.framework.dao.core.CacheDimensionDocument
;
import
cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection
;
import
cn.sh.chineseall.framework.dao.core.annotation.DocumentCreateTimestamp
;
import
cn.sh.chineseall.framework.dao.core.annotation.DocumentId
;
import
cn.sh.chineseall.framework.dao.core.annotation.DocumentUpdateTimestamp
;
import
cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentCollection
;
import
cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentDatabase
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.Date
;
/**
* 认证客户端
*/
@Getter
@Setter
@DocumentConnection
(
configName
=
"mongo"
)
@DocumentDatabase
(
database
=
"dslog"
)
@DocumentCollection
(
collection
=
"auth_client"
)
public
class
AuthClient
implements
CacheDimensionDocument
{
@DocumentId
private
String
id
;
private
String
key
;
private
String
name
;
private
String
secret
;
private
String
whiteRule
;
// 白名单规则
private
Integer
status
;
// 状态 1:启用 2:停用
private
Boolean
deleted
;
// 是否已删除
private
Date
deletedTime
;
// 删除时间
@DocumentCreateTimestamp
private
Date
createdTime
;
@DocumentUpdateTimestamp
private
Date
updatedTime
;
@Override
public
String
[]
generateCacheDimensions
()
{
return
new
String
[
0
];
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/entity/AuthSource.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
config
.
entity
;
import
cn.sh.chineseall.framework.dao.core.CacheDimensionDocument
;
import
cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection
;
import
cn.sh.chineseall.framework.dao.core.annotation.DocumentCreateTimestamp
;
import
cn.sh.chineseall.framework.dao.core.annotation.DocumentId
;
import
cn.sh.chineseall.framework.dao.core.annotation.DocumentUpdateTimestamp
;
import
cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentCollection
;
import
cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentDatabase
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.Date
;
/**
* 认证源
*/
@Getter
@Setter
@DocumentConnection
(
configName
=
"mongo"
)
@DocumentDatabase
(
database
=
"dslog"
)
@DocumentCollection
(
collection
=
"auth_source"
)
public
class
AuthSource
implements
CacheDimensionDocument
{
@DocumentId
private
String
id
;
private
String
key
;
// 标识
private
String
name
;
private
Integer
authType
;
// 认证方式: 1:oauth 2: idp
private
String
oauthUrl
;
private
String
clientId
;
private
String
clientSecret
;
private
String
loginSuccessUrl
;
private
String
logoutSuccessUrl
;
private
Integer
status
;
// 状态 1:启用 2:停用
private
Boolean
deleted
;
// 是否已删除
private
Date
deletedTime
;
// 删除时间
@DocumentCreateTimestamp
private
Date
createdTime
;
@DocumentUpdateTimestamp
private
Date
updatedTime
;
@Override
public
String
[]
generateCacheDimensions
()
{
return
new
String
[
0
];
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/service/AuthClientService.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
config
.
service
;
import
com.chineseall.eden.authcenter.config.entity.AuthClient
;
import
java.util.List
;
public
interface
AuthClientService
{
List
<
AuthClient
>
listAll
();
boolean
saveAuthClient
(
AuthClient
data
);
AuthClient
getAuthClientByKey
(
String
key
);
boolean
changeStatus
(
String
key
,
Integer
status
);
boolean
deleteByKey
(
String
key
);
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/service/AuthSourceService.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
config
.
service
;
import
com.chineseall.eden.authcenter.config.entity.AuthSource
;
import
java.util.List
;
public
interface
AuthSourceService
{
List
<
AuthSource
>
listAll
();
boolean
saveAuthSource
(
AuthSource
data
);
AuthSource
getAuthSourceByKey
(
String
key
);
boolean
changeStatus
(
String
key
,
Integer
status
);
boolean
deleteByKey
(
String
key
);
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/service/impl/AuthClientServiceImpl.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
config
.
service
.
impl
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
com.chineseall.eden.authcenter.config.dao.AuthClientDao
;
import
com.chineseall.eden.authcenter.config.entity.AuthClient
;
import
com.chineseall.eden.authcenter.config.service.AuthClientService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
AuthClientServiceImpl
implements
AuthClientService
{
@Autowired
private
AuthClientDao
authClientDao
;
@Override
public
List
<
AuthClient
>
listAll
()
{
return
authClientDao
.
loadAll
();
}
@Override
public
boolean
saveAuthClient
(
AuthClient
data
)
{
if
(
data
==
null
||
StringUtils
.
isEmpty
(
data
.
getKey
())){
return
false
;
}
AuthClient
entity
=
authClientDao
.
loadByKey
(
data
.
getKey
());
if
(
entity
==
null
){
entity
=
new
AuthClient
();
entity
.
setKey
(
data
.
getKey
());
entity
.
setDeleted
(
false
);
}
entity
.
setName
(
data
.
getName
());
entity
.
setSecret
(
data
.
getSecret
());
entity
.
setWhiteRule
(
data
.
getWhiteRule
());
entity
.
setStatus
(
data
.
getStatus
());
authClientDao
.
upsert
(
entity
);
return
true
;
}
@Override
public
AuthClient
getAuthClientByKey
(
String
key
)
{
if
(
StringUtils
.
isBlank
(
key
)){
return
null
;
}
return
authClientDao
.
loadByKey
(
key
);
}
@Override
public
boolean
changeStatus
(
String
key
,
Integer
status
)
{
AuthClient
entity
=
authClientDao
.
loadByKey
(
key
);
if
(
entity
!=
null
){
entity
.
setStatus
(
status
);
authClientDao
.
upsert
(
entity
);
}
return
true
;
}
@Override
public
boolean
deleteByKey
(
String
key
)
{
AuthClient
entity
=
authClientDao
.
loadByKey
(
key
);
if
(
entity
!=
null
){
entity
.
setDeleted
(
true
);
entity
.
setDeletedTime
(
new
Date
());
authClientDao
.
upsert
(
entity
);
}
return
true
;
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/service/impl/AuthSourceServiceImpl.java
0 → 100644
View file @
c848a42d
package
com
.
chineseall
.
eden
.
authcenter
.
config
.
service
.
impl
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
com.chineseall.eden.authcenter.config.dao.AuthSourceDao
;
import
com.chineseall.eden.authcenter.config.entity.AuthClient
;
import
com.chineseall.eden.authcenter.config.entity.AuthSource
;
import
com.chineseall.eden.authcenter.config.service.AuthSourceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
AuthSourceServiceImpl
implements
AuthSourceService
{
@Autowired
private
AuthSourceDao
authSourceDao
;
@Override
public
List
<
AuthSource
>
listAll
()
{
return
authSourceDao
.
loadAll
();
}
@Override
public
boolean
saveAuthSource
(
AuthSource
data
)
{
if
(
data
==
null
||
StringUtils
.
isEmpty
(
data
.
getKey
())){
return
false
;
}
AuthSource
entity
=
authSourceDao
.
loadByKey
(
data
.
getKey
());
if
(
entity
==
null
){
entity
=
new
AuthSource
();
entity
.
setKey
(
data
.
getKey
());
entity
.
setDeleted
(
false
);
}
entity
.
setName
(
data
.
getName
());
entity
.
setAuthType
(
data
.
getAuthType
());
entity
.
setOauthUrl
(
data
.
getOauthUrl
());
entity
.
setClientId
(
data
.
getClientId
());
entity
.
setClientSecret
(
data
.
getClientSecret
());
entity
.
setLoginSuccessUrl
(
data
.
getLoginSuccessUrl
());
entity
.
setLogoutSuccessUrl
(
data
.
getLogoutSuccessUrl
());
entity
.
setStatus
(
data
.
getStatus
());
authSourceDao
.
upsert
(
entity
);
return
true
;
}
@Override
public
AuthSource
getAuthSourceByKey
(
String
key
)
{
if
(
StringUtils
.
isBlank
(
key
)){
return
null
;
}
return
authSourceDao
.
loadByKey
(
key
);
}
@Override
public
boolean
changeStatus
(
String
key
,
Integer
status
)
{
AuthSource
entity
=
authSourceDao
.
loadByKey
(
key
);
if
(
entity
!=
null
){
entity
.
setStatus
(
status
);
authSourceDao
.
upsert
(
entity
);
}
return
true
;
}
@Override
public
boolean
deleteByKey
(
String
key
)
{
AuthSource
entity
=
authSourceDao
.
loadByKey
(
key
);
if
(
entity
!=
null
){
entity
.
setDeleted
(
true
);
entity
.
setDeletedTime
(
new
Date
());
authSourceDao
.
upsert
(
entity
);
}
return
true
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment