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
74b4b318
Commit
74b4b318
authored
May 23, 2022
by
喻春霖
Browse files
Options
Browse Files
Download
Plain Diff
ds发布上线
parents
32828439
2184307b
Changes
40
Hide whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
3644 additions
and
1155 deletions
+3644
-1155
pom.xml
eden-authcenter-agent/pom.xml
+25
-0
EdenAuthcenterAgentApplication.java
...eden/authcenter/agent/EdenAuthcenterAgentApplication.java
+1
-1
AdminUser.java
...m/chineseall/eden/authcenter/agent/account/AdminUser.java
+15
-0
ClientDataInfo.java
...ineseall/eden/authcenter/agent/client/ClientDataInfo.java
+1
-1
AuthConfigController.java
...den/authcenter/agent/controller/AuthConfigController.java
+131
-0
AuthController.java
...eall/eden/authcenter/agent/controller/AuthController.java
+241
-145
LogController.java
...seall/eden/authcenter/agent/controller/LogController.java
+33
-0
LoginController.java
...all/eden/authcenter/agent/controller/LoginController.java
+54
-0
StatisticsController.java
...den/authcenter/agent/controller/StatisticsController.java
+356
-0
UcenterController.java
...l/eden/authcenter/agent/controller/UcenterController.java
+667
-0
AccessInterceptor.java
.../eden/authcenter/agent/interceptor/AccessInterceptor.java
+29
-0
ApiInterceptor.java
...all/eden/authcenter/agent/interceptor/ApiInterceptor.java
+57
-0
ApiInterceptorConfig.java
...en/authcenter/agent/interceptor/ApiInterceptorConfig.java
+36
-0
JwtUtils.java
.../com/chineseall/eden/authcenter/agent/utils/JwtUtils.java
+72
-0
application.yml
eden-authcenter-agent/src/main/resources/application.yml
+5
-154
bootstrap.yml
eden-authcenter-agent/src/main/resources/bootstrap.yml
+6
-153
log4j.xml
eden-authcenter-agent/src/main/resources/log4j.xml
+121
-0
statistics.css
...center-agent/src/main/resources/static/css/statistics.css
+6
-1
authclient_list.html
.../src/main/resources/templates/config/authclient_list.html
+282
-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
+46
-0
ds.html
eden-authcenter-agent/src/main/resources/templates/ds.html
+1
-1
index.html
...enter-agent/src/main/resources/templates/login/index.html
+76
-0
statistics.html
...center-agent/src/main/resources/templates/statistics.html
+637
-695
pom.xml
eden-authcenter-log/pom.xml
+21
-0
AuthClientDao.java
.../chineseall/eden/authcenter/config/dao/AuthClientDao.java
+29
-0
AuthSourceDao.java
.../chineseall/eden/authcenter/config/dao/AuthSourceDao.java
+29
-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
+76
-0
AuthLogDao.java
...va/com/chineseall/eden/authcenter/log/dao/AuthLogDao.java
+152
-4
AuthLog.java
...ava/com/chineseall/eden/authcenter/log/model/AuthLog.java
+2
-0
AuthLogHourCount.java
...hineseall/eden/authcenter/log/model/AuthLogHourCount.java
+17
-0
AuthLogService.java
...hineseall/eden/authcenter/log/service/AuthLogService.java
+9
-0
AuthLogServiceImpl.java
.../eden/authcenter/log/service/impl/AuthLogServiceImpl.java
+59
-0
BusinessLogUtils.java
...chineseall/eden/authcenter/log/util/BusinessLogUtils.java
+28
-0
RequestResponseHolder.java
...seall/eden/authcenter/log/util/RequestResponseHolder.java
+108
-0
No files found.
eden-authcenter-agent/pom.xml
View file @
74b4b318
...
@@ -17,6 +17,25 @@
...
@@ -17,6 +17,25 @@
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
<exclusions>
<!-- 排除自带的logback依赖 -->
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-log4j2
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-core
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
...
@@ -71,6 +90,12 @@
...
@@ -71,6 +90,12 @@
<systemPath>
${project.basedir}/lib/alpha-framework-core-2.0.6.0014.jar
</systemPath>
<systemPath>
${project.basedir}/lib/alpha-framework-core-2.0.6.0014.jar
</systemPath>
</dependency>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
<version>
0.7.0
</version>
</dependency>
<!--因配置外部TOMCAT 而配置-->
<!--因配置外部TOMCAT 而配置-->
<dependency>
<dependency>
...
...
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/EdenAuthcenterAgentApplication.java
View file @
74b4b318
...
@@ -7,7 +7,7 @@ import org.springframework.boot.web.support.SpringBootServletInitializer;
...
@@ -7,7 +7,7 @@ import org.springframework.boot.web.support.SpringBootServletInitializer;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.ComponentScan
;
@AlphaFrameworkApplication
@AlphaFrameworkApplication
@ComponentScan
(
basePackages
=
{
"com.chineseall.eden.authcenter.agent"
,
"com.chineseall.eden.authcenter.log"
})
@ComponentScan
(
basePackages
=
{
"com.chineseall.eden.authcenter.agent"
,
"com.chineseall.eden.authcenter.log"
,
"com.chineseall.eden.authcenter.config"
})
public
class
EdenAuthcenterAgentApplication
extends
SpringBootServletInitializer
{
public
class
EdenAuthcenterAgentApplication
extends
SpringBootServletInitializer
{
@Override
@Override
protected
SpringApplicationBuilder
configure
(
SpringApplicationBuilder
builder
)
{
protected
SpringApplicationBuilder
configure
(
SpringApplicationBuilder
builder
)
{
...
...
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/account/AdminUser.java
0 → 100644
View file @
74b4b318
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/client/ClientDataInfo.java
View file @
74b4b318
...
@@ -10,6 +10,6 @@ public class ClientDataInfo {
...
@@ -10,6 +10,6 @@ public class ClientDataInfo {
private
String
returnUrl
;
private
String
returnUrl
;
private
OauthType
oauthType
;
private
String
oauthType
;
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/AuthConfigController.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
cn.sh.chineseall.framework.api.MapMessage
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
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
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
MapMessage
saveAuthSource
(
@RequestBody
AuthSource
data
){
boolean
result
=
authSourceService
.
saveAuthSource
(
data
);
return
result
?
MapMessage
.
successMessage
():
MapMessage
.
errorMessage
();
}
@GetMapping
(
"authsource/detail"
)
@ResponseBody
public
MapMessage
authSourceDetail
(
@RequestParam
(
"key"
)
String
key
){
if
(
StringUtils
.
isBlank
(
key
)){
return
MapMessage
.
errorMessage
(
"参数不全"
);
}
AuthSource
data
=
authSourceService
.
getAuthSourceByKey
(
key
);
if
(
data
==
null
){
return
MapMessage
.
errorMessage
(
"数据不存在"
);
}
return
MapMessage
.
successMessage
().
add
(
"data"
,
data
);
}
@PostMapping
(
"authsource/changestatus"
)
@ResponseBody
public
MapMessage
changeAuthSourceStatus
(
@RequestParam
(
"key"
)
String
key
,
@RequestParam
(
"status"
)
Integer
status
){
if
(
StringUtils
.
isBlank
(
key
)
||
status
==
null
){
return
MapMessage
.
errorMessage
(
"参数不全"
);
}
MapMessage
message
=
new
MapMessage
();
message
.
setSuccess
(
authSourceService
.
changeStatus
(
key
,
status
));
return
message
;
}
/**
* 认证源列表
* @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
MapMessage
saveAuthClient
(
@RequestBody
AuthClient
data
){
MapMessage
message
=
new
MapMessage
();
message
.
setSuccess
(
authClientService
.
saveAuthClient
(
data
));
return
message
;
}
@GetMapping
(
"authclient/detail"
)
@ResponseBody
public
MapMessage
authClientDetail
(
@RequestParam
(
"key"
)
String
key
){
if
(
StringUtils
.
isBlank
(
key
)){
return
MapMessage
.
errorMessage
(
"参数不全"
);
}
AuthClient
data
=
authClientService
.
getAuthClientByKey
(
key
);
if
(
data
==
null
){
return
MapMessage
.
errorMessage
(
"数据不存在"
);
}
return
MapMessage
.
successMessage
().
add
(
"data"
,
data
);
}
@PostMapping
(
"authclient/changestatus"
)
@ResponseBody
public
MapMessage
changeAuthClientStatus
(
@RequestParam
(
"key"
)
String
key
,
@RequestParam
(
"status"
)
Integer
status
){
if
(
StringUtils
.
isBlank
(
key
)
||
status
==
null
){
return
MapMessage
.
errorMessage
(
"参数不全"
);
}
MapMessage
message
=
new
MapMessage
();
message
.
setSuccess
(
authClientService
.
changeStatus
(
key
,
status
));
return
message
;
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/AuthController.java
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
cn.sh.chineseall.framework.core.util.ArrayUtils
;
import
cn.sh.chineseall.framework.core.util.ArrayUtils
;
import
cn.sh.chineseall.framework.core.util.CollectionUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.lang.calendar.DateUtils
;
import
cn.sh.chineseall.framework.lang.calendar.DateUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.chineseall.eden.authcenter.agent.client.AuthUserInfo
;
import
com.chineseall.eden.authcenter.agent.client.*
;
import
com.chineseall.eden.authcenter.agent.client.ClientDataInfo
;
import
com.chineseall.eden.authcenter.agent.oauth.OauthConfig
;
import
com.chineseall.eden.authcenter.agent.client.UserType
;
import
com.chineseall.eden.authcenter.agent.oauth.OauthConfigItem
;
import
com.chineseall.eden.authcenter.agent.oauth.OauthType
;
import
com.chineseall.eden.authcenter.agent.utils.ConvertMessageMapToBean
;
import
com.chineseall.eden.authcenter.agent.utils.ConvertMessageMapToBean
;
import
com.chineseall.eden.authcenter.agent.utils.EncodeUtil
;
import
com.chineseall.eden.authcenter.agent.utils.EncodeUtil
;
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
com.chineseall.eden.authcenter.log.enums.LogType
;
import
com.chineseall.eden.authcenter.log.enums.LogType
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.LogUserInfo
;
import
com.chineseall.eden.authcenter.log.model.LogUserInfo
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
import
com.sh.chineseall.framework.core.http.resttemplate.MyRestTemplate
;
import
com.sh.chineseall.framework.core.http.resttemplate.MyRestTemplate
;
import
org.apache.log4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
...
@@ -28,10 +32,7 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -28,10 +32,7 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.util.Date
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.function.Function
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -39,13 +40,18 @@ import java.util.stream.Collectors;
...
@@ -39,13 +40,18 @@ import java.util.stream.Collectors;
@RequestMapping
(
"/"
)
@RequestMapping
(
"/"
)
public
class
AuthController
{
public
class
AuthController
{
Logger
logger
=
Logger
.
getLogger
(
AuthController
.
class
);
Logger
logger
=
Logger
Factory
.
getLogger
(
AuthController
.
class
);
@Autowired
// @Autowired
private
OauthClient
oauthClient
;
// private OauthClient oauthClient;
//
// @Autowired
// private OauthConfig oauthConfig;
@Autowired
@Autowired
private
OauthConfig
oauthConfig
;
private
AuthClientService
authClientService
;
@Autowired
private
AuthSourceService
authSourceService
;
@Resource
@Resource
private
AuthLogService
authLogService
;
private
AuthLogService
authLogService
;
...
@@ -56,7 +62,10 @@ public class AuthController {
...
@@ -56,7 +62,10 @@ public class AuthController {
public
ModelAndView
index
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
ModelAndView
index
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
ModelAndView
modelAndView
=
new
ModelAndView
();
modelAndView
.
setViewName
(
"ds"
);
modelAndView
.
setViewName
(
"ds"
);
Map
<
String
,
ClientItem
>
clientItemMap
=
oauthClient
.
getClients
().
stream
().
collect
(
Collectors
.
toMap
(
ClientItem:
:
getClientId
,
Function
.
identity
()));
List
<
AuthClient
>
authClientList
=
authClientService
.
listAll
();
List
<
AuthSource
>
authSourceList
=
authSourceService
.
listAll
();
Map
<
String
,
AuthClient
>
clientMap
=
authClientList
.
stream
().
collect
(
Collectors
.
toMap
(
AuthClient:
:
getKey
,
Function
.
identity
(),
(
o1
,
o2
)
->
o1
));
// Map<String, ClientItem> clientItemMap = oauthClient.getClients().stream().collect(Collectors.toMap(ClientItem::getClientId, Function.identity()));
try
{
try
{
String
clientId
=
request
.
getParameter
(
"client_id"
);
String
clientId
=
request
.
getParameter
(
"client_id"
);
...
@@ -67,16 +76,16 @@ public class AuthController {
...
@@ -67,16 +76,16 @@ public class AuthController {
authLog
.
setLogType
(
LogType
.
login
);
authLog
.
setLogType
(
LogType
.
login
);
if
(
StringUtils
.
isNotEmpty
(
clientId
)){
if
(
StringUtils
.
isNotEmpty
(
clientId
)){
ClientItem
clientItem
=
clientItem
Map
.
get
(
clientId
);
AuthClient
clientItem
=
client
Map
.
get
(
clientId
);
if
(
null
==
clientItem
)
{
if
(
null
==
clientItem
)
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
return
modelAndView
;
return
modelAndView
;
}
}
authLog
.
setClientId
(
clientId
);
authLog
.
setClientId
(
clientId
);
authLog
.
setAuthSource
(
clientItem
.
get
Client
Name
());
authLog
.
setAuthSource
(
clientItem
.
getName
());
String
sign
=
request
.
getParameter
(
"sign"
);
String
sign
=
request
.
getParameter
(
"sign"
);
String
signOrigin
=
clientItem
.
get
ClientId
()
+
"$$"
+
clientItem
.
getClien
tSecret
();
String
signOrigin
=
clientItem
.
get
Key
()
+
"$$"
+
clientItem
.
ge
tSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
...
@@ -93,22 +102,21 @@ public class AuthController {
...
@@ -93,22 +102,21 @@ public class AuthController {
if
(
StringUtils
.
isNotEmpty
(
loginType
))
{
if
(
StringUtils
.
isNotEmpty
(
loginType
))
{
if
(
StringUtils
.
isNotEmpty
(
returnUrl
)
&&
(
returnUrl
.
contains
(
"readinglab"
)
||
returnUrl
.
contains
(
"read.etextbook.cn"
))){
if
(
StringUtils
.
isNotEmpty
(
returnUrl
)
&&
(
returnUrl
.
contains
(
"readinglab"
)
||
returnUrl
.
contains
(
"read.etextbook.cn"
))){
// 阅览室日志分离
// 阅览室日志分离
ClientItem
item
=
clientItem
Map
.
get
(
"readingroomClientId"
);
AuthClient
item
=
client
Map
.
get
(
"readingroomClientId"
);
authLog
.
setClientId
(
"readingroomClientId"
);
authLog
.
setClientId
(
"readingroomClientId"
);
authLog
.
setAuthSource
(
item
.
get
Client
Name
());
authLog
.
setAuthSource
(
item
.
getName
());
}
else
if
(
"cloudcourse"
.
equals
(
business_client
)
||
"cloudcourse-test"
.
equals
(
business_client
)){
}
else
if
(
"cloudcourse"
.
equals
(
business_client
)
||
"cloudcourse-test"
.
equals
(
business_client
)){
ClientItem
item
=
clientItem
Map
.
get
(
"cloudcourse"
);
AuthClient
item
=
client
Map
.
get
(
"cloudcourse"
);
authLog
.
setClientId
(
"cloudcourse"
);
authLog
.
setClientId
(
"cloudcourse"
);
authLog
.
setAuthSource
(
item
.
get
Client
Name
());
authLog
.
setAuthSource
(
item
.
getName
());
}
else
if
(
"adaptive-learning"
.
equals
(
business_client
)){
}
else
if
(
"adaptive-learning"
.
equals
(
business_client
)){
ClientItem
item
=
clientItem
Map
.
get
(
"adaptive-learning"
);
AuthClient
item
=
client
Map
.
get
(
"adaptive-learning"
);
authLog
.
setClientId
(
"adaptive-learning"
);
authLog
.
setClientId
(
"adaptive-learning"
);
authLog
.
setAuthSource
(
item
.
get
Client
Name
());
authLog
.
setAuthSource
(
item
.
getName
());
}
}
OauthType
oauthType
=
OauthType
.
getValue
(
loginType
);
if
(
authSourceList
.
stream
().
anyMatch
(
p
->
Objects
.
equals
(
p
.
getKey
(),
loginType
))){
if
(
oauthType
!=
null
){
modelAndView
.
addObject
(
"loginType"
,
loginType
);
modelAndView
.
addObject
(
"loginType"
,
loginType
);
}
else
{
}
else
{
modelAndView
.
addObject
(
"loginType"
,
""
);
modelAndView
.
addObject
(
"loginType"
,
""
);
...
@@ -119,21 +127,29 @@ public class AuthController {
...
@@ -119,21 +127,29 @@ public class AuthController {
}
}
authLogService
.
save
(
authLog
);
authLogService
.
save
(
authLog
);
String
logId
=
authLog
.
getId
();
String
dianjiaoguanLoinUrl
=
generateLoginUrl
(
returnUrl
,
OauthType
.
dianjiaoguan
.
getCode
(),
authLog
.
getId
());
if
(
CollectionUtils
.
isNotEmpty
(
authSourceList
)){
modelAndView
.
addObject
(
"dianjiaoguanLoinUrl"
,
dianjiaoguanLoinUrl
);
authSourceList
.
forEach
(
p
->
{
String
edenoperationLoginUrl
=
generateLoginUrl
(
returnUrl
,
OauthType
.
edenoperation
.
getCode
(),
authLog
.
getId
());
modelAndView
.
addObject
(
p
.
getKey
()+
"LoginUrl"
,
generateLoginUrl
(
returnUrl
,
p
,
logId
));
modelAndView
.
addObject
(
"edenoperationLoginUrl"
,
edenoperationLoginUrl
);
});
OauthType
[]
oauthTypes
=
OauthType
.
values
();
for
(
OauthType
oauthType
:
oauthTypes
)
{
if
(
"idp"
.
equals
(
oauthType
.
getType
())){
String
idpAuthTypeUrl
=
generateSpLoginUrl
(
returnUrl
,
oauthType
.
getCode
(),
authLog
.
getId
());
modelAndView
.
addObject
(
oauthType
.
getCode
()+
"LoginUrl"
,
idpAuthTypeUrl
);
}
}
}
// String dianjiaoguanLoinUrl = generateLoginUrl(returnUrl, OauthType.dianjiaoguan.getCode(), authLog.getId());
// modelAndView.addObject("dianjiaoguanLoinUrl", dianjiaoguanLoinUrl);
// String edenoperationLoginUrl = generateLoginUrl(returnUrl, OauthType.edenoperation.getCode(), authLog.getId());
// modelAndView.addObject("edenoperationLoginUrl", edenoperationLoginUrl);
//
// OauthType[] oauthTypes = OauthType.values();
// for (OauthType oauthType : oauthTypes) {
// if ("idp".equals(oauthType.getType())){
//
// String idpAuthTypeUrl = generateSpLoginUrl(returnUrl, oauthType.getCode(), authLog.getId());
// modelAndView.addObject(oauthType.getCode()+"LoginUrl", idpAuthTypeUrl);
// }
// }
modelAndView
.
addObject
(
"logId"
,
authLog
.
getId
());
modelAndView
.
addObject
(
"logId"
,
authLog
.
getId
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -155,8 +171,8 @@ public class AuthController {
...
@@ -155,8 +171,8 @@ public class AuthController {
String
os
=
request
.
getParameter
(
"os"
);
String
os
=
request
.
getParameter
(
"os"
);
try
{
try
{
AuthLog
authLog
=
authLogService
.
getById
(
logId
);
AuthLog
authLog
=
authLogService
.
getById
(
logId
);
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
AuthSource
authSource
=
authSourceService
.
getAuthSourceByKey
(
oauthType
);
authLog
.
setFowardUrl
(
oauthConfigItem
.
getOauthUrl
());
authLog
.
setFowardUrl
(
authSource
.
getOauthUrl
());
authLog
.
setOauthType
(
oauthType
);
authLog
.
setOauthType
(
oauthType
);
authLog
.
setBrowser
(
browser
);
authLog
.
setBrowser
(
browser
);
authLog
.
setVersion
(
version
);
authLog
.
setVersion
(
version
);
...
@@ -169,6 +185,9 @@ public class AuthController {
...
@@ -169,6 +185,9 @@ public class AuthController {
authLog
.
setYear
(
year
);
authLog
.
setYear
(
year
);
authLog
.
setYearMonth
(
yearMonth
);
authLog
.
setYearMonth
(
yearMonth
);
authLog
.
setYearMonthDay
(
yearMonthDay
);
authLog
.
setYearMonthDay
(
yearMonthDay
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
now
);
authLog
.
setHour
(
calendar
.
get
(
Calendar
.
HOUR
));
authLogService
.
save
(
authLog
);
authLogService
.
save
(
authLog
);
response
.
sendRedirect
(
loginUrl
);
response
.
sendRedirect
(
loginUrl
);
return
null
;
return
null
;
...
@@ -184,17 +203,19 @@ public class AuthController {
...
@@ -184,17 +203,19 @@ public class AuthController {
public
ModelAndView
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
ModelAndView
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
ModelAndView
modelAndView
=
new
ModelAndView
();
modelAndView
.
setViewName
(
"logout"
);
modelAndView
.
setViewName
(
"logout"
);
Map
<
String
,
ClientItem
>
clientItemMap
=
oauthClient
.
getClients
().
stream
().
collect
(
Collectors
.
toMap
(
ClientItem:
:
getClientId
,
Function
.
identity
()));
List
<
AuthClient
>
authClientList
=
authClientService
.
listAll
();
Map
<
String
,
AuthClient
>
authClientMap
=
authClientList
.
stream
().
collect
(
Collectors
.
toMap
(
AuthClient:
:
getKey
,
Function
.
identity
(),
(
o1
,
o2
)
->
o1
));
// Map<String, ClientItem> clientItemMap = oauthClient.getClients().stream().collect(Collectors.toMap(ClientItem::getClientId, Function.identity()));
try
{
try
{
String
clientId
=
request
.
getParameter
(
"client_id"
);
String
clientId
=
request
.
getParameter
(
"client_id"
);
ClientItem
clientItem
=
clientItem
Map
.
get
(
clientId
);
AuthClient
clientItem
=
authClient
Map
.
get
(
clientId
);
if
(
clientItem
==
null
)
{
if
(
clientItem
==
null
)
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
return
modelAndView
;
return
modelAndView
;
}
}
String
sign
=
request
.
getParameter
(
"sign"
);
String
sign
=
request
.
getParameter
(
"sign"
);
String
signOrigin
=
clientItem
.
get
ClientId
()
+
"$$"
+
clientItem
.
getClien
tSecret
();
String
signOrigin
=
clientItem
.
get
Key
()
+
"$$"
+
clientItem
.
ge
tSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
...
@@ -214,8 +235,10 @@ public class AuthController {
...
@@ -214,8 +235,10 @@ public class AuthController {
modelAndView
.
addObject
(
"message"
,
"登出方式为空"
);
modelAndView
.
addObject
(
"message"
,
"登出方式为空"
);
return
modelAndView
;
return
modelAndView
;
}
}
OauthType
type
=
OauthType
.
valueOf
(
oauthType
);
if
(
type
==
null
){
List
<
AuthSource
>
authSourceList
=
authSourceService
.
listAll
();
AuthSource
authSource
=
authSourceList
.
stream
().
filter
(
p
->
Objects
.
equals
(
p
.
getKey
(),
oauthType
)).
findFirst
().
orElse
(
null
);
if
(
authSource
==
null
){
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登出方式错误"
);
modelAndView
.
addObject
(
"message"
,
"登出方式错误"
);
return
modelAndView
;
return
modelAndView
;
...
@@ -224,19 +247,22 @@ public class AuthController {
...
@@ -224,19 +247,22 @@ public class AuthController {
authLog
.
setOauthType
(
oauthType
);
authLog
.
setOauthType
(
oauthType
);
authLog
.
setReturnUrl
(
service
);
authLog
.
setReturnUrl
(
service
);
authLog
.
setClientId
(
clientId
);
authLog
.
setClientId
(
clientId
);
authLog
.
setAuthSource
(
clientItem
.
get
Client
Name
());
authLog
.
setAuthSource
(
clientItem
.
getName
());
authLog
.
setLogType
(
LogType
.
logout
);
authLog
.
setLogType
(
LogType
.
logout
);
authLogService
.
save
(
authLog
);
authLogService
.
save
(
authLog
);
if
(
StringUtils
.
isNotEmpty
(
service
))
{
if
(
StringUtils
.
isNotEmpty
(
service
))
{
if
(!
OauthType
.
dianjiaoguan
.
equals
(
type
)
&&
!
OauthType
.
edenoperation
.
equals
(
type
)){
if
(
Objects
.
equals
(
authSource
.
getAuthType
(),
1
)
||
Objects
.
equals
(
authSource
.
getKey
(),
"qpjy"
)){
if
(
OauthType
.
qpjy
.
equals
(
type
)){
response
.
sendRedirect
(
generateLogoutUrl
(
service
,
authSource
));
response
.
sendRedirect
(
generateSpLogoutUrl
(
service
,
type
.
name
()));
}
}
else
{
response
.
sendRedirect
(
generateLogoutUrl
(
service
,
type
.
name
()));
}
}
// if (!OauthType.dianjiaoguan.equals(type) && !OauthType.edenoperation.equals(type)){
// if (OauthType.qpjy.equals(type)){
// response.sendRedirect(generateSpLogoutUrl(service,type.name()));
//
// }
//
// }else{
// response.sendRedirect(generateLogoutUrl(service, type.name()));
// }
}
}
return
null
;
return
null
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -288,9 +314,9 @@ public class AuthController {
...
@@ -288,9 +314,9 @@ public class AuthController {
Map
<
String
,
Object
>
userInfoMap
=
MyRestTemplate
.
exchange
(
HttpMethod
.
GET
,
userInfoUrl
,
null
,
null
,
HashMap
.
class
);
Map
<
String
,
Object
>
userInfoMap
=
MyRestTemplate
.
exchange
(
HttpMethod
.
GET
,
userInfoUrl
,
null
,
null
,
HashMap
.
class
);
// 转换用户信息
// 转换用户信息
AuthUserInfo
userInfo
=
null
;
AuthUserInfo
userInfo
=
null
;
if
(
oauthType
.
equals
(
OauthType
.
dianjiaoguan
.
toString
()
))
if
(
oauthType
.
equals
(
"dianjiaoguan"
))
userInfo
=
ConvertMessageMapToBean
.
converDianjiaoguanData
(
userInfoMap
);
userInfo
=
ConvertMessageMapToBean
.
converDianjiaoguanData
(
userInfoMap
);
else
if
(
oauthType
.
equals
(
OauthType
.
edenoperation
.
toString
()
))
else
if
(
oauthType
.
equals
(
"edenoperation"
))
userInfo
=
ConvertMessageMapToBean
.
converEdenoperationData
(
userInfoMap
);
userInfo
=
ConvertMessageMapToBean
.
converEdenoperationData
(
userInfoMap
);
// 封装下游数据
// 封装下游数据
ClientDataInfo
clientDataInfo
=
new
ClientDataInfo
();
ClientDataInfo
clientDataInfo
=
new
ClientDataInfo
();
...
@@ -322,7 +348,7 @@ public class AuthController {
...
@@ -322,7 +348,7 @@ public class AuthController {
authLog
.
setLogUserInfo
(
logUserInfo
);
authLog
.
setLogUserInfo
(
logUserInfo
);
}
}
clientDataInfo
.
setAuthUserInfo
(
userInfo
);
clientDataInfo
.
setAuthUserInfo
(
userInfo
);
clientDataInfo
.
setOauthType
(
OauthType
.
valueOf
(
oauthType
)
);
clientDataInfo
.
setOauthType
(
oauthType
);
modelAndView
.
addObject
(
"clientDataInfo"
,
clientDataInfo
);
modelAndView
.
addObject
(
"clientDataInfo"
,
clientDataInfo
);
modelAndView
.
addObject
(
"successPostUrl"
,
returnUrl
);
modelAndView
.
addObject
(
"successPostUrl"
,
returnUrl
);
...
@@ -394,7 +420,7 @@ public class AuthController {
...
@@ -394,7 +420,7 @@ public class AuthController {
authLog
.
setLogUserInfo
(
logUserInfo
);
authLog
.
setLogUserInfo
(
logUserInfo
);
}
}
clientDataInfo
.
setAuthUserInfo
(
userInfo
);
clientDataInfo
.
setAuthUserInfo
(
userInfo
);
clientDataInfo
.
setOauthType
(
OauthType
.
valueOf
(
oauthType
)
);
clientDataInfo
.
setOauthType
(
oauthType
);
modelAndView
.
addObject
(
"clientDataInfo"
,
clientDataInfo
);
modelAndView
.
addObject
(
"clientDataInfo"
,
clientDataInfo
);
modelAndView
.
addObject
(
"successPostUrl"
,
returnUrl
);
modelAndView
.
addObject
(
"successPostUrl"
,
returnUrl
);
...
@@ -423,108 +449,168 @@ public class AuthController {
...
@@ -423,108 +449,168 @@ public class AuthController {
return
null
;
return
null
;
}
}
private
String
generateLoginUrl
(
String
returnUrl
,
String
oauthType
,
String
logId
)
{
//oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
private
String
generateLoginUrl
(
String
returnUrl
,
AuthSource
authSource
,
String
logId
){
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
loginUrlBuilder
.
append
(
authSource
.
getOauthUrl
());
loginUrlBuilder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
authSource
.
getOauthUrl
().
endsWith
(
"/"
))
{
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
"/"
);
loginUrlBuilder
.
append
(
"/"
);
}
}
loginUrlBuilder
.
append
(
"oauth2.0/authorize?client_id="
).
append
(
oauthConfigItem
.
getClientId
());
if
(
Objects
.
equals
(
authSource
.
getAuthType
(),
1
)){
String
loginSuccessUrl
=
oauthConfigItem
.
getLoginSuccessUrl
();
// oauth 认证
loginSuccessUrl
=
loginSuccessUrl
+
"?oauth_type="
+
oauthType
+
"&log_id="
+
logId
;
loginUrlBuilder
.
append
(
"oauth2.0/authorize?client_id="
).
append
(
authSource
.
getClientId
());
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
loginUrlBuilder
.
append
(
"&state=state&response_type=code"
);
Map
<
String
,
String
>
param
=
new
HashMap
<>();
}
else
if
(
Objects
.
equals
(
authSource
.
getAuthType
(),
2
)){
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
// idp 认证
loginSuccessUrl
=
appendUrl
(
loginSuccessUrl
,
param
);
loginUrlBuilder
.
append
(
"login?client_id="
).
append
(
authSource
.
getClientId
());
String
sign
=
EncodeUtil
.
md5
(
authSource
.
getClientId
()+
"$$"
+
authSource
.
getClientSecret
());
loginUrlBuilder
.
append
(
"&sign="
).
append
(
sign
);
}
}
loginUrlBuilder
.
append
(
"&redirect_uri="
).
append
(
URLEncoder
.
encode
(
loginSuccessUrl
));
loginUrlBuilder
.
append
(
"&state=state&response_type=code"
);
String
loginSuccessUrl
=
authSource
.
getLoginSuccessUrl
();
return
loginUrlBuilder
.
toString
();
loginSuccessUrl
=
loginSuccessUrl
+
"?oauth_type="
+
authSource
.
getKey
()
+
"&log_id="
+
logId
;
}
private
String
generateSpLoginUrl
(
String
returnUrl
,
String
oauthType
,
String
logId
)
{
//oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
loginUrlBuilder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
"/"
);
}
loginUrlBuilder
.
append
(
"login?client_id="
).
append
(
oauthConfigItem
.
getClientId
());
String
loginSuccessUrl
=
oauthConfigItem
.
getLoginSuccessUrl
();
loginSuccessUrl
=
loginSuccessUrl
+
"?log_id="
+
logId
+
"&oauth_type="
+
oauthType
;
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
Map
<
String
,
String
>
param
=
new
HashMap
<>();
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
loginSuccessUrl
=
appendUrl
(
loginSuccessUrl
,
param
);
loginSuccessUrl
=
appendUrl
(
loginSuccessUrl
,
param
);
}
}
loginUrlBuilder
.
append
(
"&redirect_uri="
).
append
(
URLEncoder
.
encode
(
loginSuccessUrl
));
loginUrlBuilder
.
append
(
"&redirect_uri="
).
append
(
URLEncoder
.
encode
(
loginSuccessUrl
));
String
sign
=
EncodeUtil
.
md5
(
oauthConfigItem
.
getClientId
()+
"$$"
+
oauthConfigItem
.
getClientSecret
());
loginUrlBuilder
.
append
(
"&sign="
+
sign
);
return
loginUrlBuilder
.
toString
();
}
private
String
generateLogoutUrl
(
String
returnUrl
,
String
oauthType
)
{
//oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
loginUrlBuilder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
"/"
);
}
String
service
=
oauthConfigItem
.
getLogoutSuccessUrl
();
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
service
=
appendUrl
(
service
,
param
);
}
loginUrlBuilder
.
append
(
"logout?service="
).
append
(
URLEncoder
.
encode
(
service
));
return
loginUrlBuilder
.
toString
();
return
loginUrlBuilder
.
toString
();
}
}
// private String generateLoginUrl(String returnUrl, String oauthType, String logId) {
private
String
generateSpLogoutUrl
(
String
returnUrl
,
String
oauthType
)
{
// //oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
// StringBuilder loginUrlBuilder = new StringBuilder();
if
(
oauthType
.
equals
(
"qpjy"
)){
// OauthConfigItem oauthConfigItem = oauthConfig.getItems().get(oauthType);
// loginUrlBuilder.append(oauthConfigItem.getOauthUrl());
// if (!oauthConfigItem.getOauthUrl().endsWith("/")) {
// loginUrlBuilder.append("/");
// }
// loginUrlBuilder.append("oauth2.0/authorize?client_id=").append(oauthConfigItem.getClientId());
// String loginSuccessUrl = oauthConfigItem.getLoginSuccessUrl();
// loginSuccessUrl = loginSuccessUrl + "?oauth_type=" + oauthType + "&log_id=" + logId;
// if (StringUtils.isNotEmpty(returnUrl)) {
// Map<String, String> param = new HashMap<>();
// param.put("return_url", URLEncoder.encode(returnUrl));
// loginSuccessUrl = appendUrl(loginSuccessUrl, param);
// }
// loginUrlBuilder.append("&redirect_uri=").append(URLEncoder.encode(loginSuccessUrl));
//
// loginUrlBuilder.append("&state=state&response_type=code");
// return loginUrlBuilder.toString();
// }
//
// private String generateSpLoginUrl(String returnUrl, String oauthType, String logId) {
// //oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
// StringBuilder loginUrlBuilder = new StringBuilder();
// OauthConfigItem oauthConfigItem = oauthConfig.getItems().get(oauthType);
// loginUrlBuilder.append(oauthConfigItem.getOauthUrl());
// if (!oauthConfigItem.getOauthUrl().endsWith("/")) {
// loginUrlBuilder.append("/");
// }
// loginUrlBuilder.append("login?client_id=").append(oauthConfigItem.getClientId());
// String loginSuccessUrl = oauthConfigItem.getLoginSuccessUrl();
// loginSuccessUrl = loginSuccessUrl + "?log_id=" + logId+"&oauth_type=" + oauthType ;
// if (StringUtils.isNotEmpty(returnUrl)) {
// Map<String, String> param = new HashMap<>();
// param.put("return_url", URLEncoder.encode(returnUrl));
// loginSuccessUrl = appendUrl(loginSuccessUrl, param);
// }
// loginUrlBuilder.append("&redirect_uri=").append(URLEncoder.encode(loginSuccessUrl));
// String sign = EncodeUtil.md5( oauthConfigItem.getClientId()+ "$$" + oauthConfigItem.getClientSecret());
// loginUrlBuilder.append("&sign="+sign);
// return loginUrlBuilder.toString();
// }
private
String
generateLogoutUrl
(
String
returnUrl
,
AuthSource
authSource
){
if
(
Objects
.
equals
(
authSource
.
getKey
(),
"qpjy"
)){
returnUrl
=
"https://idp.qpedu.cn/logout/logout.html?redirect_url="
+
returnUrl
;
returnUrl
=
"https://idp.qpedu.cn/logout/logout.html?redirect_url="
+
returnUrl
;
returnUrl
=
"https://sp.etextbook.cn/Shibboleth.sso/Logout?return="
+
URLEncoder
.
encode
(
returnUrl
);
returnUrl
=
"https://sp.etextbook.cn/Shibboleth.sso/Logout?return="
+
URLEncoder
.
encode
(
returnUrl
);
return
returnUrl
;
return
returnUrl
;
}
}
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
loginUrlBuilder
.
append
(
oauthConfigItem
.
getOauthUrl
());
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
authSource
.
getOauthUrl
());
if
(!
authSource
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
"/"
);
loginUrlBuilder
.
append
(
"/"
);
}
}
String
service
=
oauthConfigItem
.
getLogoutSuccessUrl
();
String
service
=
authSource
.
getLogoutSuccessUrl
();
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
Map
<
String
,
String
>
param
=
new
HashMap
<>();
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
service
=
appendUrl
(
service
,
param
);
service
=
appendUrl
(
service
,
param
);
}
}
String
clientId
=
oauthConfigItem
.
getClientId
();
String
signOrigin
=
oauthConfigItem
.
getClientId
()
+
"$$"
+
oauthConfigItem
.
getClientSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
loginUrlBuilder
.
append
(
"logout?service="
).
append
(
URLEncoder
.
encode
(
service
));
loginUrlBuilder
.
append
(
"logout?service="
).
append
(
URLEncoder
.
encode
(
service
));
loginUrlBuilder
.
append
(
"&client_id="
+
clientId
);
if
(
Objects
.
equals
(
authSource
.
getAuthType
(),
2
)){
loginUrlBuilder
.
append
(
"&sign="
+
md5Hex
);
// idp 认证
String
clientId
=
authSource
.
getClientId
();
String
signOrigin
=
authSource
.
getClientId
()
+
"$$"
+
authSource
.
getClientSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
loginUrlBuilder
.
append
(
"&client_id="
+
clientId
);
loginUrlBuilder
.
append
(
"&sign="
+
md5Hex
);
}
return
loginUrlBuilder
.
toString
();
return
loginUrlBuilder
.
toString
();
}
}
// private String generateLogoutUrl(String returnUrl, String oauthType) {
// //oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
// StringBuilder loginUrlBuilder = new StringBuilder();
// OauthConfigItem oauthConfigItem = oauthConfig.getItems().get(oauthType);
//
// loginUrlBuilder.append(oauthConfigItem.getOauthUrl());
// if (!oauthConfigItem.getOauthUrl().endsWith("/")) {
// loginUrlBuilder.append("/");
// }
// String service = oauthConfigItem.getLogoutSuccessUrl();
// if (StringUtils.isNotEmpty(returnUrl)) {
// Map<String, String> param = new HashMap<>();
// param.put("return_url", URLEncoder.encode(returnUrl));
// service = appendUrl(service, param);
// }
// loginUrlBuilder.append("logout?service=").append(URLEncoder.encode(service));
// return loginUrlBuilder.toString();
// }
//
//
// private String generateSpLogoutUrl(String returnUrl, String oauthType) {
//
// if (oauthType.equals("qpjy")){
// returnUrl = "https://idp.qpedu.cn/logout/logout.html?redirect_url=" + returnUrl;
// returnUrl = "https://sp.etextbook.cn/Shibboleth.sso/Logout?return=" + URLEncoder.encode(returnUrl);
// return returnUrl;
// }
// StringBuilder loginUrlBuilder = new StringBuilder();
// OauthConfigItem oauthConfigItem = oauthConfig.getItems().get(oauthType);
//
// loginUrlBuilder.append(oauthConfigItem.getOauthUrl());
// if (!oauthConfigItem.getOauthUrl().endsWith("/")) {
// loginUrlBuilder.append("/");
// }
// String service = oauthConfigItem.getLogoutSuccessUrl();
// if (StringUtils.isNotEmpty(returnUrl)) {
// Map<String, String> param = new HashMap<>();
// param.put("return_url", URLEncoder.encode(returnUrl));
// service = appendUrl(service, param);
// }
//
// String clientId = oauthConfigItem.getClientId();
// String signOrigin = oauthConfigItem.getClientId() + "$$" + oauthConfigItem.getClientSecret();
// String md5Hex = EncodeUtil.md5(signOrigin);
//
// loginUrlBuilder.append("logout?service=").append(URLEncoder.encode(service));
// loginUrlBuilder.append("&client_id="+clientId);
// loginUrlBuilder.append("&sign="+md5Hex);
// return loginUrlBuilder.toString();
// }
private
String
generateUserInfoUrl
(
String
accessToken
,
String
oauthType
)
{
private
String
generateUserInfoUrl
(
String
accessToken
,
String
oauthType
)
{
//String url = "http://castest.edu.sh.cn/CAS/oauth2.0/accessToken?client_id=testClentId&client_secret=testClientSecret&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess2.do&code=" + code;
//String url = "http://castest.edu.sh.cn/CAS/oauth2.0/accessToken?client_id=testClentId&client_secret=testClientSecret&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess2.do&code=" + code;
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
// OauthConfigItem oauthConfigItem = oauthConfig.getItems().get(oauthType);
builder
.
append
(
oauthConfigItem
.
getOauthUrl
());
AuthSource
authSource
=
authSourceService
.
getAuthSourceByKey
(
oauthType
);
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
builder
.
append
(
authSource
.
getOauthUrl
());
if
(!
authSource
.
getOauthUrl
().
endsWith
(
"/"
))
{
builder
.
append
(
"/"
);
builder
.
append
(
"/"
);
}
}
builder
.
append
(
"oauth2.0/profile?access_token="
).
append
(
accessToken
);
builder
.
append
(
"oauth2.0/profile?access_token="
).
append
(
accessToken
);
...
@@ -534,15 +620,16 @@ public class AuthController {
...
@@ -534,15 +620,16 @@ public class AuthController {
private
String
generateAccessTokenUrl
(
String
code
,
String
oauthType
)
{
private
String
generateAccessTokenUrl
(
String
code
,
String
oauthType
)
{
//String url = "http://castest.edu.sh.cn/CAS/oauth2.0/accessToken?client_id=testClentId&client_secret=testClientSecret&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess2.do&code=" + code;
//String url = "http://castest.edu.sh.cn/CAS/oauth2.0/accessToken?client_id=testClentId&client_secret=testClientSecret&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess2.do&code=" + code;
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
// OauthConfigItem oauthConfigItem = oauthConfig.getItems().get(oauthType);
builder
.
append
(
oauthConfigItem
.
getOauthUrl
());
AuthSource
authSource
=
authSourceService
.
getAuthSourceByKey
(
oauthType
);
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
builder
.
append
(
authSource
.
getOauthUrl
());
if
(!
authSource
.
getOauthUrl
().
endsWith
(
"/"
))
{
builder
.
append
(
"/"
);
builder
.
append
(
"/"
);
}
}
builder
.
append
(
"oauth2.0/accessToken?client_id="
).
append
(
oauthConfigItem
.
getClientId
());
builder
.
append
(
"oauth2.0/accessToken?client_id="
).
append
(
authSource
.
getClientId
());
builder
.
append
(
"&client_secret="
).
append
(
oauthConfigItem
.
getClientSecret
());
builder
.
append
(
"&client_secret="
).
append
(
authSource
.
getClientSecret
());
builder
.
append
(
"&code="
).
append
(
code
);
builder
.
append
(
"&code="
).
append
(
code
);
builder
.
append
(
"&redirect_uri="
).
append
(
oauthConfigItem
.
getLoginSuccessUrl
());
builder
.
append
(
"&redirect_uri="
).
append
(
authSource
.
getLoginSuccessUrl
());
builder
.
append
(
"&grant_type=authorization_code"
);
builder
.
append
(
"&grant_type=authorization_code"
);
return
builder
.
toString
();
return
builder
.
toString
();
}
}
...
@@ -574,11 +661,13 @@ public class AuthController {
...
@@ -574,11 +661,13 @@ public class AuthController {
public
ModelAndView
chineseallLogin
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
ModelAndView
chineseallLogin
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
ModelAndView
modelAndView
=
new
ModelAndView
();
modelAndView
.
setViewName
(
"toward"
);
modelAndView
.
setViewName
(
"toward"
);
Map
<
String
,
ClientItem
>
clientItemMap
=
oauthClient
.
getClients
().
stream
().
collect
(
Collectors
.
toMap
(
ClientItem:
:
getClientId
,
Function
.
identity
()));
List
<
AuthClient
>
authClientList
=
authClientService
.
listAll
();
Map
<
String
,
AuthClient
>
clientMap
=
authClientList
.
stream
().
collect
(
Collectors
.
toMap
(
AuthClient:
:
getKey
,
Function
.
identity
(),
(
o1
,
o2
)
->
o1
));
// Map<String, ClientItem> clientItemMap = oauthClient.getClients().stream().collect(Collectors.toMap(ClientItem::getClientId, Function.identity()));
try
{
try
{
String
clientId
=
request
.
getParameter
(
"client_id"
);
String
clientId
=
request
.
getParameter
(
"client_id"
);
String
returnUrl
=
request
.
getParameter
(
"redirect_uri"
);
String
returnUrl
=
request
.
getParameter
(
"redirect_uri"
);
ClientItem
clientItem
=
clientItem
Map
.
get
(
clientId
);
AuthClient
clientItem
=
client
Map
.
get
(
clientId
);
AuthLog
authLog
=
new
AuthLog
();
AuthLog
authLog
=
new
AuthLog
();
authLog
.
setLogType
(
LogType
.
login
);
authLog
.
setLogType
(
LogType
.
login
);
if
(
null
==
clientItem
)
{
if
(
null
==
clientItem
)
{
...
@@ -587,9 +676,9 @@ public class AuthController {
...
@@ -587,9 +676,9 @@ public class AuthController {
return
modelAndView
;
return
modelAndView
;
}
}
authLog
.
setClientId
(
clientId
);
authLog
.
setClientId
(
clientId
);
authLog
.
setAuthSource
(
clientItem
.
get
Client
Name
());
authLog
.
setAuthSource
(
clientItem
.
getName
());
String
sign
=
request
.
getParameter
(
"sign"
);
String
sign
=
request
.
getParameter
(
"sign"
);
String
signOrigin
=
clientItem
.
get
ClientId
()
+
"$$"
+
clientItem
.
getClien
tSecret
();
String
signOrigin
=
clientItem
.
get
Key
()
+
"$$"
+
clientItem
.
ge
tSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
...
@@ -602,11 +691,13 @@ public class AuthController {
...
@@ -602,11 +691,13 @@ public class AuthController {
modelAndView
.
addObject
(
"message"
,
"登录成功回调地址为空"
);
modelAndView
.
addObject
(
"message"
,
"登录成功回调地址为空"
);
return
modelAndView
;
return
modelAndView
;
}
}
authLog
.
setOauthType
(
OauthType
.
dianjiaoguan
.
getCode
());
String
key
=
"dianjiaoguan"
;
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
OauthType
.
dianjiaoguan
.
getCode
());
AuthSource
authSource
=
authSourceService
.
getAuthSourceByKey
(
key
);
authLog
.
setFowardUrl
(
oauthConfigItem
.
getOauthUrl
());
authLog
.
setOauthType
(
key
);
// OauthConfigItem oauthConfigItem = oauthConfig.getItems().get(OauthType.dianjiaoguan.getCode());
authLog
.
setFowardUrl
(
authSource
.
getOauthUrl
());
authLogService
.
save
(
authLog
);
authLogService
.
save
(
authLog
);
String
url
=
generateLoginUrl
(
returnUrl
,
OauthType
.
dianjiaoguan
.
getCode
()
,
authLog
.
getId
());
String
url
=
generateLoginUrl
(
returnUrl
,
authSource
,
authLog
.
getId
());
modelAndView
.
addObject
(
"loginUrl"
,
url
);
modelAndView
.
addObject
(
"loginUrl"
,
url
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -620,17 +711,19 @@ public class AuthController {
...
@@ -620,17 +711,19 @@ public class AuthController {
public
ModelAndView
shLogout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
ModelAndView
shLogout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
ModelAndView
modelAndView
=
new
ModelAndView
();
modelAndView
.
setViewName
(
"logout"
);
modelAndView
.
setViewName
(
"logout"
);
Map
<
String
,
ClientItem
>
clientItemMap
=
oauthClient
.
getClients
().
stream
().
collect
(
Collectors
.
toMap
(
ClientItem:
:
getClientId
,
Function
.
identity
()));
List
<
AuthClient
>
authClientList
=
authClientService
.
listAll
();
Map
<
String
,
AuthClient
>
clientMap
=
authClientList
.
stream
().
collect
(
Collectors
.
toMap
(
AuthClient:
:
getKey
,
Function
.
identity
(),
(
o1
,
o2
)
->
o1
));
// Map<String, ClientItem> clientItemMap = oauthClient.getClients().stream().collect(Collectors.toMap(ClientItem::getClientId, Function.identity()));
try
{
try
{
String
clientId
=
request
.
getParameter
(
"client_id"
);
String
clientId
=
request
.
getParameter
(
"client_id"
);
ClientItem
clientItem
=
clientItem
Map
.
get
(
clientId
);
AuthClient
clientItem
=
client
Map
.
get
(
clientId
);
if
(
clientItem
==
null
)
{
if
(
clientItem
==
null
)
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
return
modelAndView
;
return
modelAndView
;
}
}
String
sign
=
request
.
getParameter
(
"sign"
);
String
sign
=
request
.
getParameter
(
"sign"
);
String
signOrigin
=
clientItem
.
get
ClientId
()
+
"$$"
+
clientItem
.
getClien
tSecret
();
String
signOrigin
=
clientItem
.
get
Key
()
+
"$$"
+
clientItem
.
ge
tSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
...
@@ -645,15 +738,18 @@ public class AuthController {
...
@@ -645,15 +738,18 @@ public class AuthController {
return
modelAndView
;
return
modelAndView
;
}
}
String
key
=
"dianjiaoguan"
;
AuthSource
authSource
=
authSourceService
.
getAuthSourceByKey
(
key
);
AuthLog
authLog
=
new
AuthLog
();
AuthLog
authLog
=
new
AuthLog
();
authLog
.
setOauthType
(
OauthType
.
dianjiaoguan
.
getCode
()
);
authLog
.
setOauthType
(
key
);
authLog
.
setReturnUrl
(
service
);
authLog
.
setReturnUrl
(
service
);
authLog
.
setClientId
(
clientId
);
authLog
.
setClientId
(
clientId
);
authLog
.
setAuthSource
(
clientItem
.
get
Client
Name
());
authLog
.
setAuthSource
(
clientItem
.
getName
());
authLog
.
setLogType
(
LogType
.
logout
);
authLog
.
setLogType
(
LogType
.
logout
);
authLogService
.
save
(
authLog
);
authLogService
.
save
(
authLog
);
if
(
StringUtils
.
isNotEmpty
(
service
))
{
if
(
StringUtils
.
isNotEmpty
(
service
))
{
response
.
sendRedirect
(
generateLogoutUrl
(
service
,
OauthType
.
dianjiaoguan
.
getCode
()
));
response
.
sendRedirect
(
generateLogoutUrl
(
service
,
authSource
));
}
}
return
null
;
return
null
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/LogController.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.chineseall.eden.authcenter.log.util.BusinessLogUtils
;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Map
;
@Controller
@RequestMapping
(
"log"
)
public
class
LogController
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LogController
.
class
);
@GetMapping
(
"test"
)
@ResponseBody
public
void
test
(
HttpServletRequest
request
){
Map
<
String
,
String
[]>
params
=
request
.
getParameterMap
();
BusinessLogUtils
.
info
(
params
);
logger
.
info
(
" ==== logs : "
+
JSON
.
toJSONString
(
params
));
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/LoginController.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
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.*
;
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/index"
;
}
@PostMapping
(
"login"
)
public
String
login
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
account
,
String
password
){
if
(
StringUtils
.
isEmpty
(
account
)
||
StringUtils
.
isEmpty
(
password
)){
return
"/login/index"
;
}
if
(
Objects
.
equals
(
adminUser
.
getAccount
(),
account
)
&&
Objects
.
equals
(
adminUser
.
getPassword
(),
password
)){
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"account"
,
account
);
map
.
put
(
"password"
,
password
);
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/controller/StatisticsController.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
cn.sh.chineseall.framework.api.MapMessage
;
import
cn.sh.chineseall.framework.core.util.CollectionUtils
;
import
cn.sh.chineseall.framework.core.util.MathUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.lang.calendar.DateUtils
;
import
com.chineseall.eden.authcenter.agent.client.ClientItem
;
import
com.chineseall.eden.authcenter.agent.vo.StatItem
;
import
com.chineseall.eden.authcenter.config.entity.AuthClient
;
import
com.chineseall.eden.authcenter.config.service.AuthClientService
;
import
com.chineseall.eden.authcenter.config.service.AuthSourceService
;
import
com.chineseall.eden.authcenter.log.model.AuthLogHourCount
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
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.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Controller
@RequestMapping
(
"statistics"
)
public
class
StatisticsController
{
@Autowired
private
AuthClientService
authClientService
;
@Autowired
private
AuthSourceService
authSourceService
;
@Autowired
private
AuthLogService
authLogService
;
/**
* 接入的应用列表
*
* @return
*/
@GetMapping
(
"auth_apps"
)
@ResponseBody
public
MapMessage
authApps
()
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
List
<
AuthClient
>
clientList
=
authClientService
.
listAll
();
if
(
CollectionUtils
.
isNotEmpty
(
clientList
)){
clientList
.
forEach
(
item
->
{
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"clientId"
,
item
.
getKey
());
data
.
put
(
"name"
,
item
.
getName
());
result
.
add
(
data
);
});
}
return
MapMessage
.
successMessage
().
add
(
"data"
,
result
);
}
private
Date
getStartDay
(
Integer
latestDays
){
Date
now
=
new
Date
();
return
DateUtils
.
calculateDateDay
(
now
,
-
latestDays
);
}
/**
* APP使用情况统计
*
* @param latestDays 最近多少天的统计
* @param topN topN
* @return 指定app的认证数
*/
@GetMapping
(
"app"
)
@ResponseBody
public
MapMessage
applications
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
defaultValue
=
"7"
)
Integer
latestDays
,
@RequestParam
(
value
=
"topN"
,
required
=
false
)
Integer
topN
)
{
List
<
StatItem
>
dataList
=
new
ArrayList
<>();
List
<
AuthClient
>
clientList
=
authClientService
.
listAll
();
if
(
StringUtils
.
isNoneBlank
(
clientId
)){
clientList
=
clientList
.
stream
().
filter
(
p
->
Objects
.
equals
(
p
.
getKey
(),
clientId
)).
collect
(
Collectors
.
toList
());
}
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"loginSuccessFlag"
,
true
);
Date
startDate
=
getStartDay
(
latestDays
);
clientList
.
forEach
(
item
->
{
StatItem
statItem
=
new
StatItem
();
statItem
.
setCode
(
item
.
getKey
());
statItem
.
setName
(
item
.
getName
());
param
.
put
(
"clientId"
,
item
.
getKey
());
long
count
=
authLogService
.
count
(
param
,
startDate
);
statItem
.
setCount
(
count
);
dataList
.
add
(
statItem
);
});
dataList
.
sort
((
o1
,
o2
)
->
Long
.
valueOf
(
o1
.
getCount
()
-
o2
.
getCount
()).
intValue
());
List
<
StatItem
>
result
=
dataList
;
if
(
topN
!=
null
&&
topN
>
0
){
if
(
topN
<
result
.
size
()){
result
=
result
.
subList
(
0
,
topN
);
}
}
return
MapMessage
.
successMessage
().
add
(
"data"
,
result
);
}
/**
* 来源环境情况统计
*
* @param latestDays 最近多少天
* @return
*/
@RequestMapping
(
"environment"
)
@ResponseBody
public
MapMessage
environments
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
defaultValue
=
"7"
)
Integer
latestDays
)
{
Map
<
String
,
List
<
StatItem
>>
result
=
new
HashMap
<>();
Map
<
String
,
Object
>
commonParam
=
new
HashMap
<>();
commonParam
.
put
(
"loginSuccessFlag"
,
true
);
if
(
clientId
!=
null
){
commonParam
.
put
(
"clientId"
,
clientId
);
}
Date
startDate
=
getStartDay
(
latestDays
);
List
<
String
>
browserList
=
authLogService
.
distinct
(
"browser"
,
commonParam
,
startDate
);
List
<
String
>
osList
=
authLogService
.
distinct
(
"os"
,
commonParam
,
startDate
);
Map
<
String
,
List
<
Long
>>
browserOsListMap
=
new
HashMap
<>();
if
(
CollectionUtils
.
isNotEmpty
(
browserList
)
&&
CollectionUtils
.
isNotEmpty
(
osList
)){
for
(
String
browser
:
browserList
)
{
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
putAll
(
commonParam
);
param
.
put
(
"browser"
,
browser
);
long
otherCount
=
authLogService
.
count
(
param
,
startDate
);
List
<
Long
>
osDataList
=
new
ArrayList
<>();
for
(
String
os
:
osList
){
param
.
put
(
"os"
,
os
);
long
osCount
=
authLogService
.
count
(
param
,
startDate
);
osDataList
.
add
(
osCount
);
otherCount
=
otherCount
-
osCount
;
}
osDataList
.
add
(
otherCount
);
browserOsListMap
.
put
(
browser
,
osDataList
);
}
Map
<
String
,
Object
>
unknownParam
=
new
HashMap
<>();
unknownParam
.
putAll
(
commonParam
);
long
unknownOtherCount
=
authLogService
.
count
(
unknownParam
,
browserList
,
startDate
);
List
<
Long
>
unknownDataList
=
new
ArrayList
<>();
for
(
String
os
:
osList
){
unknownParam
.
put
(
"os"
,
os
);
long
osCount
=
authLogService
.
count
(
unknownParam
,
browserList
,
startDate
);
unknownDataList
.
add
(
osCount
);
unknownOtherCount
=
unknownOtherCount
-
osCount
;
}
unknownDataList
.
add
(
unknownOtherCount
);
browserOsListMap
.
put
(
"unknown"
,
unknownDataList
);
}
browserList
.
add
(
"unknown"
);
osList
.
add
(
"unknown"
);
return
MapMessage
.
successMessage
().
add
(
"browserList"
,
browserList
).
add
(
"osList"
,
osList
).
add
(
"dataMap"
,
browserOsListMap
);
}
/**
* 认证热点单位统计
*
* @return
*/
@GetMapping
(
"auth_hot_org"
)
@ResponseBody
public
MapMessage
authHotOrgs
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
defaultValue
=
"7"
)
Integer
latestDays
,
@RequestParam
(
value
=
"topN"
,
required
=
false
)
Integer
topN
)
{
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"loginSuccessFlag"
,
true
);
if
(
clientId
!=
null
){
param
.
put
(
"clientId"
,
clientId
);
}
Date
startDate
=
getStartDay
(
latestDays
);
List
<
String
>
schoolNames
=
authLogService
.
distinct
(
"logUserInfo.schoolName"
,
param
,
startDate
);
List
<
StatItem
>
result
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
schoolNames
)){
for
(
String
name
:
schoolNames
)
{
param
.
put
(
"logUserInfo.schoolName"
,
name
);
long
count
=
authLogService
.
count
(
param
,
startDate
);
StatItem
item
=
new
StatItem
();
item
.
setCount
(
count
);
item
.
setName
(
name
);
result
.
add
(
item
);
}
}
result
.
sort
(
Comparator
.
comparing
(
StatItem:
:
getCount
).
reversed
());
if
(
result
.
size
()>
topN
){
result
=
result
.
subList
(
0
,
topN
);
}
return
MapMessage
.
successMessage
().
add
(
"data"
,
result
);
}
/**
* 认证身份统计
*
* @return
*/
@GetMapping
(
"auth_user_type"
)
@ResponseBody
public
MapMessage
authUserTypes
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
defaultValue
=
"7"
)
Integer
latestDays
)
{
int
type
=
1
;
// 1: 日数据 2: 月数据
if
(
latestDays
>
30
){
type
=
2
;
}
Date
startDate
;
if
(
type
==
1
){
startDate
=
getStartDay
(
latestDays
-
1
);
}
else
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
MONTH
,
-(
latestDays
/
30
-
1
));
startDate
=
calendar
.
getTime
();
}
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<>();
Date
endDate
=
new
Date
();
while
(!
startDate
.
after
(
endDate
)){
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"loginSuccessFlag"
,
true
);
if
(
clientId
!=
null
){
param
.
put
(
"clientId"
,
clientId
);
}
String
dateStr
=
""
;
if
(
Objects
.
equals
(
type
,
1
)){
// 日数据
String
yearMonthDay
=
DateUtils
.
dateToString
(
startDate
,
"yyyy-MM-dd"
);
param
.
put
(
"yearMonthDay"
,
yearMonthDay
);
dateStr
=
DateUtils
.
dateToString
(
startDate
,
"M月dd日"
);
}
else
{
// 月数据
String
yearMonth
=
DateUtils
.
dateToString
(
startDate
,
"yyyy-MM"
);
param
.
put
(
"yearMonth"
,
yearMonth
);
dateStr
=
yearMonth
;
}
long
all_auth
=
authLogService
.
count
(
param
);
param
.
put
(
"logUserInfo.userType"
,
"TEACHER"
);
long
teacherCount
=
authLogService
.
count
(
param
);
param
.
put
(
"logUserInfo.userType"
,
"STUDENT"
);
long
studentCount
=
authLogService
.
count
(
param
);
if
(
Objects
.
equals
(
type
,
1
)){
// 日数据
startDate
=
DateUtils
.
calculateDateDay
(
startDate
,
1
);
}
else
{
// 月数据
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startDate
);
calendar
.
add
(
Calendar
.
MONTH
,
1
);
startDate
=
calendar
.
getTime
();
}
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"date"
,
dateStr
);
data
.
put
(
"teacherCount"
,
teacherCount
);
data
.
put
(
"studentCount"
,
studentCount
);
data
.
put
(
"otherCount"
,
all_auth
-
teacherCount
-
studentCount
);
dataList
.
add
(
data
);
}
return
MapMessage
.
successMessage
().
add
(
"dataList"
,
dataList
);
}
@GetMapping
(
"auth_user_type_sum"
)
@ResponseBody
public
MapMessage
authUserTypeSum
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
defaultValue
=
"7"
)
Integer
latestDays
)
{
int
type
=
1
;
// 1: 日数据 2: 月数据
if
(
latestDays
>
30
){
type
=
2
;
}
Date
startDate
;
if
(
type
==
1
){
startDate
=
getStartDay
(
latestDays
-
1
);
}
else
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
MONTH
,
-(
latestDays
/
30
-
1
));
startDate
=
calendar
.
getTime
();
}
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"loginSuccessFlag"
,
true
);
if
(
clientId
!=
null
){
param
.
put
(
"clientId"
,
clientId
);
}
long
days
=
DateUtils
.
dayDiff
(
new
Date
(),
startDate
);
long
all_auth
=
authLogService
.
count
(
param
,
startDate
);
param
.
put
(
"logUserInfo.userType"
,
"TEACHER"
);
long
teacherCount
=
authLogService
.
count
(
param
,
startDate
);
param
.
put
(
"logUserInfo.userType"
,
"STUDENT"
);
long
studentCount
=
authLogService
.
count
(
param
,
startDate
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"totalCount"
,
all_auth
);
data
.
put
(
"teacherCount"
,
teacherCount
);
data
.
put
(
"studentCount"
,
studentCount
);
data
.
put
(
"otherCount"
,
all_auth
-
teacherCount
-
studentCount
);
data
.
put
(
"avgTotalCount"
,
all_auth
/
days
);
data
.
put
(
"avgTeacherCount"
,
teacherCount
/
days
);
data
.
put
(
"avgStudentCount"
,
studentCount
/
days
);
data
.
put
(
"avgOtherCount"
,
(
all_auth
-
teacherCount
-
studentCount
)/
days
);
return
MapMessage
.
successMessage
().
add
(
"data"
,
data
);
}
/**
* 认证高峰时间数据统计
*
* @return
*/
@GetMapping
(
"auth_pick_times"
)
@ResponseBody
public
MapMessage
authPickTimes
(
@RequestParam
(
value
=
"clientId"
,
required
=
false
)
String
clientId
,
@RequestParam
(
value
=
"latestDays"
,
defaultValue
=
"7"
)
Integer
latestDays
)
{
Map
<
String
,
Object
>
commonParam
=
new
HashMap
<>();
commonParam
.
put
(
"loginSuccessFlag"
,
true
);
if
(
clientId
!=
null
){
commonParam
.
put
(
"clientId"
,
clientId
);
}
Date
startDate
=
getStartDay
(
latestDays
);
List
<
Integer
>
hourList
=
new
ArrayList
<>();
List
<
Long
>
hourCountList
=
new
ArrayList
<>();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
putAll
(
commonParam
);
for
(
int
i
=
0
;
i
<
24
;
i
++){
param
.
put
(
"hour"
,
i
);
long
count
=
authLogService
.
count
(
param
,
startDate
);
hourList
.
add
(
i
);
long
avgCount
=
Double
.
valueOf
(
MathUtils
.
doubleDivide
(
count
,
latestDays
,
0
)).
longValue
();
hourCountList
.
add
(
avgCount
<
1
?
1
:
avgCount
);
}
List
<
AuthLogHourCount
>
hourTopList
=
authLogService
.
hourMaxCount
(
commonParam
,
startDate
,
1
);
AuthLogHourCount
max
=
null
;
if
(
CollectionUtils
.
isNotEmpty
(
hourTopList
)){
max
=
hourTopList
.
get
(
0
);
}
return
MapMessage
.
successMessage
().
add
(
"hourList"
,
hourList
).
add
(
"dataList"
,
hourCountList
).
add
(
"maxHour"
,
max
);
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/controller/UcenterController.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
controller
;
import
cn.sh.chineseall.framework.core.util.ArrayUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.lang.calendar.DateUtils
;
import
com.chineseall.eden.authcenter.agent.client.*
;
import
com.chineseall.eden.authcenter.agent.oauth.OauthConfig
;
import
com.chineseall.eden.authcenter.agent.oauth.OauthConfigItem
;
import
com.chineseall.eden.authcenter.agent.oauth.OauthType
;
import
com.chineseall.eden.authcenter.agent.utils.ConvertMessageMapToBean
;
import
com.chineseall.eden.authcenter.agent.utils.EncodeUtil
;
import
com.chineseall.eden.authcenter.log.enums.LogType
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.LogUserInfo
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
import
com.sh.chineseall.framework.core.http.resttemplate.MyRestTemplate
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.servlet.ModelAndView
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
@Controller
@RequestMapping
(
"/ucenter"
)
public
class
UcenterController
{
Logger
logger
=
LoggerFactory
.
getLogger
(
UcenterController
.
class
);
@Autowired
private
OauthClient
oauthClient
;
@Autowired
private
OauthConfig
oauthConfig
;
@Resource
private
AuthLogService
authLogService
;
@RequestMapping
(
value
=
{
""
,
"auth"
,
"auth/index"
})
public
ModelAndView
index
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
modelAndView
.
setViewName
(
"ds"
);
Map
<
String
,
ClientItem
>
clientItemMap
=
oauthClient
.
getClients
().
stream
().
collect
(
Collectors
.
toMap
(
ClientItem:
:
getClientId
,
Function
.
identity
()));
try
{
String
clientId
=
request
.
getParameter
(
"client_id"
);
String
returnUrl
=
request
.
getParameter
(
"redirect_uri"
);
String
business_client
=
request
.
getParameter
(
"business_client"
);
AuthLog
authLog
=
new
AuthLog
();
authLog
.
setLogType
(
LogType
.
login
);
if
(
StringUtils
.
isNotEmpty
(
clientId
)){
ClientItem
clientItem
=
clientItemMap
.
get
(
clientId
);
if
(
null
==
clientItem
)
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
return
modelAndView
;
}
authLog
.
setClientId
(
clientId
);
authLog
.
setAuthSource
(
clientItem
.
getClientName
());
String
sign
=
request
.
getParameter
(
"sign"
);
String
signOrigin
=
clientItem
.
getClientId
()
+
"$$"
+
clientItem
.
getClientSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"请求不合法"
);
return
modelAndView
;
}
if
(
StringUtils
.
isEmpty
(
returnUrl
))
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登录成功回调地址为空"
);
return
modelAndView
;
}
String
loginType
=
request
.
getParameter
(
"login_type"
);
if
(
StringUtils
.
isNotEmpty
(
loginType
))
{
if
(
StringUtils
.
isNotEmpty
(
returnUrl
)
&&
(
returnUrl
.
contains
(
"readinglab"
)
||
returnUrl
.
contains
(
"read.etextbook.cn"
))){
// 阅览室日志分离
ClientItem
item
=
clientItemMap
.
get
(
"readingroomClientId"
);
authLog
.
setClientId
(
"readingroomClientId"
);
authLog
.
setAuthSource
(
item
.
getClientName
());
}
else
if
(
"cloudcourse"
.
equals
(
business_client
)
||
"cloudcourse-test"
.
equals
(
business_client
)){
ClientItem
item
=
clientItemMap
.
get
(
"cloudcourse"
);
authLog
.
setClientId
(
"cloudcourse"
);
authLog
.
setAuthSource
(
item
.
getClientName
());
}
else
if
(
"adaptive-learning"
.
equals
(
business_client
)){
ClientItem
item
=
clientItemMap
.
get
(
"adaptive-learning"
);
authLog
.
setClientId
(
"adaptive-learning"
);
authLog
.
setAuthSource
(
item
.
getClientName
());
}
OauthType
oauthType
=
OauthType
.
getValue
(
loginType
);
if
(
oauthType
!=
null
){
modelAndView
.
addObject
(
"loginType"
,
loginType
);
}
else
{
modelAndView
.
addObject
(
"loginType"
,
""
);
}
}
else
{
modelAndView
.
addObject
(
"loginType"
,
""
);
}
}
authLogService
.
save
(
authLog
);
String
dianjiaoguanLoinUrl
=
generateLoginUrl
(
returnUrl
,
OauthType
.
dianjiaoguan
.
getCode
(),
authLog
.
getId
());
modelAndView
.
addObject
(
"dianjiaoguanLoinUrl"
,
dianjiaoguanLoinUrl
);
String
edenoperationLoginUrl
=
generateLoginUrl
(
returnUrl
,
OauthType
.
edenoperation
.
getCode
(),
authLog
.
getId
());
modelAndView
.
addObject
(
"edenoperationLoginUrl"
,
edenoperationLoginUrl
);
OauthType
[]
oauthTypes
=
OauthType
.
values
();
for
(
OauthType
oauthType
:
oauthTypes
)
{
if
(
"idp"
.
equals
(
oauthType
.
getType
())){
String
idpAuthTypeUrl
=
generateSpLoginUrl
(
returnUrl
,
oauthType
.
getCode
(),
authLog
.
getId
());
modelAndView
.
addObject
(
oauthType
.
getCode
()+
"LoginUrl"
,
idpAuthTypeUrl
);
}
}
modelAndView
.
addObject
(
"logId"
,
authLog
.
getId
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"未知错误"
);
}
return
modelAndView
;
}
@RequestMapping
(
"auth/tologin"
)
public
ModelAndView
toLogin
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
String
loginUrl
=
request
.
getParameter
(
"loginUrl"
);
String
logId
=
request
.
getParameter
(
"logId"
);
String
oauthType
=
request
.
getParameter
(
"oauthType"
);
String
browser
=
request
.
getParameter
(
"browser"
);
String
version
=
request
.
getParameter
(
"version"
);
String
device
=
request
.
getParameter
(
"device"
);
String
os
=
request
.
getParameter
(
"os"
);
try
{
AuthLog
authLog
=
authLogService
.
getById
(
logId
);
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
authLog
.
setFowardUrl
(
oauthConfigItem
.
getOauthUrl
());
authLog
.
setOauthType
(
oauthType
);
authLog
.
setBrowser
(
browser
);
authLog
.
setVersion
(
version
);
authLog
.
setDevice
(
device
);
authLog
.
setOs
(
os
);
Date
now
=
new
Date
();
String
yearMonthDay
=
DateUtils
.
dateToString
(
now
,
"yyyy-MM-dd"
);
String
yearMonth
=
DateUtils
.
dateToString
(
now
,
"yyyy-MM"
);
String
year
=
DateUtils
.
dateToString
(
now
,
"yyyy"
);
authLog
.
setYear
(
year
);
authLog
.
setYearMonth
(
yearMonth
);
authLog
.
setYearMonthDay
(
yearMonthDay
);
authLogService
.
save
(
authLog
);
response
.
sendRedirect
(
loginUrl
);
return
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"跳转失败,请联系管理人员"
);
}
return
modelAndView
;
}
@RequestMapping
(
"auth/logout"
)
public
ModelAndView
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
modelAndView
.
setViewName
(
"logout"
);
Map
<
String
,
ClientItem
>
clientItemMap
=
oauthClient
.
getClients
().
stream
().
collect
(
Collectors
.
toMap
(
ClientItem:
:
getClientId
,
Function
.
identity
()));
try
{
String
clientId
=
request
.
getParameter
(
"client_id"
);
ClientItem
clientItem
=
clientItemMap
.
get
(
clientId
);
if
(
clientItem
==
null
)
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
return
modelAndView
;
}
String
sign
=
request
.
getParameter
(
"sign"
);
String
signOrigin
=
clientItem
.
getClientId
()
+
"$$"
+
clientItem
.
getClientSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"请求不合法"
);
return
modelAndView
;
}
String
service
=
request
.
getParameter
(
"service"
);
if
(
StringUtils
.
isEmpty
(
service
))
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登出成功回调地址为空"
);
return
modelAndView
;
}
String
oauthType
=
request
.
getParameter
(
"oauth_type"
);
if
(
StringUtils
.
isEmpty
(
oauthType
)){
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登出方式为空"
);
return
modelAndView
;
}
OauthType
type
=
OauthType
.
valueOf
(
oauthType
);
if
(
type
==
null
){
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登出方式错误"
);
return
modelAndView
;
}
AuthLog
authLog
=
new
AuthLog
();
authLog
.
setOauthType
(
oauthType
);
authLog
.
setReturnUrl
(
service
);
authLog
.
setClientId
(
clientId
);
authLog
.
setAuthSource
(
clientItem
.
getClientName
());
authLog
.
setLogType
(
LogType
.
logout
);
authLogService
.
save
(
authLog
);
if
(
StringUtils
.
isNotEmpty
(
service
))
{
if
(!
OauthType
.
dianjiaoguan
.
equals
(
type
)
&&
!
OauthType
.
edenoperation
.
equals
(
type
)){
if
(
OauthType
.
qpjy
.
equals
(
type
)){
response
.
sendRedirect
(
generateSpLogoutUrl
(
service
,
type
.
name
()));
}
}
else
{
response
.
sendRedirect
(
generateLogoutUrl
(
service
,
type
.
name
()));
}
}
return
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"未知错误"
);
}
return
modelAndView
;
}
@RequestMapping
(
value
=
"auth/loginsuccess"
,
method
=
RequestMethod
.
GET
)
public
ModelAndView
loginsuccess
(
HttpServletRequest
request
,
HttpServletResponse
response
,
ModelAndView
modelAndView
)
{
modelAndView
.
setViewName
(
"loginsuccess"
);
String
code
=
request
.
getParameter
(
"code"
);
String
oauthType
=
request
.
getParameter
(
"oauth_type"
);
String
logId
=
request
.
getParameter
(
"log_id"
);
String
returnUrl
=
request
.
getParameter
(
"return_url"
);
System
.
out
.
println
(
"code="
+
code
);
System
.
out
.
println
(
"oauthType="
+
oauthType
);
System
.
out
.
println
(
"returnUrl="
+
returnUrl
);
AuthLog
authLog
=
authLogService
.
getById
(
logId
);
if
(
authLog
==
null
){
authLog
=
new
AuthLog
();
authLog
.
setOauthType
(
oauthType
);
}
authLog
.
setLoginSuccessFlag
(
true
);
authLog
.
setReturnUrl
(
returnUrl
);
String
url
=
generateAccessTokenUrl
(
code
,
oauthType
);
try
{
String
exchange
=
MyRestTemplate
.
exchange
(
HttpMethod
.
GET
,
url
,
null
,
null
,
String
.
class
);
logger
.
info
(
"AccessTokenMethod......exchange........."
+
exchange
);
Map
<
String
,
String
>
keyValueMap
=
new
HashMap
<>();
if
(
StringUtils
.
isNotEmpty
(
exchange
))
{
String
[]
strings
=
exchange
.
split
(
"&"
);
for
(
int
i
=
0
;
i
<
strings
.
length
;
i
++)
{
String
temp
=
strings
[
i
];
String
[]
keyValue
=
temp
.
split
(
"="
);
if
(
ArrayUtils
.
isNotEmpty
(
keyValue
)
&&
keyValue
.
length
==
2
)
{
keyValueMap
.
put
(
keyValue
[
0
],
keyValue
[
1
]);
}
}
}
String
access_token
=
keyValueMap
.
get
(
"access_token"
);
// 获取用户信息
if
(
StringUtils
.
isNotEmpty
(
access_token
))
{
String
userInfoUrl
=
generateUserInfoUrl
(
access_token
,
oauthType
);
Map
<
String
,
Object
>
userInfoMap
=
MyRestTemplate
.
exchange
(
HttpMethod
.
GET
,
userInfoUrl
,
null
,
null
,
HashMap
.
class
);
// 转换用户信息
AuthUserInfo
userInfo
=
null
;
if
(
oauthType
.
equals
(
OauthType
.
dianjiaoguan
.
toString
()))
userInfo
=
ConvertMessageMapToBean
.
converDianjiaoguanData
(
userInfoMap
);
else
if
(
oauthType
.
equals
(
OauthType
.
edenoperation
.
toString
()))
userInfo
=
ConvertMessageMapToBean
.
converEdenoperationData
(
userInfoMap
);
// 封装下游数据
ClientDataInfo
clientDataInfo
=
new
ClientDataInfo
();
if
(
userInfo
!=
null
)
{
userInfo
.
setSource
(
oauthType
);
// 封装日志用户信息
LogUserInfo
logUserInfo
=
new
LogUserInfo
();
logUserInfo
.
setRealName
(
userInfo
.
getRealName
());
logUserInfo
.
setUserId
(
userInfo
.
getId
());
logUserInfo
.
setStudentCode
(
userInfo
.
getStudentCode
());
logUserInfo
.
setTeacherTrainingNo
(
userInfo
.
getTeacherTrainingNo
());
if
(
null
!=
userInfo
.
getUserType
()){
logUserInfo
.
setUserType
(
userInfo
.
getUserType
().
name
());
}
if
(
StringUtils
.
isNotEmpty
(
userInfo
.
getStudentSchoolId
())){
logUserInfo
.
setSchoolId
(
userInfo
.
getStudentSchoolId
());
}
if
(
StringUtils
.
isNotEmpty
(
userInfo
.
getTeacherSchoolId
())){
logUserInfo
.
setSchoolId
(
userInfo
.
getTeacherSchoolId
());
}
if
(
StringUtils
.
isNotEmpty
(
userInfo
.
getStudentSchoolName
())){
logUserInfo
.
setSchoolName
(
userInfo
.
getStudentSchoolName
());
}
if
(
StringUtils
.
isNotEmpty
(
userInfo
.
getTeacherSchoolName
())){
logUserInfo
.
setSchoolName
(
userInfo
.
getTeacherSchoolName
());
}
authLog
.
setGetUserInfoSuccessFlag
(
true
);
authLog
.
setUserInfoMap
(
userInfoMap
);
authLog
.
setLogUserInfo
(
logUserInfo
);
}
clientDataInfo
.
setAuthUserInfo
(
userInfo
);
clientDataInfo
.
setOauthType
(
oauthType
);
modelAndView
.
addObject
(
"clientDataInfo"
,
clientDataInfo
);
modelAndView
.
addObject
(
"successPostUrl"
,
returnUrl
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
authLog
.
setGetUserInfoSuccessFlag
(
false
);
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登录失败"
);
}
authLogService
.
save
(
authLog
);
return
modelAndView
;
}
@RequestMapping
(
value
=
"auth/idp/loginsuccess"
)
public
ModelAndView
idploginsuccess
(
HttpServletRequest
request
,
HttpServletResponse
response
,
ModelAndView
modelAndView
)
{
modelAndView
.
setViewName
(
"loginsuccess"
);
String
code
=
request
.
getParameter
(
"code"
);
String
oauthType
=
request
.
getParameter
(
"oauth_type"
);
String
logId
=
request
.
getParameter
(
"log_id"
);
String
returnUrl
=
request
.
getParameter
(
"return_url"
);
AuthLog
authLog
=
authLogService
.
getById
(
logId
);
if
(
authLog
==
null
){
authLog
=
new
AuthLog
();
authLog
.
setOauthType
(
oauthType
);
}
authLog
.
setLoginSuccessFlag
(
true
);
authLog
.
setReturnUrl
(
returnUrl
);
try
{
Map
<
String
,
Object
>
userInfoMap
=
null
;
// 转换用户信息
AuthUserInfo
userInfo
=
new
AuthUserInfo
();
String
userType
=
request
.
getParameter
(
"user_type"
);
userInfo
.
setRealName
(
request
.
getParameter
(
"real_name"
));
userInfo
.
setId
(
request
.
getParameter
(
"login_name"
));
if
(
"student"
.
equals
(
userType
)){
userInfo
.
setUserType
(
UserType
.
STUDENT
);
}
else
if
(
"tearcher"
.
equals
(
userType
)){
userInfo
.
setUserType
(
UserType
.
TEACHER
);
}
// 封装下游数据
ClientDataInfo
clientDataInfo
=
new
ClientDataInfo
();
if
(
userInfo
!=
null
)
{
userInfo
.
setSource
(
oauthType
);
// 封装日志用户信息
LogUserInfo
logUserInfo
=
new
LogUserInfo
();
logUserInfo
.
setRealName
(
userInfo
.
getRealName
());
logUserInfo
.
setUserId
(
userInfo
.
getId
());
logUserInfo
.
setStudentCode
(
userInfo
.
getStudentCode
());
logUserInfo
.
setTeacherTrainingNo
(
userInfo
.
getTeacherTrainingNo
());
if
(
null
!=
userInfo
.
getUserType
()){
logUserInfo
.
setUserType
(
userInfo
.
getUserType
().
name
());
}
if
(
StringUtils
.
isNotEmpty
(
userInfo
.
getStudentSchoolId
())){
logUserInfo
.
setSchoolId
(
userInfo
.
getStudentSchoolId
());
}
if
(
StringUtils
.
isNotEmpty
(
userInfo
.
getTeacherSchoolId
())){
logUserInfo
.
setSchoolId
(
userInfo
.
getTeacherSchoolId
());
}
if
(
StringUtils
.
isNotEmpty
(
userInfo
.
getStudentSchoolName
())){
logUserInfo
.
setSchoolName
(
userInfo
.
getStudentSchoolName
());
}
if
(
StringUtils
.
isNotEmpty
(
userInfo
.
getTeacherSchoolName
())){
logUserInfo
.
setSchoolName
(
userInfo
.
getTeacherSchoolName
());
}
authLog
.
setGetUserInfoSuccessFlag
(
true
);
authLog
.
setUserInfoMap
(
userInfoMap
);
authLog
.
setLogUserInfo
(
logUserInfo
);
}
clientDataInfo
.
setAuthUserInfo
(
userInfo
);
clientDataInfo
.
setOauthType
(
oauthType
);
modelAndView
.
addObject
(
"clientDataInfo"
,
clientDataInfo
);
modelAndView
.
addObject
(
"successPostUrl"
,
returnUrl
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
authLog
.
setGetUserInfoSuccessFlag
(
false
);
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登录失败"
);
}
authLogService
.
save
(
authLog
);
return
modelAndView
;
}
@RequestMapping
(
value
=
"auth/logoutsuccess"
,
method
=
RequestMethod
.
GET
)
public
ModelAndView
loginoutsuccess
(
HttpServletRequest
request
,
HttpServletResponse
response
,
ModelAndView
modelAndView
)
throws
IOException
{
String
returnUrl
=
request
.
getParameter
(
"return_url"
);
if
(
StringUtils
.
isNotEmpty
(
returnUrl
)){
response
.
sendRedirect
(
returnUrl
);
}
else
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登出失败"
);
return
modelAndView
;
}
return
null
;
}
private
String
generateLoginUrl
(
String
returnUrl
,
String
oauthType
,
String
logId
)
{
//oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
loginUrlBuilder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
"/"
);
}
loginUrlBuilder
.
append
(
"oauth2.0/authorize?client_id="
).
append
(
oauthConfigItem
.
getClientId
());
String
loginSuccessUrl
=
oauthConfigItem
.
getLoginSuccessUrl
();
loginSuccessUrl
=
loginSuccessUrl
+
"?oauth_type="
+
oauthType
+
"&log_id="
+
logId
;
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
loginSuccessUrl
=
appendUrl
(
loginSuccessUrl
,
param
);
}
loginUrlBuilder
.
append
(
"&redirect_uri="
).
append
(
URLEncoder
.
encode
(
loginSuccessUrl
));
loginUrlBuilder
.
append
(
"&state=state&response_type=code"
);
return
loginUrlBuilder
.
toString
();
}
private
String
generateSpLoginUrl
(
String
returnUrl
,
String
oauthType
,
String
logId
)
{
//oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
loginUrlBuilder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
"/"
);
}
loginUrlBuilder
.
append
(
"login?client_id="
).
append
(
oauthConfigItem
.
getClientId
());
String
loginSuccessUrl
=
oauthConfigItem
.
getLoginSuccessUrl
();
loginSuccessUrl
=
loginSuccessUrl
+
"?log_id="
+
logId
+
"&oauth_type="
+
oauthType
;
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
loginSuccessUrl
=
appendUrl
(
loginSuccessUrl
,
param
);
}
loginUrlBuilder
.
append
(
"&redirect_uri="
).
append
(
URLEncoder
.
encode
(
loginSuccessUrl
));
String
sign
=
EncodeUtil
.
md5
(
oauthConfigItem
.
getClientId
()+
"$$"
+
oauthConfigItem
.
getClientSecret
());
loginUrlBuilder
.
append
(
"&sign="
+
sign
);
return
loginUrlBuilder
.
toString
();
}
private
String
generateLogoutUrl
(
String
returnUrl
,
String
oauthType
)
{
//oauthConfig + "/authorize?client_id=testClentId&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess.do&state=state"
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
loginUrlBuilder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
"/"
);
}
String
service
=
oauthConfigItem
.
getLogoutSuccessUrl
();
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
service
=
appendUrl
(
service
,
param
);
}
loginUrlBuilder
.
append
(
"logout?service="
).
append
(
URLEncoder
.
encode
(
service
));
return
loginUrlBuilder
.
toString
();
}
private
String
generateSpLogoutUrl
(
String
returnUrl
,
String
oauthType
)
{
if
(
oauthType
.
equals
(
"qpjy"
)){
returnUrl
=
"https://idp.qpedu.cn/logout/logout.html?redirect_url="
+
returnUrl
;
returnUrl
=
"https://sp.etextbook.cn/Shibboleth.sso/Logout?return="
+
URLEncoder
.
encode
(
returnUrl
);
return
returnUrl
;
}
StringBuilder
loginUrlBuilder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
loginUrlBuilder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
loginUrlBuilder
.
append
(
"/"
);
}
String
service
=
oauthConfigItem
.
getLogoutSuccessUrl
();
if
(
StringUtils
.
isNotEmpty
(
returnUrl
))
{
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"return_url"
,
URLEncoder
.
encode
(
returnUrl
));
service
=
appendUrl
(
service
,
param
);
}
String
clientId
=
oauthConfigItem
.
getClientId
();
String
signOrigin
=
oauthConfigItem
.
getClientId
()
+
"$$"
+
oauthConfigItem
.
getClientSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
loginUrlBuilder
.
append
(
"logout?service="
).
append
(
URLEncoder
.
encode
(
service
));
loginUrlBuilder
.
append
(
"&client_id="
+
clientId
);
loginUrlBuilder
.
append
(
"&sign="
+
md5Hex
);
return
loginUrlBuilder
.
toString
();
}
private
String
generateUserInfoUrl
(
String
accessToken
,
String
oauthType
)
{
//String url = "http://castest.edu.sh.cn/CAS/oauth2.0/accessToken?client_id=testClentId&client_secret=testClientSecret&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess2.do&code=" + code;
StringBuilder
builder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
builder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
builder
.
append
(
"/"
);
}
builder
.
append
(
"oauth2.0/profile?access_token="
).
append
(
accessToken
);
return
builder
.
toString
();
}
private
String
generateAccessTokenUrl
(
String
code
,
String
oauthType
)
{
//String url = "http://castest.edu.sh.cn/CAS/oauth2.0/accessToken?client_id=testClentId&client_secret=testClientSecret&redirect_uri=http%3a%2f%2f192.168.17.129%3a7774%2fauth%2floginsuccess2.do&code=" + code;
StringBuilder
builder
=
new
StringBuilder
();
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
oauthType
);
builder
.
append
(
oauthConfigItem
.
getOauthUrl
());
if
(!
oauthConfigItem
.
getOauthUrl
().
endsWith
(
"/"
))
{
builder
.
append
(
"/"
);
}
builder
.
append
(
"oauth2.0/accessToken?client_id="
).
append
(
oauthConfigItem
.
getClientId
());
builder
.
append
(
"&client_secret="
).
append
(
oauthConfigItem
.
getClientSecret
());
builder
.
append
(
"&code="
).
append
(
code
);
builder
.
append
(
"&redirect_uri="
).
append
(
oauthConfigItem
.
getLoginSuccessUrl
());
builder
.
append
(
"&grant_type=authorization_code"
);
return
builder
.
toString
();
}
/**
* 在指定url后追加参数
*
* @param url
* @param data 参数集合 key = value
* @return
*/
private
static
String
appendUrl
(
String
url
,
Map
<
String
,
String
>
data
)
{
String
newUrl
=
url
;
StringBuffer
param
=
new
StringBuffer
();
for
(
String
key
:
data
.
keySet
())
{
param
.
append
(
key
+
"="
+
data
.
get
(
key
)
+
"&"
);
}
String
paramStr
=
param
.
toString
();
paramStr
=
paramStr
.
substring
(
0
,
paramStr
.
length
()
-
1
);
if
(
newUrl
.
indexOf
(
"?"
)
>=
0
)
{
newUrl
+=
"&"
+
paramStr
;
}
else
{
newUrl
+=
"?"
+
paramStr
;
}
return
newUrl
;
}
@RequestMapping
(
"auth/shauth"
)
public
ModelAndView
chineseallLogin
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
modelAndView
.
setViewName
(
"toward"
);
Map
<
String
,
ClientItem
>
clientItemMap
=
oauthClient
.
getClients
().
stream
().
collect
(
Collectors
.
toMap
(
ClientItem:
:
getClientId
,
Function
.
identity
()));
try
{
String
clientId
=
request
.
getParameter
(
"client_id"
);
String
returnUrl
=
request
.
getParameter
(
"redirect_uri"
);
ClientItem
clientItem
=
clientItemMap
.
get
(
clientId
);
AuthLog
authLog
=
new
AuthLog
();
authLog
.
setLogType
(
LogType
.
login
);
if
(
null
==
clientItem
)
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
return
modelAndView
;
}
authLog
.
setClientId
(
clientId
);
authLog
.
setAuthSource
(
clientItem
.
getClientName
());
String
sign
=
request
.
getParameter
(
"sign"
);
String
signOrigin
=
clientItem
.
getClientId
()
+
"$$"
+
clientItem
.
getClientSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"请求不合法"
);
return
modelAndView
;
}
if
(
StringUtils
.
isEmpty
(
returnUrl
))
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登录成功回调地址为空"
);
return
modelAndView
;
}
authLog
.
setOauthType
(
OauthType
.
dianjiaoguan
.
getCode
());
OauthConfigItem
oauthConfigItem
=
oauthConfig
.
getItems
().
get
(
OauthType
.
dianjiaoguan
.
getCode
());
authLog
.
setFowardUrl
(
oauthConfigItem
.
getOauthUrl
());
authLogService
.
save
(
authLog
);
String
url
=
generateLoginUrl
(
returnUrl
,
OauthType
.
dianjiaoguan
.
getCode
(),
authLog
.
getId
());
modelAndView
.
addObject
(
"loginUrl"
,
url
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"未知错误"
);
}
return
modelAndView
;
}
@RequestMapping
(
"auth/shlogout"
)
public
ModelAndView
shLogout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
ModelAndView
modelAndView
=
new
ModelAndView
();
modelAndView
.
setViewName
(
"logout"
);
Map
<
String
,
ClientItem
>
clientItemMap
=
oauthClient
.
getClients
().
stream
().
collect
(
Collectors
.
toMap
(
ClientItem:
:
getClientId
,
Function
.
identity
()));
try
{
String
clientId
=
request
.
getParameter
(
"client_id"
);
ClientItem
clientItem
=
clientItemMap
.
get
(
clientId
);
if
(
clientItem
==
null
)
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"client_id为空或者不正确"
);
return
modelAndView
;
}
String
sign
=
request
.
getParameter
(
"sign"
);
String
signOrigin
=
clientItem
.
getClientId
()
+
"$$"
+
clientItem
.
getClientSecret
();
String
md5Hex
=
EncodeUtil
.
md5
(
signOrigin
);
if
(!
Objects
.
equals
(
sign
,
md5Hex
))
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"请求不合法"
);
return
modelAndView
;
}
String
service
=
request
.
getParameter
(
"service"
);
if
(
StringUtils
.
isEmpty
(
service
))
{
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"登出成功回调地址为空"
);
return
modelAndView
;
}
AuthLog
authLog
=
new
AuthLog
();
authLog
.
setOauthType
(
OauthType
.
dianjiaoguan
.
getCode
());
authLog
.
setReturnUrl
(
service
);
authLog
.
setClientId
(
clientId
);
authLog
.
setAuthSource
(
clientItem
.
getClientName
());
authLog
.
setLogType
(
LogType
.
logout
);
authLogService
.
save
(
authLog
);
if
(
StringUtils
.
isNotEmpty
(
service
))
{
response
.
sendRedirect
(
generateLogoutUrl
(
service
,
OauthType
.
dianjiaoguan
.
getCode
()));
}
return
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
modelAndView
.
setViewName
(
"error"
);
modelAndView
.
addObject
(
"message"
,
"未知错误"
);
}
return
modelAndView
;
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/interceptor/AccessInterceptor.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
interceptor
;
import
com.chineseall.eden.authcenter.log.util.RequestResponseHolder
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
@Component
public
class
AccessInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
,
Object
o
)
throws
Exception
{
RequestResponseHolder
.
set
(
httpServletRequest
,
httpServletResponse
);
return
true
;
}
@Override
public
void
postHandle
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
,
Object
o
,
ModelAndView
modelAndView
)
throws
Exception
{
RequestResponseHolder
.
remove
();
}
@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/ApiInterceptor.java
0 → 100644
View file @
74b4b318
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 @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
agent
.
interceptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistration
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
java.util.List
;
@Configuration
public
class
ApiInterceptorConfig
extends
WebMvcConfigurerAdapter
{
@Autowired
ApiInterceptor
apiInterceptor
;
@Autowired
AccessInterceptor
accessInterceptor
;
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
//注册TestInterceptor拦截器
InterceptorRegistration
accessRegistration
=
registry
.
addInterceptor
(
accessInterceptor
);
accessRegistration
.
addPathPatterns
(
"/**"
);
InterceptorRegistration
registration
=
registry
.
addInterceptor
(
apiInterceptor
);
registration
.
addPathPatterns
(
"/config/**"
);
//
}
@Override
public
void
extendMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
();
converters
.
add
(
0
,
converter
);
}
}
eden-authcenter-agent/src/main/java/com/chineseall/eden/authcenter/agent/utils/JwtUtils.java
0 → 100644
View file @
74b4b318
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/application.yml
View file @
74b4b318
server
:
server
:
port
:
9600
port
:
9600
context-path
:
/authcenter
context-path
:
/authcenter
logging
:
config
:
classpath:log4j.xml
spring
:
spring
:
application
:
application
:
name
:
eden-authcenter-agent
name
:
eden-authcenter-agent
...
@@ -24,158 +26,7 @@ spring:
...
@@ -24,158 +26,7 @@ spring:
multipart
:
multipart
:
max-file-size
:
200MB
max-file-size
:
200MB
max-request-size
:
300MB
max-request-size
:
300MB
oauth
:
admin-user
:
items
:
account
:
ac_admin
dianjiaoguan
:
#电教馆
password
:
AC_PWD_2022
# oauthUrl: https://castest.edu.sh.cn/CAS
# clientId: testClentId
# clientSecret: testClientSecret
oauthUrl
:
https://cas2.edu.sh.cn/CAS
clientId
:
clientid
clientSecret
:
clientSecret
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
edenoperation
:
#运营中心
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://operator-api.sh-genius.cn/cas/
clientId
:
testClentId
clientSecret
:
testClientSecret
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
qpjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
cmjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
fxjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
sjjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jsjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jdjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
bsjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
mhjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
pdjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
ypjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
hkjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
ptjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jajy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
cnjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
xhjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
hpjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
oauthclient
:
clients
:
-
clientName
:
数字教材
clientId
:
testClentId
clientSecret
:
testClientSecret
# - clientName: 接入样例
# clientId: testClentId2
# clientSecret: testClientSecret2
-
clientName
:
资源评价系统
clientId
:
xhzyClientId
clientSecret
:
xhzyClientSecret
-
clientName
:
阅览室
clientId
:
readingroomClientId
clientSecret
:
readingroomClientSecret
-
clientName
:
空中课堂
clientId
:
cloudcourse
clientSecret
:
cloudcourseSecret
-
clientName
:
自适应学习
clientId
:
adaptive-learning
clientSecret
:
adaptive-learningSecret
-
clientName
:
教学平台
clientId
:
ai-study-client
clientSecret
:
4fa6jt85XeqoSC67
\ No newline at end of file
eden-authcenter-agent/src/main/resources/bootstrap.yml
View file @
74b4b318
server
:
server
:
port
:
9600
port
:
9600
context-path
:
/authcenter
context-path
:
/authcenter
logging
:
config
:
classpath:log4j.xml
spring
:
spring
:
application
:
application
:
name
:
eden-authcenter-agent
name
:
eden-authcenter-agent
...
@@ -24,158 +26,9 @@ spring:
...
@@ -24,158 +26,9 @@ spring:
multipart
:
multipart
:
max-file-size
:
200MB
max-file-size
:
200MB
max-request-size
:
300MB
max-request-size
:
300MB
oauth
:
admin-user
:
items
:
account
:
ac_admin
dianjiaoguan
:
#电教馆
password
:
AC_PWD_2022
# oauthUrl: https://castest.edu.sh.cn/CAS
# clientId: testClentId
# clientSecret: testClientSecret
oauthUrl
:
https://cas2.edu.sh.cn/CAS
clientId
:
clientid
clientSecret
:
clientSecret
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
edenoperation
:
#运营中心
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://operator-api.sh-genius.cn/cas/
clientId
:
testClentId
clientSecret
:
testClientSecret
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
qpjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
cmjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
fxjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
sjjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jsjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jdjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
bsjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
mhjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
pdjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
ypjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
hkjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
ptjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
jajy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
cnjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
xhjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
hpjy
:
#idp
#oauthUrl: https://operator-api-test.etextbook.cn/cas
oauthUrl
:
https://sp.etextbook.cn/authcenter/auth
clientId
:
dsClentId
clientSecret
:
VjyqUkkM5Znu
loginSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/idp/loginsuccess
logoutSuccessUrl
:
https://ds.etextbook.cn/authcenter/auth/logoutsuccess
oauthclient
:
clients
:
-
clientName
:
数字教材
clientId
:
testClentId
clientSecret
:
testClientSecret
# - clientName: 接入样例
# clientId: testClentId2
# clientSecret: testClientSecret2
-
clientName
:
资源评价系统
clientId
:
xhzyClientId
clientSecret
:
xhzyClientSecret
-
clientName
:
阅览室
clientId
:
readingroomClientId
clientSecret
:
readingroomClientSecret
-
clientName
:
空中课堂
clientId
:
cloudcourse
clientSecret
:
cloudcourseSecret
-
clientName
:
自适应学习
clientId
:
adaptive-learning
clientSecret
:
adaptive-learningSecret
-
clientName
:
教学平台
clientId
:
ai-study-client
clientSecret
:
4fa6jt85XeqoSC67
eden-authcenter-agent/src/main/resources/log4j.xml
0 → 100644
View file @
74b4b318
<?xml version="1.0" encoding="UTF-8"?>
<!--Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,你会看到log4j2内部各种详细输出-->
<!--monitorInterval:Log4j能够自动检测修改配置 文件和重新配置本身,设置间隔秒数-->
<configuration
monitorInterval=
"5"
>
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
<!--变量配置-->
<Properties>
<!-- 格式化输出:%date表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %msg:日志消息,%n是换行符-->
<!-- %logger{36} 表示 Logger 名字最长36个字符 -->
<property
name=
"LOG_PATTERN"
value=
"%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
/>
<!-- 定义日志存储的路径 -->
<property
name=
"FILE_PATH"
value=
"/data/ds/logs/"
/>
<property
name=
"FILE_NAME"
value=
"info"
/>
<property
name=
"BUSINESS_FILE_NAME"
value=
"business_info"
/>
</Properties>
<appenders>
<console
name=
"Console"
target=
"SYSTEM_OUT"
>
<!--输出日志的格式-->
<PatternLayout
pattern=
"${LOG_PATTERN}"
/>
<!--控制台只输出level及其以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter
level=
"info"
onMatch=
"ACCEPT"
onMismatch=
"DENY"
/>
</console>
<!--文件会打印出所有信息,这个log每次运行程序会自动清空,由append属性决定,适合临时测试用-->
<File
name=
"Filelog"
fileName=
"${FILE_PATH}/test.log"
append=
"false"
>
<PatternLayout
pattern=
"${LOG_PATTERN}"
/>
</File>
<!-- 这个会打印出所有的info及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile
name=
"RollingFileInfo"
fileName=
"${FILE_PATH}/info.log"
filePattern=
"${FILE_PATH}/${FILE_NAME}-INFO-%d{yyyy-MM-dd}_%i.log.gz"
>
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter
level=
"info"
onMatch=
"ACCEPT"
onMismatch=
"DENY"
/>
<PatternLayout
pattern=
"${LOG_PATTERN}"
/>
<Policies>
<!--interval属性用来指定多久滚动一次,1 天-->
<TimeBasedTriggeringPolicy
interval=
"1"
/>
<SizeBasedTriggeringPolicy
size=
"10MB"
/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy
max=
"300"
/>
</RollingFile>
<!-- 这个会打印出所有的info及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile
name=
"RollingBusinessFileInfo"
fileName=
"${FILE_PATH}/business_info.log"
filePattern=
"${FILE_PATH}/${BUSINESS_FILE_NAME}-INFO-%d{yyyy-MM-dd}_%i.log.gz"
>
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter
level=
"info"
onMatch=
"ACCEPT"
onMismatch=
"DENY"
/>
<PatternLayout
pattern=
"%msg%n"
/>
<Policies>
<!--interval属性用来指定多久滚动一次,1 天-->
<TimeBasedTriggeringPolicy
interval=
"1"
/>
<SizeBasedTriggeringPolicy
size=
"10MB"
/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy
max=
"300"
/>
</RollingFile>
<!-- 这个会打印出所有的warn及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile
name=
"RollingFileWarn"
fileName=
"${FILE_PATH}/warn.log"
filePattern=
"${FILE_PATH}/${FILE_NAME}-WARN-%d{yyyy-MM-dd}_%i.log.gz"
>
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter
level=
"warn"
onMatch=
"ACCEPT"
onMismatch=
"DENY"
/>
<PatternLayout
pattern=
"${LOG_PATTERN}"
/>
<Policies>
<!--interval属性用来指定多久滚动一次,1天-->
<TimeBasedTriggeringPolicy
interval=
"1"
/>
<SizeBasedTriggeringPolicy
size=
"10MB"
/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy
max=
"300"
/>
</RollingFile>
<!-- 这个会打印出所有的error及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile
name=
"RollingFileError"
fileName=
"${FILE_PATH}/error.log"
filePattern=
"${FILE_PATH}/${FILE_NAME}-ERROR-%d{yyyy-MM-dd}_%i.log.gz"
>
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter
level=
"error"
onMatch=
"ACCEPT"
onMismatch=
"DENY"
/>
<PatternLayout
pattern=
"${LOG_PATTERN}"
/>
<Policies>
<!--interval属性用来指定多久滚动一次,1天-->
<TimeBasedTriggeringPolicy
interval=
"1"
/>
<SizeBasedTriggeringPolicy
size=
"10MB"
/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy
max=
"300"
/>
</RollingFile>
</appenders>
<!--Logger节点用来单独指定日志的形式,比如要为指定包下的class指定不同的日志级别等。-->
<!--然后定义loggers,只有定义了logger并引入的appender,appender才会生效-->
<loggers>
<!--过滤掉spring和mybatis的一些无用的DEBUG信息-->
<logger
name=
"org.mongodb"
level=
"info"
additivity=
"false"
>
<AppenderRef
ref=
"Console"
/>
</logger>
<!-- 启动日志打到控制台 -->
<Logger
name=
"org.springframework"
level=
"info"
additivity=
"false"
>
<AppenderRef
ref=
"Console"
/>
</Logger>
<!--监控系统信息-->
<!--若是additivity设为false,则 子Logger 只会在自己的appender里输出,而不会在 父Logger 的appender里输出。-->
<Logger
name=
"com.chineseall.eden.authcenter.log.util.BusinessLogUtils"
level=
"info"
additivity=
"true"
>
<AppenderRef
ref=
"RollingBusinessFileInfo"
/>
</Logger>
<root
level=
"info"
>
<appender-ref
ref=
"Console"
/>
<appender-ref
ref=
"Filelog"
/>
<appender-ref
ref=
"RollingFileInfo"
/>
<appender-ref
ref=
"RollingFileWarn"
/>
<appender-ref
ref=
"RollingFileError"
/>
</root>
</loggers>
</configuration>
eden-authcenter-agent/src/main/resources/static/css/statistics.css
View file @
74b4b318
...
@@ -19,7 +19,7 @@ body {
...
@@ -19,7 +19,7 @@ body {
}
}
.statistics-content-item
{
.statistics-content-item
{
background-color
:
white
;
background-color
:
white
;
margin
:
10px
5px
;
margin
:
10px
5px
0
;
overflow
:
hidden
;
overflow
:
hidden
;
}
}
.item-height
{
.item-height
{
...
@@ -31,6 +31,11 @@ body {
...
@@ -31,6 +31,11 @@ body {
.statistics-content-item-title
{
.statistics-content-item-title
{
padding
:
12px
0
0
20px
;
padding
:
12px
0
0
20px
;
font-size
:
14px
;
font-size
:
14px
;
font-weight
:
bold
;
}
.statistics-content-item-title-sub
{
padding
:
5px
0
0
20px
;
font-size
:
12px
;
color
:
#777c82
;
color
:
#777c82
;
}
}
.statistics-content-item-title-remark
{
.statistics-content-item-title-remark
{
...
...
eden-authcenter-agent/src/main/resources/templates/config/authclient_list.html
0 → 100644
View file @
74b4b318
<!DOCTYPE html>
<!--[if lt IE 7]>
<html xmlns:th="http://www.thymeleaf.org">
<html xmlns:th="http://www.w3.org/1999/xhtml" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html xmlns:th="http://www.w3.org/1999/xhtml" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html xmlns:th="http://www.w3.org/1999/xhtml" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html
class=
"no-js"
xmlns:th=
"http://www.w3.org/1999/xhtml"
>
<!--<![endif]-->
<head>
<meta
charset=
"utf-8"
/>
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<meta
content=
""
name=
"description"
/>
<meta
content=
"width=device-width, initial-scale=1"
name=
"viewport"
/>
<title>
上海市中小学数字教材
</title>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/main_0327.css}"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/statistics.css}"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/bootstrap.min.css}"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/normalize.css}"
/>
<link
rel=
"stylesheet"
type=
"text/css"
th:href=
"@{/static/css/iview.css}"
/>
<link
rel=
"shortcut icon"
th:href=
"@{/static/img/favicon.ico}"
>
<script
type=
"text/javascript"
th:src=
"@{/static/js/jquery-1.10.2.min.js}"
></script>
<script
th:src=
"@{/static/js/echarts.min.js}"
></script>
<script
th:src=
"@{/static/js/vue.js}"
></script>
<script
type=
"text/javascript"
th:src=
"@{/static/js/iview.min.js}"
></script>
</head>
<body
style=
"background-color: rgb(244, 245, 245);"
>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a
href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div
id=
"app"
class=
"static"
>
<div
class=
"statistics-header"
>
<div
class=
"flex"
style=
"display: flex; align-items: center;"
>
<img
th:src=
"@{/static/img/Rlogo.png}"
style=
"margin:5px 0; margin-left: 30px; width: 250px;"
alt=
""
>
<Divider
type=
"vertical"
style=
"height: 26px;"
></Divider>
<p
style=
"font-size: 14px; font-weight: 700;"
>
发现服务 · 速享之旅
</p>
</div>
<div
class=
"flex"
>
<img
th:src=
"@{/static/img/top-title.png}"
style=
"height: 22px;"
alt=
""
>
</div>
<div
class=
"flex"
style=
"width: 33%;"
>
</div>
</div>
<div
style=
"margin: 6px 6px; width: 100%; background-color: #fff;"
>
<div
style=
"margin: 6px 6px; padding-top: 10px; display: flex; justify-content: space-between;"
>
<span>
授权应用列表:
</span>
<i-button
type=
"primary"
size=
"small"
style=
"margin-right: 20px;"
@
click=
"clientModal = true;"
>
新增
</i-button>
</div>
<i-table
:columns=
"columnsClient"
:data=
"dataClient"
style=
"width: 100%; margin: 6px 6px;"
></i-table>
</div>
<Modal
v-model=
"clientModal"
title=
"授权应用配置"
@
on-ok=
"handleSubmit('formValidate')"
@
on-cancel=
"clientModal = false;"
>
<i-form
ref=
"formValidate"
:model=
"formSetting"
label-position=
"right"
:label-width=
"100"
>
<Form-Item
label=
"clientId"
>
<i-input
v-model=
"formSetting.key"
></i-input>
</Form-Item>
<Form-Item
label=
"clientName"
>
<i-input
v-model=
"formSetting.name"
></i-input>
</Form-Item>
<Form-Item
label=
"clientSecret"
>
<i-input
v-model=
"formSetting.secret"
></i-input>
</Form-Item>
<Form-Item
label=
"白名单"
>
<i-input
v-model=
"formSetting.whiteRule"
></i-input>
</Form-Item>
</i-form>
</Modal>
</div>
<script
th:inline=
"javascript"
>
var
dataList
=
[[
$
{
dataList
}]];
</script>
<!-- iview使用了includes方法,兼容ie11 -->
<script>
if
(
!
Array
.
prototype
.
includes
)
{
Object
.
defineProperty
(
Array
.
prototype
,
'includes'
,
{
value
:
function
(
valueToFind
,
fromIndex
)
{
if
(
this
==
null
)
{
throw
new
TypeError
(
'"this" is null or not defined'
);
}
// 1. Let O be ? ToObject(this value).
var
o
=
Object
(
this
);
// 2. Let len be ? ToLength(? Get(O, "length")).
var
len
=
o
.
length
>>>
0
;
// 3. If len is 0, return false.
if
(
len
===
0
)
{
return
false
;
}
// 4. Let n be ? ToInteger(fromIndex).
// (If fromIndex is undefined, this step produces the value 0.)
var
n
=
fromIndex
|
0
;
// 5. If n ≥ 0, then
// a. Let k be n.
// 6. Else n
<
0
,
// a. Let k be len + n.
// b. If k
<
0
,
let
k
be
0
.
var
k
=
Math
.
max
(
n
>=
0
?
n
:
len
-
Math
.
abs
(
n
),
0
);
function
sameValueZero
(
x
,
y
)
{
return
x
===
y
||
(
typeof
x
===
'number'
&&
typeof
y
===
'number'
&&
isNaN
(
x
)
&&
isNaN
(
y
));
}
// 7. Repeat, while k
<
len
while
(
k
<
len
)
{
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
// b. If SameValueZero(valueToFind, elementK) is true, return true.
if
(
sameValueZero
(
o
[
k
],
valueToFind
))
{
return
true
;
}
// c. Increase k by 1.
k
++
;
}
// 8. Return false
return
false
;
}
});
}
</script>
<script
type=
"text/javascript"
>
var
baseUrl
=
"/authcenter/"
;
var
colorList
=
[
'#6c5df1'
,
'#a78bf4'
,
'#fdbf3c'
,
'#ec6367'
,
'#2fcaa8'
,
'#79c161'
]
new
Vue
({
el
:
'#app'
,
data
()
{
var
that
=
this
;
return
{
clientModal
:
false
,
settingIndex
:
null
,
columnsClient
:
[
{
title
:
'应用ID'
,
key
:
'id'
,
},
{
title
:
'应用名称'
,
key
:
'name'
,
},
{
title
:
'备注'
,
key
:
'province'
,
},
{
title
:
'创建时间'
,
key
:
'createdTime'
,
},
{
title
:
'状态'
,
key
:
'status'
,
},
{
title
:
'操作'
,
key
:
'action'
,
render
:
function
(
h
,
params
)
{
return
h
(
'div'
,
[
h
(
'Button'
,
{
props
:
{
type
:
'text'
,
size
:
'small'
},
on
:
{
click
:
function
()
{
that
.
updateClientStatus
(
params
.
index
,
2
)
}
}
},
'废弃'
),
h
(
'Button'
,
{
props
:
{
type
:
'text'
,
size
:
'small'
},
on
:
{
click
:
function
()
{
that
.
updateClientStatus
(
params
.
index
,
1
)
}
}
},
'启用'
),
h
(
'Button'
,
{
props
:
{
type
:
'text'
,
size
:
'small'
},
on
:
{
click
:
function
()
{
that
.
formSetting
=
params
.
row
;
that
.
clientModal
=
true
;
}
}
},
'配置'
)
]);
}
}
],
dataClient
:
dataList
,
formSetting
:
{
key
:
''
,
name
:
''
,
secret
:
''
,
whiteRule
:
''
,
status
:
1
,
},
}
},
mounted
:
function
()
{
},
methods
:
{
handleSubmit
:
function
(
name
)
{
var
_this
=
this
;
_this
.
$refs
[
name
].
validate
(
function
(
valid
)
{
if
(
valid
)
{
var
params
=
{
key
:
_this
.
formSetting
.
key
,
name
:
_this
.
formSetting
.
name
,
secret
:
_this
.
formSetting
.
secret
,
whiteRule
:
_this
.
formSetting
.
whiteRule
,
status
:
1
}
console
.
log
(
'params'
,
params
,
_this
)
$
.
ajax
({
url
:
baseUrl
+
'config/authclient/save'
,
type
:
'POST'
,
data
:
params
,
contentType
:
'application/json; charset=utf-8'
,
success
:
function
(
result
)
{
_this
.
$Message
.
success
(
'保存成功!'
);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
});
}
else
{
_this
.
$Message
.
error
(
'Fail!'
);
}
})
},
updateClientStatus
:
function
(
index
,
status
)
{
var
params
=
{
status
}
var
_this
=
this
;
$
.
ajax
({
url
:
baseUrl
+
'config/authclient/changestatus'
,
type
:
'POST'
,
data
:
params
,
success
:
function
(
result
)
{
_this
.
$Message
.
success
(
'更新成功!'
);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
});
},
},
})
</script>
</body>
</html>
\ No newline at end of file
eden-authcenter-agent/src/main/resources/templates/config/authsource_list.html
0 → 100644
View file @
74b4b318
eden-authcenter-agent/src/main/resources/templates/config/index.html
0 → 100644
View file @
74b4b318
<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<html
class=
"no-js"
xmlns:th=
"http://www.w3.org/1999/xhtml"
>
<!--<![endif]-->
<head>
<meta
charset=
"utf-8"
/>
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<meta
content=
""
name=
"description"
/>
<meta
content=
"width=device-width, initial-scale=1"
name=
"viewport"
/>
<title>
统一认证登录配置
</title>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/main_0216.css}"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/bootstrap.min.css}"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/normalize.css}"
/>
<script
type=
"text/javascript"
th:src=
"@{/static/js/jquery-1.10.2.min.js}"
></script>
<!--<script src="../js/vendor/modernizr-2.6.2.min.js"></script>-->
</head>
<body
style=
"background-color: #4e97f7 !important;"
>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a
href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div
class=
"bg"
>
</div>
<script
th:inline=
"javascript"
>
/*<![CDATA[*/
var
ctxPath
=
/*[[@{/}]]*/
''
;
/*]]>*/
</script>
<script
type=
"text/javascript"
>
window
.
location
.
href
=
ctxPath
+
'config/authclient/list'
</script>
</body>
</html>
\ No newline at end of file
eden-authcenter-agent/src/main/resources/templates/ds.html
View file @
74b4b318
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
<script
type=
"text/javascript"
th:src=
"@{/static/js/browser.js}"
></script>
<script
type=
"text/javascript"
th:src=
"@{/static/js/browser.js}"
></script>
<script
th:inline=
"javascript"
>
<script
th:inline=
"javascript"
>
/*<![CDATA[*/
/*<![CDATA[*/
var
dianjiaoguanLoinUrl
=
[[
$
{
dianjiaoguanLoinUrl
}]];
var
dianjiaoguanLoinUrl
=
[[
$
{
dianjiaoguanLo
g
inUrl
}]];
var
edenoperationLoginUrl
=
[[
$
{
edenoperationLoginUrl
}]];
var
edenoperationLoginUrl
=
[[
$
{
edenoperationLoginUrl
}]];
var
logId
=
[[
$
{
logId
}]];
var
logId
=
[[
$
{
logId
}]];
var
loginType
=
[[
$
{
loginType
}]];
var
loginType
=
[[
$
{
loginType
}]];
...
...
eden-authcenter-agent/src/main/resources/templates/login/index.html
0 → 100644
View file @
74b4b318
<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<html
class=
"no-js"
xmlns:th=
"http://www.w3.org/1999/xhtml"
>
<!--<![endif]-->
<head>
<meta
charset=
"utf-8"
/>
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<meta
content=
""
name=
"description"
/>
<meta
content=
"width=device-width, initial-scale=1"
name=
"viewport"
/>
<title>
统一认证登录配置
</title>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/main_0216.css}"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/bootstrap.min.css}"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/normalize.css}"
/>
<script
type=
"text/javascript"
th:src=
"@{/static/js/jquery-1.10.2.min.js}"
></script>
<!--<script src="../js/vendor/modernizr-2.6.2.min.js"></script>-->
</head>
<body
style=
"background-color: #4e97f7 !important;"
>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a
href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div
class=
"bg"
>
<div
class=
"bg-form"
>
<div
class=
"loginContainer"
>
<div
class=
"login-box text-center"
>
<form
class=
"form"
method=
"post"
>
<h2
class=
"text-center"
style=
"margin-top: 30px;"
>
统一认证登录配置
</h2>
<div
class=
"bg-form"
style=
"width: 80%;margin: 50px auto"
>
<div
class=
"form-group text-left"
style=
"float: left"
>
<div
class=
"input-group"
>
<span
class=
"input-group-addon"
id=
"basic-addon1"
><span
aria-hidden=
"true"
class=
"glyphicon glyphicon-user"
></span></span>
<input
aria-describedby=
"basic-addon1"
autocomplete=
"off"
class=
"form-control"
id=
"account"
placeholder=
"请输入管理员账号"
size=
"25"
tabindex=
"1"
type=
"text"
name=
"account"
value=
""
/>
</div>
</div>
<div
class=
"form-group text-left"
style=
"float: left"
>
<div
class=
"input-group"
>
<span
class=
"input-group-addon "
id=
"basic-addon2"
>
<span
aria-hidden=
"true"
class=
"glyphicon glyphicon-lock"
></span></span>
<input
aria-describedby=
"basic-addon1"
autocomplete=
"off"
class=
"form-control"
id=
"password"
placeholder=
"请输入管理员密码"
size=
"25"
tabindex=
"2"
type=
"password"
name=
"password"
/>
</div>
</div>
<button
accesskey=
"l"
class=
"btn btn-primary btn-block"
id=
"login-button"
style=
"outline: 0"
tabindex=
"6"
type=
"button"
onclick=
"toLogin()"
>
登录
</button>
</div>
</form>
</div>
<!-- <div class="login-box">
<button onclick="toLogin(1)" accesskey="l" class="login-btn" id="login-button" name="button" style="outline: 0" type="button">登录
</button>
</div> -->
</div>
</div>
</div>
<script
th:inline=
"javascript"
>
/*<![CDATA[*/
var
ctxPath
=
/*[[@{/}]]*/
''
;
/*]]>*/
</script>
<script
type=
"text/javascript"
>
function
toLogin
()
{
var
action
=
ctxPath
+
"login/login"
;
$
(
"form"
).
attr
(
"action"
,
action
);
$
(
"form"
).
submit
();
}
</script>
</body></html>
\ No newline at end of file
eden-authcenter-agent/src/main/resources/templates/statistics.html
View file @
74b4b318
...
@@ -12,22 +12,22 @@
...
@@ -12,22 +12,22 @@
<!--<![endif]-->
<!--<![endif]-->
<head>
<head>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<meta
content=
""
name=
"description"
/>
<meta
content=
""
name=
"description"
/>
<meta
content=
"width=device-width, initial-scale=1"
name=
"viewport"
/>
<meta
content=
"width=device-width, initial-scale=1"
name=
"viewport"
/>
<title>
上海市中小学数字教材
</title>
<title>
上海市中小学数字教材
</title>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/main_0327.css}
"
/>
<link
rel=
"stylesheet"
href=
"../static/css/main_0327.css
"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/statistics.css}
"
/>
<link
rel=
"stylesheet"
href=
"../static/css/statistics.css
"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/bootstrap.min.css}
"
/>
<link
rel=
"stylesheet"
href=
"../static/css/bootstrap.min.css
"
/>
<link
rel=
"stylesheet"
th:href=
"@{/static/css/normalize.css}
"
/>
<link
rel=
"stylesheet"
href=
"../static/css/normalize.css
"
/>
<link
rel=
"stylesheet"
type=
"text/css"
th:href=
"@{/static/css/iview.css}
"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"../static/css/iview.css
"
/>
<link
rel=
"shortcut icon"
th:href=
"@{/static/img/favicon.ico}"
>
<link
rel=
"shortcut icon"
href=
"../static/img/favicon.ico"
>
<script
type=
"text/javascript"
src=
"../static/js/jquery-1.10.2.min.js"
></script>
<script
type=
"text/javascript"
src=
"../static/js/jquery-1.10.2.min.js"
></script>
<script
src=
"../static/js/echarts.min.js"
></script>
<script
src=
"../static/js/echarts.min.js"
></script>
<script
src=
"../static/js/vue.js"
></script>
<script
src=
"../static/js/vue.js"
></script>
<script
type=
"text/javascript"
src=
"../static/js/iview.min.js"
></script>
<script
type=
"text/javascript"
src=
"../static/js/iview.min.js"
></script>
<!-- <link rel="stylesheet" th:href="@{/static/css/main_0327.css}"/>
<!-- <link rel="stylesheet" th:href="@{/static/css/main_0327.css}"/>
<link rel="stylesheet" href="@{/static/css/statistics.css}"/>
<link rel="stylesheet" href="@{/static/css/statistics.css}"/>
<link rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/static/css/normalize.css}"/>
<link rel="stylesheet" th:href="@{/static/css/normalize.css}"/>
...
@@ -36,726 +36,668 @@
...
@@ -36,726 +36,668 @@
</head>
</head>
<body
style=
"background-color: rgb(244, 245, 245);"
>
<body
style=
"background-color: rgb(244, 245, 245);"
>
<!--[if lt IE 7]>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a
href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<![endif]-->
<!-- Add your site or application content here -->
<!-- Add your site or application content here -->
<div
id=
"app"
class=
"static"
>
<div
id=
"app"
class=
"static"
>
<div
class=
"statistics-header"
>
<div
class=
"statistics-header"
>
<div
class=
"flex"
style=
"display: flex; align-items: center;"
>
<div
class=
"flex"
style=
"display: flex; align-items: center;"
>
<img
src=
"../static/img/Rlogo.png"
style=
"margin:5px 0; margin-left: 30px; width: 250px;"
alt=
""
>
<img
src=
"../static/img/Rlogo.png"
style=
"margin:5px 0; margin-left: 30px; width: 250px;"
alt=
""
>
<Divider
type=
"vertical"
style=
"height: 26px;"
></Divider>
<Divider
type=
"vertical"
style=
"height: 26px;"
></Divider>
<p
style=
"font-size: 14px; font-weight: 700;"
>
发现服务 · 速享之旅
</p>
<p
style=
"font-size: 14px; font-weight: 700;"
>
发现服务 · 速享之旅
</p>
</div>
</div>
<div
class=
"flex"
>
<div
class=
"flex"
>
<img
src=
"../static/img/top-title.png"
style=
"height: 22px;"
alt=
""
>
<img
src=
"../static/img/top-title.png"
style=
"height: 22px;"
alt=
""
>
</div>
</div>
<div
class=
"flex"
style=
"display: flex;"
>
<div
class=
"flex"
style=
"display: flex;"
>
<i-select
v-model=
"app"
@
on-change=
"refresh"
style=
"width: 120px; margin: 0 5px;"
>
<i-select
v-model=
"app"
@
on-change=
"refresh"
style=
"width: 120px; margin: 0 5px;"
>
<i-option
v-for=
"item in appList"
:value=
"item.code"
:label=
"item.name"
></i-option>
<i-option
v-for=
"item in appList"
:value=
"item.code"
:label=
"item.name"
></i-option>
</i-select>
</i-select>
<i-select
v-model=
"time"
@
on-change=
"refresh"
style=
"width: 120px; margin: 0 5px;"
>
<i-select
v-model=
"timeRange"
@
on-change=
"refresh"
<i-option
v-for=
"item in timeType"
:value=
"item.code"
:label=
"item.name"
></i-option>
style=
"width: 120px; margin: 0 5px;"
>
</i-select>
<i-option
v-for=
"item in timeRangeList"
:value=
"item.code"
:label=
"item.name"
></i-option>
<i-select
v-if=
"time === 'year'"
v-model=
"year"
@
on-change=
"refresh"
style=
"width: 120px; margin: 0 5px;"
>
</i-select>
<i-option
v-for=
"item in yearList"
:value=
"item.code"
:label=
"item.name"
></i-option>
</i-select>
<i-select
v-if=
"time === 'month'"
v-model=
"month"
@
on-change=
"refresh"
style=
"width: 120px; margin: 0 5px;"
>
<i-option
v-for=
"item in monthList"
:value=
"item.code"
:label=
"item.name"
></i-option>
</i-select>
</div>
</div>
<div
class=
"statistics-content"
>
<div
style=
"width: 25%; height: 100%;"
>
<div
class=
"statistics-content-item item-height"
>
<p
class=
"statistics-content-item-title"
>
应用来源
</p>
<div
id=
"app-source"
style=
"width: 95%;height: calc(100% - 40px); margin: 5px 5px;"
></div>
</div>
<div
class=
"statistics-content-item item-height-higher"
>
<p
class=
"statistics-content-item-title"
>
来源环境分析
</p>
<div
id=
"app-env-browser"
style=
"width: 95%;height: calc(50% - 30px); margin: 5px 5px;"
></div>
<div
id=
"app-env-system"
style=
"width: 95%;height: calc(50% - 30px); margin: 5px 5px;"
></div>
</div>
</div>
<div
style=
"width: 50%; height: 100%;"
>
<div
class=
"statistics-content-item"
style=
"height: 30%;"
>
<p
class=
"statistics-content-item-title"
>
认证数据统计
<span
class=
"statistics-content-item-title-remark"
>
累计登录用户总数:
<span
v-text=
"numsOfPeople"
></span>
人
</span>
</p>
<div
style=
"display: flex; height: 100%;"
>
<div
class=
"nums-by-idp"
style=
"height: calc(100% - 40px);"
>
<div
class=
"nums-total"
style=
"background: url(../static/img/center-bg-1.png);"
>
<p
class=
"nums-title"
>
总人次
</p>
<p
class=
"nums-title-num"
><span
class=
"nums-total-nums"
v-text=
"nums"
></span>
人次
</p>
</div>
<div
class=
"nums-total"
style=
"background: url(../static/img/center-bg-2.png);"
>
<p
class=
"nums-title"
>
基础教育统一认证
</p>
<p
class=
"nums-title-num"
><span
class=
"nums-total-nums"
v-text=
"numsJcjy"
></span>
人次
</p>
</div>
<div
class=
"nums-total"
style=
"background: url(../static/img/center-bg-3.png);"
>
<p
class=
"nums-title"
>
青浦区认证子域
</p>
<p
class=
"nums-title-num"
><span
class=
"nums-total-nums"
v-text=
"numsQp"
></span>
人次
</p>
</div>
<div
class=
"nums-total"
style=
"background: url(../static/img/center-bg-4.png);"
>
<p
class=
"nums-title"
>
数字教材实验用户
</p>
<p
class=
"nums-title-num"
><span
class=
"nums-total-nums"
v-text=
"numsSy"
></span>
人次
</p>
</div>
<!-- <div style="margin-top: 10px; line-height: 1.5;">
<p v-for="item in numsIdpList">通过<span v-text="item.name"></span>子域认证:<span class="idp-total-nums"
v-text="item.value"></span>
</p>
</div> -->
</div>
</div>
<!-- <div id="idp" style="width: 48%; height: calc(100% - 40px); margin: 5px 5px;"></div> -->
</div>
</div>
<div
class=
"statistics-content-item"
style=
"height: 70%;"
>
<p
class=
"statistics-content-item-title"
>
认证登陆高峰时间
</p>
<div
id=
"nums-by-time"
style=
"width: 100%; height: calc(100% - 40px); margin: 0;"
></div>
</div>
</div>
<div
style=
"width: 25%; height: 100%;"
>
<div
class=
"statistics-content-item item-height"
>
<p
class=
"statistics-content-item-title"
>
身份认证
</p>
<div
id=
"user-type"
style=
"width: 95%;height: calc(100% - 40px); margin: 5px 5px;"
></div>
</div>
</div>
<div
class=
"statistics-content-item item-height-higher"
>
<div
class=
"statistics-content"
>
<p
class=
"statistics-content-item-title"
>
认证热点单位
</p>
<div
style=
"width: 28%; height: 100%;"
>
<div
id=
"user-org"
style=
"height: calc(100% - 40px); margin-top: 8px;"
>
<div
class=
"statistics-content-item item-height"
>
<p
style=
"padding: 5px 20px 0 20px; color: #5f646a; font-size: 12px; line-height: 1.8;"
v-for=
"item in userOrgList"
><span
<p
class=
"statistics-content-item-title"
>
应用来源排行 TOP5
</p>
style=
"color: orange; font-weight: 900; padding-right: 8px;"
>
·
</span><span
v-text=
"item.name"
></span><span
<p
class=
"statistics-content-item-title-sub"
><span
v-text=
"formatTime(-timeRange)"
></span>
至
<span
v-text=
"formatTime(0)"
></span>
| 最近
<span
v-text=
"timeRange"
></span>
天
</p>
style=
"float: right;"
v-text=
"item.count + ' 人次'"
></span></p>
<div
id=
"app-source"
style=
"height: calc(100% - 65px); margin: 5px 5px;"
></div>
</div>
</div>
<div
class=
"statistics-content-item item-height-higher"
>
<p
class=
"statistics-content-item-title"
>
认证热点单位
</p>
<p
class=
"statistics-content-item-title-sub"
><span
v-text=
"formatTime(-timeRange)"
></span>
至
<span
v-text=
"formatTime(0)"
></span>
| 最近
<span
v-text=
"timeRange"
></span>
天
</p>
<div
id=
"user-org"
style=
"height: calc(100% - 65px); margin-top: 8px;"
>
<p
style=
"padding: 5px 20px 0 20px; color: #5f646a; font-size: 12px; line-height: 1.8;"
v-for=
"item in userOrgList"
><span
style=
"color: orange; font-weight: 900; padding-right: 8px;"
>
·
</span><span
v-text=
"item.name"
></span><span
style=
"float: right;"
v-text=
"item.count + ' 人次'"
></span></p>
</div>
</div>
</div>
<div
style=
"width: 72%; height: 100%;"
>
<div
class=
"statistics-content-item"
style=
"height: 50%; display: flex;"
>
<div
style=
"width: calc(100% - 150px); height: 100%;"
>
<p
class=
"statistics-content-item-title"
>
认证用户访问情况统计
</p>
<p
class=
"statistics-content-item-title-sub"
><span
v-text=
"formatTime(-timeRange)"
></span>
至
<span
v-text=
"formatTime(0)"
></span>
| 最近
<span
v-text=
"timeRange"
></span>
天
</p>
<div
id=
"nums-by-time"
style=
"width: 100%; height: calc(100% - 65px); margin: 0;"
></div>
</div>
<div
style=
"width: 150px; margin-top: 65px;"
>
<p>
合计:
<span
v-text=
"totalCount"
></span>
人次
</p>
<p>
教师:
<span
v-text=
"teacherCount"
></span>
人次
</p>
<p>
学生:
<span
v-text=
"studentCount"
></span>
人次
</p>
<p>
其他:
<span
v-text=
"otherCount"
></span>
人次
</p>
<p>
均值:
<span
v-text=
"avgTotalCount"
></span>
人次/天
</p>
<p>
教师:
<span
v-text=
"avgTeacherCount"
></span>
人次/天
</p>
<p>
学生:
<span
v-text=
"avgStudentCount"
></span>
人次/天
</p>
<p>
其他:
<span
v-text=
"avgOtherCount"
></span>
人次/天
</p>
</div>
</div>
<div
style=
"height: 50%; display: flex;"
>
<div
class=
"statistics-content-item"
style=
"width: 50%; height: 100%;"
>
<div
style=
"display: flex; justify-content: space-between;"
>
<div>
<p
class=
"statistics-content-item-title"
>
用户访问高峰时段
</p>
<p
class=
"statistics-content-item-title-sub"
><span
v-text=
"formatTime(-timeRange)"
></span>
至
<span
v-text=
"formatTime(0)"
></span>
| 最近
<span
v-text=
"timeRange"
></span>
天
</p>
</div>
<div
v-if=
"maxHour"
style=
"margin-top: 32px; margin-right: 20px;"
>
<p>
最高:
<span
v-text=
"maxHour.count"
style=
"font-size: 18px; font-weight: 900; "
></span>
人次
<span
v-text=
"maxHour.yearMonthDay"
></span>
<span
v-text=
"maxHour.hour"
></span>
:00
</p>
</div>
</div>
<div
id=
"pv"
style=
"width: 95%;height: calc(100% - 65px); margin: 5px 5px;"
></div>
</div>
<div
class=
"statistics-content-item"
style=
"width: 50%; height: 100%;"
>
<p
class=
"statistics-content-item-title"
>
来源环境分析
</p>
<p
class=
"statistics-content-item-title-sub"
><span
v-text=
"formatTime(-timeRange)"
></span>
至
<span
v-text=
"formatTime(0)"
></span>
| 最近
<span
v-text=
"timeRange"
></span>
天
</p>
<div
id=
"app-env-browser"
style=
"width: 95%;height: calc(100% - 65px); margin: 5px 5px;"
></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- iview使用了includes方法,兼容ie11 -->
<!-- iview使用了includes方法,兼容ie11 -->
<script>
<script>
if
(
!
Array
.
prototype
.
includes
)
{
if
(
!
Array
.
prototype
.
includes
)
{
Object
.
defineProperty
(
Array
.
prototype
,
'includes'
,
{
Object
.
defineProperty
(
Array
.
prototype
,
'includes'
,
{
value
:
function
(
valueToFind
,
fromIndex
)
{
value
:
function
(
valueToFind
,
fromIndex
)
{
if
(
this
==
null
)
{
if
(
this
==
null
)
{
throw
new
TypeError
(
'"this" is null or not defined'
);
throw
new
TypeError
(
'"this" is null or not defined'
);
}
}
// 1. Let O be ? ToObject(this value).
var
o
=
Object
(
this
);
// 2. Let len be ? ToLength(? Get(O, "length")).
var
len
=
o
.
length
>>>
0
;
// 3. If len is 0, return false.
// 1. Let O be ? ToObject(this value).
if
(
len
===
0
)
{
var
o
=
Object
(
this
);
return
false
;
}
// 4. Let n be ? ToInteger(fromIndex).
// 2. Let len be ? ToLength(? Get(O, "length")).
// (If fromIndex is undefined, this step produces the value 0.)
var
len
=
o
.
length
>>>
0
;
var
n
=
fromIndex
|
0
;
// 5. If n ≥ 0, then
// 3. If len is 0, return false.
// a. Let k be n.
if
(
len
===
0
)
{
// 6. Else n
<
0
,
return
false
;
// a. Let k be len + n.
}
// b. If k
<
0
,
let
k
be
0
.
var
k
=
Math
.
max
(
n
>=
0
?
n
:
len
-
Math
.
abs
(
n
),
0
);
function
sameValueZero
(
x
,
y
)
{
// 4. Let n be ? ToInteger(fromIndex).
return
x
===
y
||
(
typeof
x
===
'number'
&&
typeof
y
===
'number'
&&
isNaN
(
x
)
&&
isNaN
(
y
));
// (If fromIndex is undefined, this step produces the value 0.)
}
var
n
=
fromIndex
|
0
;
// 7. Repeat, while k
<
len
// 5. If n ≥ 0, then
while
(
k
<
len
)
{
// a. Let k be n.
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
// 6. Else n
<
0
,
// b. If SameValueZero(valueToFind, elementK) is true, return true.
// a. Let k be len + n.
if
(
sameValueZero
(
o
[
k
],
valueToFind
))
{
// b. If k
<
0
,
let
k
be
0
.
return
true
;
var
k
=
Math
.
max
(
n
>=
0
?
n
:
len
-
Math
.
abs
(
n
),
0
);
}
// c. Increase k by 1.
k
++
;
}
// 8. Return false
function
sameValueZero
(
x
,
y
)
{
return
false
;
return
x
===
y
||
(
typeof
x
===
'number'
&&
typeof
y
===
'number'
&&
isNaN
(
x
)
&&
}
isNaN
(
y
));
});
}
}
</script>
<script
type=
"text/javascript"
>
// 7. Repeat, while k
<
len
var
baseUrl
=
"/"
;
while
(
k
<
len
)
{
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
// b. If SameValueZero(valueToFind, elementK) is true, return true.
if
(
sameValueZero
(
o
[
k
],
valueToFind
))
{
return
true
;
}
// c. Increase k by 1.
k
++
;
}
var
colorList
=
[
// 8. Return false
'#6c5df1'
,
'#a78bf4'
,
'#fdbf3c'
,
'#ec6367'
,
'#2fcaa8'
,
'#79c161'
return
false
;
]
}
new
Vue
({
});
el
:
'#app'
,
data
:
{
year
:
'all'
,
yearList
:
[],
month
:
1
,
monthList
:
[],
time
:
'year'
,
timeType
:
[
{
code
:
'year'
,
name
:
'按年统计'
},
{
code
:
'month'
,
name
:
'按月统计'
},
],
app
:
'all'
,
appList
:
[],
numsIdpList
:
[],
userOrgList
:
[],
nums
:
0
,
numsJcjy
:
0
,
numsQp
:
0
,
numsSy
:
0
,
numsOfPeople
:
0
},
mounted
:
function
()
{
this
.
init
();
this
.
refresh
();
var
_this
=
this
;
window
.
onresize
=
function
()
{
var
myChart
=
echarts
.
init
(
document
.
getElementById
(
'app-source'
));
var
myChartBrowser
=
echarts
.
init
(
document
.
getElementById
(
'app-env-browser'
));
var
myChartSystem
=
echarts
.
init
(
document
.
getElementById
(
'app-env-system'
));
// var myChartNums = echarts.init(document.getElementById("idp"));
var
myChartNumsByTime
=
echarts
.
init
(
document
.
getElementById
(
"nums-by-time"
));
var
myChartUserType
=
echarts
.
init
(
document
.
getElementById
(
'user-type'
));
myChart
.
resize
();
myChartBrowser
.
resize
();
myChartSystem
.
resize
();
// myChartNums.resize();
myChartNumsByTime
.
resize
();
myChartUserType
.
resize
();
}
}
},
</script>
methods
:
{
init
:
function
()
{
this
.
appList
=
[{
code
:
'all'
,
name
:
'全部'
}]
var
date
=
new
Date
();
var
year
=
date
.
getFullYear
();
var
month
=
date
.
getMonth
()
+
1
;
this
.
yearList
=
[{
code
:
'all'
,
name
:
'全部'
},]
<script
type=
"text/javascript"
>
for
(
var
i
=
2020
;
i
<=
year
;
i
++
)
{
var
baseUrl
=
"/authcenter"
;
this
.
yearList
.
push
({
code
:
i
,
name
:
i
+
"年"
})
}
for
(
var
i
=
1
;
i
<=
month
;
i
++
)
{
this
.
monthList
.
push
({
code
:
i
,
name
:
year
+
'年'
+
i
+
"月"
})
}
var
_this
=
this
;
var
colorList
=
[
$
.
ajax
({
'#6c5df1'
,
'#a78bf4'
,
'#fdbf3c'
,
'#ec6367'
,
'#2fcaa8'
,
'#79c161'
type
:
'GET'
,
]
url
:
baseUrl
+
'authcenter/logstatistics/auth_apps'
,
new
Vue
({
success
:
function
(
result
)
{
el
:
'#app'
,
_this
.
appList
=
_this
.
appList
.
concat
(
result
.
data
)
data
:
{
},
year
:
'all'
,
error
:
function
(
e
)
{
timeRangeList
:
[],
console
.
log
(
e
)
month
:
1
,
}
monthList
:
[],
})
timeRange
:
7
,
},
app
:
'all'
,
refresh
:
function
()
{
appList
:
[],
this
.
initSource
();
numsIdpList
:
[],
this
.
initAppEnv
();
userOrgList
:
[],
this
.
initNums
();
totalCount
:
0
,
this
.
initNumsByTime
();
teacherCount
:
0
,
this
.
initUserType
();
studentCount
:
0
,
this
.
initUserOrg
();
otherCount
:
0
,
},
avgTotalCount
:
0
,
initSource
:
function
()
{
avgTeacherCount
:
0
,
var
myChart
=
echarts
.
init
(
document
.
getElementById
(
'app-source'
));
avgStudentCount
:
0
,
var
option
=
{
avgOtherCount
:
0
,
tooltip
:
{
maxHour
:
null
,
trigger
:
"item"
,
formatter
:
"{a} <br/>{b}: {c}人次 ({d}%)"
,
position
:
[
20
,
20
],
},
legend
:
{
icon
:
"circle"
,
bottom
:
0
,
data
:
[
"数字教材"
,
"阅览室"
,
"其他"
]
},
},
series
:
[
mounted
:
function
()
{
{
this
.
init
();
name
:
"应用来源"
,
this
.
refresh
();
type
:
"pie"
,
var
_this
=
this
;
radius
:
[
"40%"
,
"60%"
],
window
.
onresize
=
function
()
{
center
:
[
"50%"
,
"48%"
],
var
myChart
=
echarts
.
init
(
document
.
getElementById
(
'app-source'
),
'light'
);
label
:
{
var
myChartBrowser
=
echarts
.
init
(
document
.
getElementById
(
'app-env-browser'
),
'light'
);
position
:
'outside'
,
var
myChartNumsByTime
=
echarts
.
init
(
document
.
getElementById
(
"nums-by-time"
),
'light'
);
formatter
:
"{per|{d}%}"
,
var
myChartPV
=
echarts
.
init
(
document
.
getElementById
(
'pv'
),
'light'
);
rich
:
{
myChart
.
resize
();
per
:
{
myChartBrowser
.
resize
();
color
:
"black"
myChartNumsByTime
.
resize
();
}
myChartPV
.
resize
();
}
},
data
:
[],
itemStyle
:
{
normal
:
{
color
:
function
(
params
)
{
// build a color map as your need.
return
colorList
[
params
.
dataIndex
]
}
}
}
}
}
]
};
var
params
=
{
clientId
:
this
.
app
,
year
:
this
.
year
,
month
:
this
.
month
}
var
_this
=
this
;
$
.
ajax
({
url
:
baseUrl
+
'authcenter/logstatistics/app?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
// _this.appList = _this.appList.concat(result.data.data)
var
legend
=
[];
var
data
=
[];
for
(
var
i
=
0
;
i
<
result
.
data
.
length
;
i
++
)
{
var
element
=
result
.
data
[
i
];
legend
.
push
(
element
.
name
);
data
.
push
({
value
:
element
.
count
,
name
:
element
.
name
})
}
option
.
legend
.
data
=
legend
;
option
.
series
[
0
].
data
=
data
;
myChart
.
setOption
(
option
);
},
},
error
:
function
(
e
)
{
methods
:
{
console
.
log
(
e
)
init
:
function
()
{
}
this
.
appList
=
[{
})
code
:
'all'
,
},
name
:
'全部'
initAppEnv
:
function
()
{
}]
var
params
=
{
clientId
:
this
.
app
,
year
:
this
.
year
,
month
:
this
.
month
}
var
_this
=
this
;
$
.
ajax
({
url
:
baseUrl
+
'authcenter/logstatistics/environment?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
var
legendSystem
=
[],
dataSystem
=
[],
legendBroswer
=
[],
dataBrowser
=
[];
if
(
result
.
data
.
os
.
length
)
{
this
.
timeRangeList
=
[{
result
.
data
.
os
.
sort
(
function
(
a
,
b
)
{
return
b
.
count
-
a
.
count
})
code
:
7
,
}
name
:
'最近7天'
var
others
=
{
name
:
'其他'
,
value
:
0
};
},
{
var
t
=
0
;
code
:
30
,
for
(
var
i
=
0
;
i
<
result
.
data
.
os
.
length
;
i
++
)
{
name
:
'最近30天'
var
element
=
result
.
data
.
os
[
i
];
},
{
if
(
element
.
name
===
'unknown'
)
element
.
name
=
'未知'
code
:
180
,
if
(
element
.
name
===
'others'
||
t
>=
4
)
{
name
:
'最近180天'
others
.
value
+=
element
.
count
;
},
{
continue
;
code
:
365
,
}
name
:
'最近一年'
t
++
;
}]
legendSystem
.
push
(
element
.
name
);
dataSystem
.
push
({
value
:
element
.
count
,
name
:
element
.
name
})
}
if
(
others
.
value
)
{
legendSystem
.
push
(
'其他'
);
dataSystem
.
push
(
others
)
}
if
(
result
.
data
.
browser
.
length
)
{
var
_this
=
this
;
result
.
data
.
browser
.
sort
(
function
(
a
,
b
)
{
return
b
.
count
-
a
.
count
})
$
.
ajax
({
}
type
:
'GET'
,
others
=
{
name
:
'其他'
,
value
:
0
};
url
:
baseUrl
+
'/logstatistics/auth_apps'
,
t
=
0
;
success
:
function
(
result
)
{
for
(
var
i
=
0
;
i
<
result
.
data
.
browser
.
length
;
i
++
)
{
_this
.
appList
=
_this
.
appList
.
concat
(
result
.
data
)
var
element
=
result
.
data
.
browser
[
i
];
},
if
(
element
.
name
===
'unknown'
)
element
.
name
=
'未知'
error
:
function
(
e
)
{
if
(
element
.
name
===
'others'
||
t
>=
4
)
{
console
.
log
(
e
)
others
.
value
+=
element
.
count
;
}
continue
;
})
}
},
t
++
;
refresh
:
function
()
{
legendBroswer
.
push
(
element
.
name
);
this
.
initSource
();
dataBrowser
.
push
({
value
:
element
.
count
,
name
:
element
.
name
})
this
.
initAppEnv
();
}
this
.
initNums
();
if
(
others
.
value
)
{
this
.
initNumsByTime
();
legendBroswer
.
push
(
'其他'
);
this
.
initUserType
();
dataBrowser
.
push
(
others
)
this
.
initUserOrg
();
}
},
initSource
:
function
()
{
var
myChart
=
echarts
.
init
(
document
.
getElementById
(
'app-source'
),
'light'
);
var
option
=
{
yAxis
:
{
type
:
'category'
,
data
:
[
'数字教材'
,
'资源评价系统'
,
'阅览室'
,
'空中课堂'
,
'自适应学习系统'
],
axisLabel
:
{
interval
:
0
,
}
},
xAxis
:
{
type
:
'value'
,
minInterval
:
1
},
series
:
[{
data
:
[
120
,
200
,
150
,
80
,
70
,
110
,
130
],
type
:
'bar'
,
itemStyle
:
{
normal
:
{
color
:
function
(
params
)
{
// build a color map as your need.
return
colorList
[
params
.
dataIndex
]
}
}
}
}],
grid
:
{
left
:
0
,
top
:
0
,
bottom
:
0
,
containLabel
:
true
,
},
tooltip
:
{
trigger
:
'axis'
,
axisPointer
:
{
// Use axis to trigger tooltip
type
:
'shadow'
// 'shadow' as default; can also be 'line' or 'shadow'
}
},
};
var
params
=
{
latestDays
:
this
.
timeRange
,
topN
:
5
}
var
_this
=
this
;
$
.
ajax
({
url
:
baseUrl
+
'/statistics/app?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
// _this.appList = _this.appList.concat(result.data.data)
var
myChartBrowser
=
echarts
.
init
(
document
.
getElementById
(
'app-env-browser'
));
var
legend
=
[];
var
optionBrowser
=
{
var
data
=
[];
tooltip
:
{
for
(
var
i
=
0
;
i
<
result
.
data
.
length
;
i
++
)
{
trigger
:
"item"
,
var
element
=
result
.
data
[
i
];
formatter
:
"{a} <br/>{b}: {c}人次 ({d}%)"
,
legend
.
push
(
element
.
name
);
position
:
[
20
,
20
],
data
.
push
({
value
:
element
.
count
,
name
:
element
.
name
})
}
option
.
yAxis
.
data
=
legend
;
option
.
series
[
0
].
data
=
data
;
myChart
.
setOption
(
option
,
true
);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
})
},
},
legend
:
{
initAppEnv
:
function
()
{
icon
:
"circle"
,
var
params
=
{
orient
:
'vertical'
,
clientId
:
this
.
app
,
right
:
'right'
,
latestDays
:
this
.
timeRange
,
top
:
'middle'
,
topN
:
5
,
data
:
legendBroswer
,
formatter
:
function
(
name
)
{
var
target
;
for
(
var
i
=
0
,
l
=
dataBrowser
.
length
;
i
<
l
;
i
++
)
{
if
(
dataBrowser
[
i
].
name
==
name
)
{
target
=
dataBrowser
[
i
].
value
;
}
}
}
return
name
+
' '
+
target
;
var
_this
=
this
;
}
$
.
ajax
({
url
:
baseUrl
+
'/statistics/environment?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
var
series
=
[];
var
browserList
=
result
.
browserList
;
var
osList
=
result
.
osList
;
var
dataMap
=
result
.
dataMap
;
var
len
=
browserList
.
length
;
for
(
let
index
=
0
;
index
<
len
;
index
++
)
{
var
element
=
browserList
[
index
];
console
.
log
(
dataMap
?.[
element
]?.
reduce
((
t
,
n
)
=>
{
return
t
+
n
;
},
0
))
if
(
dataMap
?.[
element
]?.
reduce
((
t
,
n
)
=>
{
return
t
+
n
;
},
0
)
===
0
)
{
console
.
log
(
index
,
dataMap
)
browserList
.
splice
(
index
,
1
);
delete
dataMap
[
element
];
index
--
;
len
--
;
}
}
browserList
=
browserList
.
map
((
element
,
index
)
=>
{
if
(
element
===
'unknown'
)
{
dataMap
[
'未知'
]
=
dataMap
[
'unknown'
];
delete
dataMap
[
'unknown'
];
return
element
=
'未知'
;
}
if
(
element
===
'others'
)
{
dataMap
[
'其他'
]
=
dataMap
[
'others'
];
delete
dataMap
[
'others'
];
return
element
=
'其他'
;
}
return
element
;
})
osList
=
osList
.
map
((
element
,
index
)
=>
{
if
(
element
===
'unknown'
)
return
element
=
'未知'
;
if
(
element
===
'others'
)
return
element
=
'其他'
;
return
element
;
})
osList
.
forEach
((
element
,
index
)
=>
{
series
.
push
({
name
:
element
,
type
:
'bar'
,
stack
:
'total'
,
emphasis
:
{
focus
:
'series'
},
data
:
browserList
.
map
(
b
=>
{
return
dataMap
?.[
b
]?.[
index
]
||
0
;
}),
})
});
var
myChartBrowser
=
echarts
.
init
(
document
.
getElementById
(
'app-env-browser'
),
'light'
);
var
optionBrowser
=
{
tooltip
:
{
trigger
:
'axis'
,
axisPointer
:
{
// Use axis to trigger tooltip
type
:
'shadow'
// 'shadow' as default; can also be 'line' or 'shadow'
}
},
legend
:
{},
grid
:
{
left
:
'3%'
,
right
:
'4%'
,
bottom
:
'3%'
,
containLabel
:
true
},
xAxis
:
{
type
:
'value'
,
minInterval
:
1
},
yAxis
:
{
type
:
'category'
,
data
:
browserList
,
},
series
:
series
,
};
myChartBrowser
.
setOption
(
optionBrowser
,
true
);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
})
},
},
series
:
[
initNums
:
function
()
{
{
var
_this
=
this
;
name
:
"浏览器类型"
,
type
:
"pie"
,
var
params
=
{
radius
:
[
"30%"
,
"70%"
],
clientId
:
_this
.
app
,
center
:
[
'30%'
,
'50%'
],
latestDays
:
_this
.
timeRange
labelLine
:
{
}
show
:
false
$
.
ajax
({
},
url
:
baseUrl
+
'/statistics/auth_user_type_sum?'
+
_this
.
getParams
(
params
),
label
:
{
success
:
function
(
result
)
{
show
:
false
_this
.
totalCount
=
result
.
data
.
totalCount
;
},
_this
.
teacherCount
=
result
.
data
.
teacherCount
;
data
:
dataBrowser
,
_this
.
studentCount
=
result
.
data
.
studentCount
;
itemStyle
:
{
_this
.
otherCount
=
result
.
data
.
otherCount
;
normal
:
{
_this
.
avgTotalCount
=
result
.
data
.
avgTotalCount
;
color
:
function
(
params
)
{
_this
.
avgTeacherCount
=
result
.
data
.
avgTeacherCount
;
// build a color map as your need.
_this
.
avgStudentCount
=
result
.
data
.
avgStudentCount
;
return
colorList
[
params
.
dataIndex
]
_this
.
avgOtherCount
=
result
.
data
.
avgOtherCount
;
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
}
}
})
},
initNumsByTime
:
function
()
{
var
optionNumsByTime
=
{
grid
:
{
top
:
'20px'
,
left
:
'40px'
,
right
:
'40px'
,
bottom
:
'20px'
,
containLabel
:
true
},
tooltip
:
{
trigger
:
'axis'
,
axisPointer
:
{
type
:
'cross'
,
label
:
{
backgroundColor
:
'#6a7985'
}
}
},
legend
:
{},
xAxis
:
{
type
:
'category'
,
boundaryGap
:
false
,
axisLine
:
{
// show: false,//不显示坐标轴线
lineStyle
:
{
color
:
'lightgray'
}
},
axisLabel
:
{
color
:
"black"
//Y轴刻度字颜色
},
splitLine
:
{
show
:
true
},
data
:
[]
},
yAxis
:
{
type
:
'value'
,
minInterval
:
1
// axisLine: {
// // show: false,//不显示坐标轴线
// lineStyle: {
// color: 'lightgray'
// }
// },
// axisLabel: {
// show: false, //不显示坐标轴上的文字
// },
},
series
:
[{
name
:
'学生'
,
data
:
[],
type
:
'line'
,
stack
:
'Total'
,
areaStyle
:
{
normal
:
{
color
:
'#2fcaa8'
}
},
emphasis
:
{
focus
:
'series'
},
itemStyle
:
{
normal
:
{
color
:
'#2fcaa8'
}
}
},
{
name
:
'教师'
,
data
:
[],
type
:
'line'
,
stack
:
'Total'
,
areaStyle
:
{
normal
:
{
color
:
'#ec6367'
}
},
emphasis
:
{
focus
:
'series'
},
itemStyle
:
{
normal
:
{
color
:
'#ec6367'
}
}
},
{
name
:
'其他'
,
data
:
[],
type
:
'line'
,
stack
:
'Total'
,
areaStyle
:
{
normal
:
{
color
:
'#fdbf3c'
}},
emphasis
:
{
focus
:
'series'
},
itemStyle
:
{
normal
:
{
color
:
'#fdbf3c'
}
}
}]
};
var
params
=
{
clientId
:
this
.
app
,
latestDays
:
this
.
timeRange
}
}
}
var
_this
=
this
;
]
$
.
ajax
({
};
url
:
baseUrl
+
'/statistics/auth_user_type?'
+
_this
.
getParams
(
params
),
myChartBrowser
.
setOption
(
optionBrowser
);
success
:
function
(
result
)
{
var
legend
=
[],
var
myChartSystem
=
echarts
.
init
(
document
.
getElementById
(
'app-env-system'
));
studentData
=
[],
var
optionSystem
=
{
teacherData
=
[],
tooltip
:
{
otherData
=
[];
trigger
:
"item"
,
for
(
var
i
=
0
;
i
<
result
.
dataList
.
length
;
i
++
)
{
formatter
:
"{a} <br/>{b}: {c}人次 ({d}%)"
,
var
element
=
result
.
dataList
[
i
];
position
:
[
20
,
20
],
legend
.
push
(
element
.
date
);
studentData
.
push
(
element
.
studentCount
)
teacherData
.
push
(
element
.
teacherCount
)
otherData
.
push
(
element
.
otherCount
)
}
optionNumsByTime
.
xAxis
.
data
=
legend
;
optionNumsByTime
.
series
[
0
].
data
=
studentData
;
optionNumsByTime
.
series
[
1
].
data
=
teacherData
;
optionNumsByTime
.
series
[
2
].
data
=
otherData
;
var
myChartNumsByTime
=
echarts
.
init
(
document
.
getElementById
(
"nums-by-time"
),
'light'
);
myChartNumsByTime
.
setOption
(
optionNumsByTime
,
true
);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
})
},
},
legend
:
{
initUserType
:
function
()
{
icon
:
"circle"
,
var
optionPV
=
{
orient
:
'vertical'
,
xAxis
:
{
right
:
'right'
,
type
:
'category'
,
top
:
'middle'
,
data
:
[
'Mon'
,
'Tue'
,
'Wed'
,
'Thu'
,
'Fri'
,
'Sat'
,
'Sun'
]
data
:
legendSystem
,
},
formatter
:
function
(
name
)
{
yAxis
:
{
var
target
;
type
:
'value'
,
for
(
var
i
=
0
,
l
=
dataSystem
.
length
;
i
<
l
;
i
++
)
{
minInterval
:
1
if
(
dataSystem
[
i
].
name
==
name
)
{
},
target
=
dataSystem
[
i
].
value
;
series
:
[{
}
data
:
[
150
,
230
,
224
,
218
,
135
,
147
,
260
],
type
:
'line'
}],
tooltip
:
{
trigger
:
'axis'
,
axisPointer
:
{
type
:
'cross'
,
label
:
{
backgroundColor
:
'#6a7985'
}
}
},
};
var
params
=
{
clientId
:
this
.
app
,
latestDays
:
this
.
timeRange
,
}
}
return
name
+
' '
+
target
;
var
_this
=
this
;
}
$
.
ajax
({
url
:
baseUrl
+
'/statistics/auth_pick_times?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
_this
.
maxHour
=
result
.
maxHour
;
optionPV
.
xAxis
.
data
=
result
.
hourList
;
optionPV
.
series
[
0
].
data
=
result
.
dataList
;
var
myChartPV
=
echarts
.
init
(
document
.
getElementById
(
'pv'
),
'light'
);
myChartPV
.
setOption
(
optionPV
,
true
);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
})
},
},
series
:
[
initUserOrg
:
function
()
{
{
var
params
=
{
name
:
"操作系统类型"
,
clientId
:
this
.
app
,
type
:
"pie"
,
latestDays
:
this
.
timeRange
,
radius
:
[
"30%"
,
"70%"
],
topN
:
10
center
:
[
'30%'
,
'50%'
],
}
labelLine
:
{
var
_this
=
this
;
show
:
false
$
.
ajax
({
},
url
:
baseUrl
+
'/statistics/auth_hot_org?'
+
_this
.
getParams
(
label
:
{
params
),
show
:
false
success
:
function
(
result
)
{
},
_this
.
userOrgList
=
result
.
data
data
:
dataSystem
,
},
itemStyle
:
{
error
:
function
(
e
)
{
normal
:
{
console
.
log
(
e
)
color
:
function
(
params
)
{
// build a color map as your need.
return
colorList
[
params
.
dataIndex
]
}
}
}
})
},
getParams
:
function
(
params
)
{
if
(
!
params
)
return
''
;
var
res
=
''
;
var
keys
=
Object
.
keys
(
params
);
if
(
this
.
time
===
'month'
)
{
var
date
=
new
Date
();
var
year
=
date
.
getFullYear
();
params
.
year
=
year
;
params
.
month
=
year
+
'-'
+
(
this
.
month
<
10
?
(
'0'
+
this
.
month
)
:
this
.
month
);
}
}
}
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
]
if
(
this
.
time
!==
'month'
&&
keys
[
i
]
===
'month'
)
continue
;
};
if
(
params
[
keys
[
i
]]
!==
'all'
)
{
myChartSystem
.
setOption
(
optionSystem
);
if
(
res
!==
''
)
res
+=
'&'
},
res
=
res
+
keys
[
i
]
+
'='
+
params
[
keys
[
i
]];
error
:
function
(
e
)
{
}
console
.
log
(
e
)
}
})
},
initNums
:
function
()
{
var
_this
=
this
;
// $.getJSON('./static/js/SHdata.json', function (SHjson) {
// var myChartNums = echarts.init(document.getElementById("idp"));
// // 第二个参数为导入地图文件
// echarts.registerMap('shanghai', SHjson);
// var optionNums = {
// tooltip: {
// trigger: 'item',
// formatter: "{b}: {c}"
// },
// visualMap: {
// show: false,
// min: 0,
// max: 418,
// text: ['高', '低'],
// realtime: false,
// calculable: true,
// inRange: {
// color: ['lightskyblue', 'yellow', 'orangered']
// }
// },
// series: [
// {
// type: 'map',
// mapType: 'shanghai',
// data: [],
// }
// ]
// };
var
params
=
{
clientId
:
_this
.
app
,
year
:
_this
.
year
,
month
:
_this
.
month
}
$
.
ajax
({
url
:
baseUrl
+
'authcenter/logstatistics/auth?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
_this
.
nums
=
result
.
data
.
all_auth
;
_this
.
numsJcjy
=
result
.
data
.
cas_edu_auth
;
_this
.
numsQp
=
result
.
data
.
qp_auth
;
_this
.
numsSy
=
result
.
data
.
operator_auth
;
_this
.
numsOfPeople
=
result
.
data
.
num_of_people
;
// _this.numsIdpList = result.data.area_auth;
// var legend = [], data = [];
// for (var i = 0; i
<
result
.
data
.
area_auth
.
length
;
i
++
)
{
// var element = result.data.area_auth[i];
// legend.push(element.name);
// data.push({ value: element.count, name: element.name })
// }
// _this.numsIdpList = data.filter(function (element) { return element.value > 0 });
// optionNums.series[0].data = data
// myChartNums.setOption(optionNums);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
})
// })
},
initNumsByTime
:
function
()
{
var
optionNumsByTime
=
{
grid
:
{
top
:
'20px'
,
left
:
'40px'
,
right
:
'40px'
,
bottom
:
'20px'
,
containLabel
:
true
},
tooltip
:
{
trigger
:
'axis'
,
axisPointer
:
{
type
:
'cross'
,
label
:
{
backgroundColor
:
'#6a7985'
}
},
formatter
:
"{b}: {c}人次 "
},
xAxis
:
{
type
:
'category'
,
boundaryGap
:
false
,
axisLine
:
{
// show: false,//不显示坐标轴线
lineStyle
:
{
color
:
'lightgray'
}
},
axisLabel
:
{
color
:
"black"
//Y轴刻度字颜色
},
splitLine
:
{
show
:
true
},
data
:
[]
},
yAxis
:
{
type
:
'value'
,
axisLine
:
{
// show: false,//不显示坐标轴线
lineStyle
:
{
color
:
'lightgray'
}
},
axisLabel
:
{
show
:
false
,
//不显示坐标轴上的文字
},
},
series
:
[{
data
:
[],
type
:
'line'
,
smooth
:
true
,
lineStyle
:
{
color
:
"#4583f4"
},
areaStyle
:
{
color
:
'#4583f4'
}
}]
};
var
params
=
{
clientId
:
this
.
app
,
year
:
this
.
year
,
month
:
this
.
month
}
var
_this
=
this
;
$
.
ajax
({
url
:
baseUrl
+
'authcenter/logstatistics/auth_pick_times?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
var
legend
=
[],
data
=
[];
for
(
var
i
=
0
;
i
<
result
.
data
.
length
;
i
++
)
{
var
element
=
result
.
data
[
i
];
legend
.
push
(
element
.
name
);
data
.
push
({
value
:
element
.
count
,
name
:
element
.
name
})
}
optionNumsByTime
.
xAxis
.
data
=
legend
;
optionNumsByTime
.
series
[
0
].
data
=
data
;
var
myChartNumsByTime
=
echarts
.
init
(
document
.
getElementById
(
"nums-by-time"
));
myChartNumsByTime
.
setOption
(
optionNumsByTime
);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
})
},
initUserType
:
function
()
{
var
optionUserType
=
{
tooltip
:
{
trigger
:
"item"
,
formatter
:
"{a} <br/>{b}: {c}人次 ({d}%)"
,
position
:
[
20
,
20
],
},
legend
:
{
icon
:
"circle"
,
bottom
:
0
,
data
:
[]
},
series
:
[
{
name
:
"访客身份"
,
type
:
"pie"
,
radius
:
[
"30%"
,
"50%"
],
center
:
[
"50%"
,
"48%"
],
label
:
{
position
:
'outside'
,
formatter
:
"{per|{d}%}"
,
rich
:
{
per
:
{
color
:
"black"
}
}
}
return
res
;
},
},
data
:
[],
randomFun
:
function
(
arr
)
{
itemStyle
:
{
for
(
var
i
=
0
,
len
=
arr
.
length
;
i
<
len
;
i
++
)
{
normal
:
{
var
index
=
parseInt
(
Math
.
random
()
*
(
len
-
1
));
color
:
function
(
params
)
{
var
tempValue
=
arr
[
i
];
// build a color map as your need.
arr
[
i
]
=
arr
[
index
];
return
colorList
[
params
.
dataIndex
]
arr
[
index
]
=
tempValue
;
}
}
}
return
arr
;
}
},
}
formatTime
:
function
(
day
)
{
]
var
today
=
new
Date
();
};
var
target
=
today
.
getTime
()
+
1000
*
3600
*
24
*
day
;
var
params
=
{
today
.
setTime
(
target
);
clientId
:
this
.
app
,
return
today
.
getFullYear
()
+
'-'
+
(
today
.
getMonth
()
+
1
)
+
'-'
+
today
.
getDate
();
year
:
this
.
year
,
},
month
:
this
.
month
}
var
_this
=
this
;
$
.
ajax
({
url
:
baseUrl
+
'authcenter/logstatistics/auth_user_type?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
var
legend
=
[],
data
=
[];
for
(
var
i
=
0
;
i
<
result
.
data
.
length
;
i
++
)
{
var
element
=
result
.
data
[
i
];
legend
.
push
(
element
.
name
);
data
.
push
({
value
:
element
.
count
,
name
:
element
.
name
})
}
optionUserType
.
legend
.
data
=
legend
;
optionUserType
.
series
[
0
].
data
=
data
;
var
myChartUserType
=
echarts
.
init
(
document
.
getElementById
(
'user-type'
));
myChartUserType
.
setOption
(
optionUserType
);
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
})
},
initUserOrg
:
function
()
{
var
params
=
{
clientId
:
this
.
app
,
year
:
this
.
year
,
month
:
this
.
month
}
var
_this
=
this
;
$
.
ajax
({
url
:
baseUrl
+
'authcenter/logstatistics/auth_hot_org?'
+
_this
.
getParams
(
params
),
success
:
function
(
result
)
{
_this
.
userOrgList
=
result
.
data
},
error
:
function
(
e
)
{
console
.
log
(
e
)
}
})
},
getParams
:
function
(
params
)
{
if
(
!
params
)
return
''
;
var
res
=
''
;
var
keys
=
Object
.
keys
(
params
);
if
(
this
.
time
===
'month'
)
{
var
date
=
new
Date
();
var
year
=
date
.
getFullYear
();
params
.
year
=
year
;
params
.
month
=
year
+
'-'
+
(
this
.
month
<
10
?
(
'0'
+
this
.
month
)
:
this
.
month
);
}
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
if
(
this
.
time
!==
'month'
&&
keys
[
i
]
===
'month'
)
continue
;
if
(
params
[
keys
[
i
]]
!==
'all'
)
{
if
(
res
!==
''
)
res
+=
'&'
res
=
res
+
keys
[
i
]
+
'='
+
params
[
keys
[
i
]];
}
}
}
})
return
res
;
</script>
},
randomFun
:
function
(
arr
)
{
for
(
var
i
=
0
,
len
=
arr
.
length
;
i
<
len
;
i
++
)
{
var
index
=
parseInt
(
Math
.
random
()
*
(
len
-
1
));
var
tempValue
=
arr
[
i
];
arr
[
i
]
=
arr
[
index
];
arr
[
index
]
=
tempValue
;
}
return
arr
;
}
},
})
</script>
</body>
</body>
...
...
eden-authcenter-log/pom.xml
View file @
74b4b318
...
@@ -15,6 +15,21 @@
...
@@ -15,6 +15,21 @@
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
<exclusions>
<!-- 排除自带的logback依赖 -->
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-log4j2
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<groupId>
org.projectlombok
</groupId>
...
@@ -79,6 +94,12 @@
...
@@ -79,6 +94,12 @@
<type>
jar
</type>
<type>
jar
</type>
</dependency>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.7.22
</version>
</dependency>
</dependencies>
</dependencies>
...
...
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/config/dao/AuthClientDao.java
0 → 100644
View file @
74b4b318
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
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 @
74b4b318
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.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 @
74b4b318
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 @
74b4b318
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 @
74b4b318
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 @
74b4b318
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 @
74b4b318
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 @
74b4b318
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.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
;
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/dao/AuthLogDao.java
View file @
74b4b318
...
@@ -3,14 +3,30 @@ package com.chineseall.eden.authcenter.log.dao;
...
@@ -3,14 +3,30 @@ package com.chineseall.eden.authcenter.log.dao;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.PageRequest
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.PageRequest
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Pageable
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Pageable
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort
;
import
cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort
;
import
cn.sh.chineseall.framework.core.util.CollectionUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentCollection
;
import
cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentDatabase
;
import
cn.sh.chineseall.framework.dao.core.hql.Criteria
;
import
cn.sh.chineseall.framework.dao.core.hql.Criteria
;
import
cn.sh.chineseall.framework.dao.core.hql.Query
;
import
cn.sh.chineseall.framework.dao.core.hql.Query
;
import
cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao
;
import
cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao
;
import
cn.sh.chineseall.framework.dao.mongo.hql.MongoCriteriaTranslator
;
import
cn.sh.chineseall.framework.lang.calendar.DateUtils
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLogHourCount
;
import
com.mongodb.MongoClient
;
import
com.mongodb.client.AggregateIterable
;
import
com.mongodb.client.MongoCollection
;
import
com.mongodb.client.MongoDatabase
;
import
com.mongodb.client.model.*
;
import
com.mongodb.util.JSON
;
import
org.bson.BsonDocument
;
import
org.bson.Document
;
import
org.bson.conversions.Bson
;
import
org.json.JSONObject
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.*
;
import
java.util.Map
;
@Component
@Component
public
class
AuthLogDao
extends
StaticCacheDimensionDocumentMongoDao
<
AuthLog
,
String
>
{
public
class
AuthLogDao
extends
StaticCacheDimensionDocumentMongoDao
<
AuthLog
,
String
>
{
...
@@ -34,11 +50,17 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
...
@@ -34,11 +50,17 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
criteria
.
and
(
"logUserInfo.userType"
).
is
(
params
.
get
(
"userType"
).
toString
());
criteria
.
and
(
"logUserInfo.userType"
).
is
(
params
.
get
(
"userType"
).
toString
());
}
}
if
(
params
.
get
(
"beginTime"
)!=
null
){
if
(
params
.
get
(
"beginTime"
)!=
null
){
criteria
.
and
(
"createTime"
).
gte
((
Date
)
params
.
get
(
"beginTime"
));
List
<
String
>
days
=
getDayList
((
Date
)
params
.
get
(
"beginTime"
));
if
(
CollectionUtils
.
isNotEmpty
(
days
)){
criteria
.
and
(
"yearMonthDay"
).
in
(
days
);
}
}
}
if
(
params
.
get
(
"endTime"
)!=
null
){
if
(
params
.
get
(
"endTime"
)!=
null
){
criteria
.
lte
((
Date
)
params
.
get
(
"endTime"
));
criteria
.
lte
((
Date
)
params
.
get
(
"endTime"
));
}
}
if
(
params
.
get
(
"clientId"
)
!=
null
){
criteria
.
and
(
"clientId"
).
is
(
params
.
get
(
"clientId"
).
toString
());
}
Query
query
=
Query
.
query
(
criteria
);
Query
query
=
Query
.
query
(
criteria
);
return
count
(
query
);
return
count
(
query
);
}
}
...
@@ -60,6 +82,39 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
...
@@ -60,6 +82,39 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
return
super
.
distinct
(
key
,
new
Query
(
criteria
),
String
.
class
);
return
super
.
distinct
(
key
,
new
Query
(
criteria
),
String
.
class
);
}
}
public
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
params
,
Date
beginTime
){
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
params
&&
params
.
size
()
>
0
){
params
.
forEach
((
k
,
v
)->{
criteria
.
and
(
k
).
is
(
v
);
});
}
if
(
beginTime
!=
null
){
List
<
String
>
days
=
getDayList
(
beginTime
);
if
(
CollectionUtils
.
isNotEmpty
(
days
)){
criteria
.
and
(
"yearMonthDay"
).
in
(
days
);
}
}
return
super
.
distinct
(
key
,
new
Query
(
criteria
),
String
.
class
);
}
private
List
<
String
>
getDayList
(
Date
beginTime
){
Calendar
nextDay
=
Calendar
.
getInstance
();
nextDay
.
add
(
Calendar
.
DATE
,
1
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
beginTime
);
Set
<
String
>
days
=
new
HashSet
<>();
while
(
calendar
.
before
(
nextDay
)){
days
.
add
(
DateUtils
.
dateToString
(
calendar
.
getTime
(),
"yyyy-MM-dd"
));
calendar
.
add
(
Calendar
.
DATE
,
1
);
}
return
new
ArrayList
<>(
days
);
}
public
long
count
(
Map
<
String
,
Object
>
params
){
public
long
count
(
Map
<
String
,
Object
>
params
){
Criteria
criteria
=
new
Criteria
();
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
params
&&
params
.
size
()
>
0
){
if
(
null
!=
params
&&
params
.
size
()
>
0
){
...
@@ -71,6 +126,44 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
...
@@ -71,6 +126,44 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
return
count
(
query
);
return
count
(
query
);
}
}
public
long
count
(
Map
<
String
,
Object
>
params
,
Date
beginTime
){
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
params
&&
params
.
size
()
>
0
){
params
.
forEach
((
k
,
v
)->{
criteria
.
and
(
k
).
is
(
v
);
});
}
if
(
beginTime
!=
null
){
List
<
String
>
days
=
getDayList
(
beginTime
);
if
(
CollectionUtils
.
isNotEmpty
(
days
)){
criteria
.
and
(
"yearMonthDay"
).
in
(
days
);
}
}
Query
query
=
Query
.
query
(
criteria
);
return
count
(
query
);
}
public
long
count
(
Map
<
String
,
Object
>
params
,
List
<
String
>
notInBrowserList
,
Date
beginTime
){
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
params
&&
params
.
size
()
>
0
){
params
.
forEach
((
k
,
v
)->{
criteria
.
and
(
k
).
is
(
v
);
});
}
if
(
CollectionUtils
.
isNotEmpty
(
notInBrowserList
)){
criteria
.
and
(
"browser"
).
nin
(
notInBrowserList
);
}
if
(
beginTime
!=
null
){
List
<
String
>
days
=
getDayList
(
beginTime
);
if
(
CollectionUtils
.
isNotEmpty
(
days
)){
criteria
.
and
(
"yearMonthDay"
).
in
(
days
);
}
}
Query
query
=
Query
.
query
(
criteria
);
return
count
(
query
);
}
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
)
{
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
)
{
Criteria
criteria
=
new
Criteria
();
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
prams
&&
prams
.
size
()
>
0
){
if
(
null
!=
prams
&&
prams
.
size
()
>
0
){
...
@@ -83,4 +176,59 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
...
@@ -83,4 +176,59 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
Pageable
pageable
=
new
PageRequest
(
pageNo
-
1
,
pageSize
,
sort
);
Pageable
pageable
=
new
PageRequest
(
pageNo
-
1
,
pageSize
,
sort
);
return
query
(
query
.
with
(
pageable
));
return
query
(
query
.
with
(
pageable
));
}
}
public
List
<
AuthLogHourCount
>
hourMaxCount
(
Map
<
String
,
Object
>
matchParams
,
Date
beginTime
,
int
topN
){
DocumentDatabase
documentDatabase
=
(
DocumentDatabase
)
this
.
getDocumentClass
().
getAnnotation
(
DocumentDatabase
.
class
);
DocumentCollection
documentCollection
=
(
DocumentCollection
)
this
.
getDocumentClass
().
getAnnotation
(
DocumentCollection
.
class
);
MongoClient
mongoClient
=
super
.
getMongoClient
();
MongoDatabase
database
=
mongoClient
.
getDatabase
(
documentDatabase
.
database
());
MongoCollection
<
BsonDocument
>
collection
=
database
.
getCollection
(
documentCollection
.
collection
(),
BsonDocument
.
class
);
Criteria
criteria
=
new
Criteria
();
if
(
null
!=
matchParams
&&
matchParams
.
size
()
>
0
){
matchParams
.
forEach
((
k
,
v
)->{
criteria
.
and
(
k
).
is
(
v
);
});
}
if
(
beginTime
!=
null
){
List
<
String
>
days
=
getDayList
(
beginTime
);
if
(
CollectionUtils
.
isNotEmpty
(
days
)){
criteria
.
and
(
"yearMonthDay"
).
in
(
days
);
}
}
List
<
Bson
>
aggregateList
=
new
ArrayList
<>();
BsonDocument
matchDocument
=
MongoCriteriaTranslator
.
INSTANCE
.
translate
(
criteria
);
aggregateList
.
add
(
Aggregates
.
match
(
matchDocument
));
Document
groupBy
=
new
Document
().
append
(
"yearMonthDay"
,
"$yearMonthDay"
).
append
(
"hour"
,
"$hour"
);
aggregateList
.
add
(
Aggregates
.
group
(
groupBy
,
Accumulators
.
sum
(
"count"
,
1
)));
Document
project
=
new
Document
().
append
(
"_id"
,
0
).
append
(
"yearMonthDay"
,
"$_id.yearMonthDay"
).
append
(
"hour"
,
"$_id.hour"
).
append
(
"count"
,
"$count"
);
aggregateList
.
add
(
Aggregates
.
project
(
project
));
aggregateList
.
add
(
Aggregates
.
sort
(
Sorts
.
descending
(
"count"
)));
aggregateList
.
add
(
Aggregates
.
limit
(
topN
));
AggregateIterable
<
BsonDocument
>
iterable
=
collection
.
aggregate
(
aggregateList
);
List
<
AuthLogHourCount
>
dataList
=
new
ArrayList
<>();
for
(
BsonDocument
item
:
iterable
){
AuthLogHourCount
data
=
new
AuthLogHourCount
();
if
(
item
.
containsKey
(
"yearMonthDay"
)){
data
.
setYearMonthDay
(
item
.
getString
(
"yearMonthDay"
).
getValue
());
}
if
(
item
.
containsKey
(
"hour"
)
){
data
.
setHour
(
item
.
getInt32
(
"hour"
).
getValue
());
}
if
(
item
.
containsKey
(
"count"
)){
double
count
=
item
.
getInt32
(
"count"
).
getValue
();
data
.
setCount
(
Double
.
valueOf
(
count
).
longValue
());
}
dataList
.
add
(
data
);
}
return
dataList
;
}
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/model/AuthLog.java
View file @
74b4b318
...
@@ -79,6 +79,8 @@ public class AuthLog implements CacheDimensionDocument {
...
@@ -79,6 +79,8 @@ public class AuthLog implements CacheDimensionDocument {
@DocumentField
@DocumentField
private
String
yearMonthDay
;
private
String
yearMonthDay
;
private
Integer
hour
;
@Override
@Override
public
String
[]
generateCacheDimensions
()
{
public
String
[]
generateCacheDimensions
()
{
return
new
String
[
0
];
return
new
String
[
0
];
...
...
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/model/AuthLogHourCount.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
model
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.io.Serializable
;
@Getter
@Setter
public
class
AuthLogHourCount
implements
Serializable
{
private
String
yearMonthDay
;
private
Integer
hour
;
private
Long
count
;
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/service/AuthLogService.java
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
service
;
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
service
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLogHourCount
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -17,9 +19,16 @@ public interface AuthLogService {
...
@@ -17,9 +19,16 @@ public interface AuthLogService {
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
prams
);
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
prams
);
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
prams
,
Date
beginTime
);
long
count
(
Map
<
String
,
Object
>
prams
);
long
count
(
Map
<
String
,
Object
>
prams
);
long
count
(
Map
<
String
,
Object
>
prams
,
Date
beginTime
);
long
count
(
Map
<
String
,
Object
>
params
,
List
<
String
>
notInBrowserList
,
Date
beginTime
);
void
replace
(
AuthLog
authLog
);
void
replace
(
AuthLog
authLog
);
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
);
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
);
List
<
AuthLogHourCount
>
hourMaxCount
(
Map
<
String
,
Object
>
matchParams
,
Date
beginTime
,
int
topN
);
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/service/impl/AuthLogServiceImpl.java
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
service
.
impl
;
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
service
.
impl
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.sh.chineseall.framework.core.util.CollectionUtils
;
import
cn.sh.chineseall.framework.core.util.CollectionUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.chineseall.eden.authcenter.log.dao.AuthLogDao
;
import
com.chineseall.eden.authcenter.log.dao.AuthLogDao
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLog
;
import
com.chineseall.eden.authcenter.log.model.AuthLogHourCount
;
import
com.chineseall.eden.authcenter.log.model.LogUserInfo
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
import
com.chineseall.eden.authcenter.log.service.AuthLogService
;
import
com.chineseall.eden.authcenter.log.util.BusinessLogUtils
;
import
com.chineseall.eden.authcenter.log.util.RequestResponseHolder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -25,6 +31,7 @@ public class AuthLogServiceImpl implements AuthLogService {
...
@@ -25,6 +31,7 @@ public class AuthLogServiceImpl implements AuthLogService {
if
(
authLog
.
getId
()
!=
null
){
if
(
authLog
.
getId
()
!=
null
){
authLog
.
setUpdateTime
(
new
Date
());
authLog
.
setUpdateTime
(
new
Date
());
authLogDao
.
replace
(
authLog
);
authLogDao
.
replace
(
authLog
);
addBusinessLog
(
authLog
);
}
else
{
}
else
{
authLog
.
setId
(
UUID
.
randomUUID
().
toString
());
authLog
.
setId
(
UUID
.
randomUUID
().
toString
());
authLog
.
setCreateTime
(
new
Date
());
authLog
.
setCreateTime
(
new
Date
());
...
@@ -32,6 +39,28 @@ public class AuthLogServiceImpl implements AuthLogService {
...
@@ -32,6 +39,28 @@ public class AuthLogServiceImpl implements AuthLogService {
}
}
}
}
private
void
addBusinessLog
(
AuthLog
authLog
){
if
(
authLog
==
null
){
return
;
}
RequestResponseHolder
holder
=
RequestResponseHolder
.
get
();
Map
<
String
,
Object
>
dataMap
=
new
HashMap
<>();
LogUserInfo
userInfo
=
authLog
.
getLogUserInfo
();
if
(
userInfo
!=
null
){
dataMap
.
put
(
"userId"
,
userInfo
.
getUserId
());
dataMap
.
put
(
"userName"
,
userInfo
.
getRealName
());
}
dataMap
.
put
(
"clientId"
,
authLog
.
getClientId
());
dataMap
.
put
(
"forwardUrl"
,
authLog
.
getFowardUrl
());
dataMap
.
put
(
"user-agent"
,
holder
.
getRequestUserAgent
());
dataMap
.
put
(
"remote-address"
,
holder
.
getRequestRemoteAddress
());
dataMap
.
put
(
"referer"
,
holder
.
getRequestReferer
());
dataMap
.
put
(
"ip"
,
holder
.
getIpAddress
());
dataMap
.
put
(
"request"
,
holder
.
getRequestMethod
()
+
" "
+
holder
.
getRequestContextPath
());
dataMap
.
put
(
"timestamp"
,
System
.
currentTimeMillis
());
BusinessLogUtils
.
info
(
JSON
.
toJSONString
(
dataMap
));
}
@Override
@Override
public
Long
countLoginByParams
(
Map
<
String
,
Object
>
params
)
{
public
Long
countLoginByParams
(
Map
<
String
,
Object
>
params
)
{
return
authLogDao
.
countLoginByParams
(
params
);
return
authLogDao
.
countLoginByParams
(
params
);
...
@@ -57,11 +86,36 @@ public class AuthLogServiceImpl implements AuthLogService {
...
@@ -57,11 +86,36 @@ public class AuthLogServiceImpl implements AuthLogService {
return
result
;
return
result
;
}
}
@Override
public
List
<
String
>
distinct
(
String
key
,
Map
<
String
,
Object
>
prams
,
Date
beginTime
)
{
List
<
String
>
stringList
=
authLogDao
.
distinct
(
key
,
prams
,
beginTime
);
List
<
String
>
result
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
stringList
)){
stringList
.
forEach
(
item
->
{
if
(
null
!=
item
){
result
.
add
(
item
);
}
});
}
return
result
;
}
@Override
@Override
public
long
count
(
Map
<
String
,
Object
>
prams
)
{
public
long
count
(
Map
<
String
,
Object
>
prams
)
{
return
authLogDao
.
count
(
prams
);
return
authLogDao
.
count
(
prams
);
}
}
@Override
public
long
count
(
Map
<
String
,
Object
>
prams
,
Date
beginTime
)
{
return
authLogDao
.
count
(
prams
,
beginTime
);
}
@Override
public
long
count
(
Map
<
String
,
Object
>
params
,
List
<
String
>
notInBrowserList
,
Date
beginTime
)
{
return
authLogDao
.
count
(
params
,
notInBrowserList
,
beginTime
);
}
@Override
@Override
public
void
replace
(
AuthLog
authLog
)
{
public
void
replace
(
AuthLog
authLog
)
{
authLogDao
.
replace
(
authLog
);
authLogDao
.
replace
(
authLog
);
...
@@ -71,4 +125,9 @@ public class AuthLogServiceImpl implements AuthLogService {
...
@@ -71,4 +125,9 @@ public class AuthLogServiceImpl implements AuthLogService {
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
)
{
public
List
<
AuthLog
>
listLogWithPage
(
int
pageNo
,
int
pageSize
,
Map
<
String
,
Object
>
prams
)
{
return
authLogDao
.
listLogWithPage
(
pageNo
,
pageSize
,
prams
);
return
authLogDao
.
listLogWithPage
(
pageNo
,
pageSize
,
prams
);
}
}
@Override
public
List
<
AuthLogHourCount
>
hourMaxCount
(
Map
<
String
,
Object
>
matchParams
,
Date
beginTime
,
int
topN
)
{
return
authLogDao
.
hourMaxCount
(
matchParams
,
beginTime
,
topN
);
}
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/util/BusinessLogUtils.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
util
;
import
cn.sh.chineseall.framework.core.util.MapUtils
;
import
cn.sh.chineseall.framework.core.util.StringUtils
;
import
com.alibaba.fastjson.JSON
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Map
;
public
class
BusinessLogUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BusinessLogUtils
.
class
);
public
static
void
info
(
Map
<
String
,
String
[]>
data
){
if
(
MapUtils
.
isEmpty
(
data
)){
return
;
}
logger
.
info
(
JSON
.
toJSONString
(
data
));
}
public
static
void
info
(
String
jsonData
){
if
(
StringUtils
.
isBlank
(
jsonData
)){
return
;
}
logger
.
info
(
jsonData
);
}
}
eden-authcenter-log/src/main/java/com/chineseall/eden/authcenter/log/util/RequestResponseHolder.java
0 → 100644
View file @
74b4b318
package
com
.
chineseall
.
eden
.
authcenter
.
log
.
util
;
import
cn.sh.chineseall.framework.core.repackaged.org.apache.commons.lang3.StringUtils
;
import
lombok.Getter
;
import
lombok.Setter
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Map
;
@Getter
@Setter
public
class
RequestResponseHolder
{
public
static
final
ThreadLocal
<
RequestResponseHolder
>
requestResponseLocal
=
new
ThreadLocal
<>();
private
HttpServletRequest
request
;
private
HttpServletResponse
response
;
public
Map
<
String
,
String
>
getRequestHeaderMap
(){
Map
<
String
,
String
>
requestHeaderMap
=
new
HashMap
<>();
Enumeration
<
String
>
headerNames
=
getRequest
().
getHeaderNames
();
while
(
headerNames
.
hasMoreElements
()){
String
headerName
=
headerNames
.
nextElement
();
String
value
=
getRequest
().
getHeader
(
headerName
);
requestHeaderMap
.
put
(
headerName
,
value
);
}
return
requestHeaderMap
;
}
public
String
getRequestUserAgent
(){
Map
<
String
,
String
>
headerMap
=
getRequestHeaderMap
();
return
headerMap
.
get
(
"user-agent"
);
}
public
String
getRequestRemoteAddress
(){
return
getRequest
().
getRemoteAddr
();
}
public
String
getRequestReferer
(){
Map
<
String
,
String
>
headerMap
=
getRequestHeaderMap
();
return
headerMap
.
get
(
"referer"
);
}
public
String
getRequestMethod
(){
return
getRequest
().
getMethod
();
}
public
String
getRequestContextPath
(){
return
getRequest
().
getContextPath
();
}
public
String
getIpAddress
()
{
Map
<
String
,
String
>
headerMap
=
getRequestHeaderMap
();
String
Xip
=
headerMap
.
get
(
"X-Real-IP"
);
String
XFor
=
headerMap
.
get
(
"X-Forwarded-For"
);
if
(
StringUtils
.
isNotEmpty
(
XFor
)
&&
!
"unKnown"
.
equalsIgnoreCase
(
XFor
)){
//多次反向代理后会有多个ip值,第一个ip才是真实ip
int
index
=
XFor
.
indexOf
(
","
);
if
(
index
!=
-
1
){
return
XFor
.
substring
(
0
,
index
);
}
else
{
return
XFor
;
}
}
XFor
=
Xip
;
if
(
StringUtils
.
isNotEmpty
(
XFor
)
&&
!
"unKnown"
.
equalsIgnoreCase
(
XFor
)){
return
XFor
;
}
if
(
StringUtils
.
isBlank
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
StringUtils
.
isBlank
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
StringUtils
.
isBlank
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getHeader
(
"HTTP_CLIENT_IP"
);
}
if
(
StringUtils
.
isBlank
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getHeader
(
"HTTP_X_FORWARDED_FOR"
);
}
if
(
StringUtils
.
isBlank
(
XFor
)
||
"unknown"
.
equalsIgnoreCase
(
XFor
))
{
XFor
=
request
.
getRemoteAddr
();
}
return
XFor
;
}
public
static
void
set
(
HttpServletRequest
request
,
HttpServletResponse
response
){
RequestResponseHolder
holder
=
new
RequestResponseHolder
();
holder
.
setRequest
(
request
);
holder
.
setResponse
(
response
);
requestResponseLocal
.
set
(
holder
);
}
public
static
RequestResponseHolder
get
(){
return
requestResponseLocal
.
get
();
}
public
static
void
remove
(){
requestResponseLocal
.
remove
();
}
}
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