Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-backend
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
cloud-backend
Commits
bd8ef4fc
Commit
bd8ef4fc
authored
Jul 10, 2023
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加安全验证
parent
eeade8ae
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
87 additions
and
39 deletions
+87
-39
admin-server/src/main/java/com/zq/admin/modules/security/rest/AuthorizationController.java
+8
-0
admin-server/src/main/resources/bootstrap.yml
+9
-4
api-server/src/main/resources/bootstrap.yml
+8
-4
config-server/pom.xml
+5
-0
config-server/src/main/resources/application.yml
+10
-4
eureka-server/src/main/resources/application.yml
+12
-9
file-server/src/main/resources/bootstrap.yml
+9
-4
gateway-server/src/main/resources/bootstrap.yml
+9
-4
pom.xml
+3
-3
user-server/src/main/java/com/zq/user/config/TokenFilter.java
+4
-1
user-server/src/main/java/com/zq/user/controller/admin/UserAdminController.java
+1
-2
user-server/src/main/resources/bootstrap.yml
+9
-4
No files found.
admin-server/src/main/java/com/zq/admin/modules/security/rest/AuthorizationController.java
View file @
bd8ef4fc
...
@@ -32,6 +32,8 @@ import com.zq.common.annotation.rest.AnonymousGetMapping;
...
@@ -32,6 +32,8 @@ import com.zq.common.annotation.rest.AnonymousGetMapping;
import
com.zq.common.annotation.rest.AnonymousPostMapping
;
import
com.zq.common.annotation.rest.AnonymousPostMapping
;
import
com.zq.common.config.redis.RedisUtils
;
import
com.zq.common.config.redis.RedisUtils
;
import
com.zq.common.config.security.SecurityProperties
;
import
com.zq.common.config.security.SecurityProperties
;
import
com.zq.common.context.ContextUtils
;
import
com.zq.common.vo.OnlineUserDto
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.common.vo.ResultVo
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
...
@@ -124,6 +126,12 @@ public class AuthorizationController {
...
@@ -124,6 +126,12 @@ public class AuthorizationController {
return
ResponseEntity
.
ok
(
SecurityUtils
.
getCurrentUser
());
return
ResponseEntity
.
ok
(
SecurityUtils
.
getCurrentUser
());
}
}
@ApiOperation
(
"获取当前用户"
)
@GetMapping
(
value
=
"/getCurrentUser"
)
public
ResultVo
<
OnlineUserDto
>
getCurrentUser
()
{
return
ResultVo
.
success
(
ContextUtils
.
getAdminContext
());
}
@ApiOperation
(
"获取验证码"
)
@ApiOperation
(
"获取验证码"
)
@AnonymousGetMapping
(
value
=
"/code"
)
@AnonymousGetMapping
(
value
=
"/code"
)
public
ResponseEntity
<
Object
>
getCode
()
{
public
ResponseEntity
<
Object
>
getCode
()
{
...
...
admin-server/src/main/resources/bootstrap.yml
View file @
bd8ef4fc
...
@@ -8,13 +8,18 @@ spring:
...
@@ -8,13 +8,18 @@ spring:
discovery
:
discovery
:
enabled
:
true
enabled
:
true
service-id
:
CONFIG-SERVER
service-id
:
CONFIG-SERVER
username
:
admin
password
:
123456
eureka
:
eureka
:
instance
:
instance
:
prefer-ip-address
:
true
prefer-ip-address
:
true
lease-renewal-interval-in-seconds
:
2
#每间隔1s,向服务端发送一次心跳,证明自己依然"存活"
lease-renewal-interval-in-seconds
:
5
#向服务端发送心跳间隔
lease-expiration-duration-in-seconds
:
6
#告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,
将我踢出掉。
lease-expiration-duration-in-seconds
:
15
#告诉服务端多少秒没收到心跳
将我踢出掉。
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client
:
client
:
service-url
:
# 客户端拉取readOnly缓存的时间间隔,默认是30s
defaultZone
:
@
eureka.server.url@
registry-fetch-interval-seconds
:
3
# 拉取注册表信息间隔时间
serviceUrl
:
defaultZone
:
@
register.url@
api-server/src/main/resources/bootstrap.yml
View file @
bd8ef4fc
...
@@ -8,16 +8,20 @@ spring:
...
@@ -8,16 +8,20 @@ spring:
discovery
:
discovery
:
enabled
:
true
enabled
:
true
service-id
:
CONFIG-SERVER
service-id
:
CONFIG-SERVER
username
:
admin
password
:
123456
eureka
:
eureka
:
instance
:
instance
:
prefer-ip-address
:
true
prefer-ip-address
:
true
lease-renewal-interval-in-seconds
:
2
#每间隔1s,向服务端发送一次心跳,证明自己依然"存活"
lease-renewal-interval-in-seconds
:
5
#向服务端发送心跳间隔
lease-expiration-duration-in-seconds
:
6
#告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,
将我踢出掉。
lease-expiration-duration-in-seconds
:
15
#告诉服务端多少秒没收到心跳
将我踢出掉。
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client
:
client
:
service-url
:
# 客户端拉取readOnly缓存的时间间隔,默认是30s
defaultZone
:
@
eureka.server.url@
registry-fetch-interval-seconds
:
3
# 拉取注册表信息间隔时间
serviceUrl
:
defaultZone
:
@
register.url@
feign
:
feign
:
client
:
client
:
...
...
config-server/pom.xml
View file @
bd8ef4fc
...
@@ -20,6 +20,11 @@
...
@@ -20,6 +20,11 @@
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-config-server
</artifactId>
<artifactId>
spring-cloud-config-server
</artifactId>
</dependency>
</dependency>
<!--Spring boot 安全框架-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
config-server/src/main/resources/application.yml
View file @
bd8ef4fc
...
@@ -5,6 +5,10 @@ spring:
...
@@ -5,6 +5,10 @@ spring:
name
:
CONFIG-SERVER
name
:
CONFIG-SERVER
profiles
:
profiles
:
active
:
native
# 配置使用本地储存
active
:
native
# 配置使用本地储存
security
:
user
:
name
:
admin
password
:
123456
cloud
:
cloud
:
config
:
config
:
server
:
server
:
...
@@ -18,12 +22,14 @@ spring:
...
@@ -18,12 +22,14 @@ spring:
eureka
:
eureka
:
instance
:
instance
:
prefer-ip-address
:
true
prefer-ip-address
:
true
lease-renewal-interval-in-seconds
:
2
#每间隔1s,向服务端发送一次心跳,证明自己依然"存活"
lease-renewal-interval-in-seconds
:
5
#向服务端发送心跳间隔
lease-expiration-duration-in-seconds
:
6
#告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,
将我踢出掉。
lease-expiration-duration-in-seconds
:
15
#告诉服务端多少秒没收到心跳
将我踢出掉。
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client
:
client
:
service-url
:
# 客户端拉取readOnly缓存的时间间隔,默认是30s
defaultZone
:
@
eureka.server.url@
registry-fetch-interval-seconds
:
3
# 拉取注册表信息间隔时间
serviceUrl
:
defaultZone
:
@
register.url@
management
:
management
:
endpoints
:
endpoints
:
...
...
eureka-server/src/main/resources/application.yml
View file @
bd8ef4fc
...
@@ -8,20 +8,24 @@ spring:
...
@@ -8,20 +8,24 @@ spring:
name
:
admin
name
:
admin
password
:
123456
password
:
123456
eureka
:
eureka
:
instance
:
#设置使用IP注册就会优先使用IP,hostname则无效
prefer-ip-address
:
true
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
server
:
server
:
# 关闭自我保护机制(程序停掉了还注册的问题)
# 关闭自我保护机制(程序停掉了还注册的问题)
enable-self-preservation
:
false
enable-self-preservation
:
false
# 主动失效检测间隔,配置成5秒
# 主动检测失效间隔,配置成3秒,默认60000
eviction-interval-timer-in-ms
:
2000
eviction-interval-timer-in-ms
:
3000
# 禁用readOnlyCacheMap
# 禁用use-read-only-response-cache只读缓存或者减少response-cache-update-interval-ms更新缓存的时间间隔都可以更快的同步实例信息
use-read-only-response-cache
:
false
# use-read-only-response-cache: false
# 减少readWrite 和 readOnly 同步时间间隔。
response-cache-update-interval-ms
:
3000
client
:
client
:
# 客户端拉取readOnly缓存的时间间隔,默认是30s
registry-fetch-interval-seconds
:
10
# 表示是否将自己注册到Eureka Server,默认为true。
# 表示是否将自己注册到Eureka Server,默认为true。
register-with-eureka
:
false
register-with-eureka
:
false
# 表示是否从Eureka Server获取注册信息,默认为true。
# 表示是否从Eureka Server获取注册信息,默认为true。
fetch-registry
:
false
fetch-registry
:
false
# 设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是http://
localhost:8761/eureka/
;多个地址可使用,分隔
# 设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是http://
127.0.0.1:8000/eureka
;多个地址可使用,分隔
service-url
:
service-url
:
defaultZone
:
http://${spring.security.user.name}:${spring.security.user.password}@${spring.cloud.client.ip-address}:${server.port}/eureka/
defaultZone
:
http://admin:GXfy2021@127.0.0.1:8800/eureka/
\ No newline at end of file
file-server/src/main/resources/bootstrap.yml
View file @
bd8ef4fc
...
@@ -8,13 +8,18 @@ spring:
...
@@ -8,13 +8,18 @@ spring:
discovery
:
discovery
:
enabled
:
true
enabled
:
true
service-id
:
CONFIG-SERVER
service-id
:
CONFIG-SERVER
username
:
admin
password
:
123456
eureka
:
eureka
:
instance
:
instance
:
prefer-ip-address
:
true
prefer-ip-address
:
true
lease-renewal-interval-in-seconds
:
2
#每间隔1s,向服务端发送一次心跳,证明自己依然"存活"
lease-renewal-interval-in-seconds
:
5
#向服务端发送心跳间隔
lease-expiration-duration-in-seconds
:
6
#告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,
将我踢出掉。
lease-expiration-duration-in-seconds
:
15
#告诉服务端多少秒没收到心跳
将我踢出掉。
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client
:
client
:
service-url
:
# 客户端拉取readOnly缓存的时间间隔,默认是30s
defaultZone
:
@
eureka.server.url@
registry-fetch-interval-seconds
:
3
# 拉取注册表信息间隔时间
serviceUrl
:
defaultZone
:
@
register.url@
gateway-server/src/main/resources/bootstrap.yml
View file @
bd8ef4fc
...
@@ -8,13 +8,18 @@ spring:
...
@@ -8,13 +8,18 @@ spring:
discovery
:
discovery
:
enabled
:
true
enabled
:
true
service-id
:
CONFIG-SERVER
service-id
:
CONFIG-SERVER
username
:
admin
password
:
123456
eureka
:
eureka
:
instance
:
instance
:
prefer-ip-address
:
true
prefer-ip-address
:
true
lease-renewal-interval-in-seconds
:
2
#每间隔1s,向服务端发送一次心跳,证明自己依然"存活"
lease-renewal-interval-in-seconds
:
5
#向服务端发送心跳间隔
lease-expiration-duration-in-seconds
:
6
#告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,
将我踢出掉。
lease-expiration-duration-in-seconds
:
15
#告诉服务端多少秒没收到心跳
将我踢出掉。
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client
:
client
:
service-url
:
# 客户端拉取readOnly缓存的时间间隔,默认是30s
defaultZone
:
@
eureka.server.url@
registry-fetch-interval-seconds
:
3
# 拉取注册表信息间隔时间
serviceUrl
:
defaultZone
:
@
register.url@
pom.xml
View file @
bd8ef4fc
...
@@ -98,7 +98,7 @@
...
@@ -98,7 +98,7 @@
<properties>
<properties>
<profiles.active>
dev
</profiles.active>
<profiles.active>
dev
</profiles.active>
<logging.level>
debug
</logging.level>
<logging.level>
debug
</logging.level>
<
eureka.server.url>
http://admin:123456@127.0.0.1:8800/eureka/
</eureka.serv
er.url>
<
register.url>
http://admin:123456@127.0.0.1:8800/eureka/
</regist
er.url>
</properties>
</properties>
<activation>
<activation>
<activeByDefault>
true
</activeByDefault>
<activeByDefault>
true
</activeByDefault>
...
@@ -110,7 +110,7 @@
...
@@ -110,7 +110,7 @@
<properties>
<properties>
<profiles.active>
test
</profiles.active>
<profiles.active>
test
</profiles.active>
<logging.level>
debug
</logging.level>
<logging.level>
debug
</logging.level>
<
eureka.server.url>
http://admin:123456@127.0.0.1:8800/eureka/
</eureka.serv
er.url>
<
register.url>
http://admin:123456@127.0.0.1:8800/eureka/
</regist
er.url>
</properties>
</properties>
</profile>
</profile>
<profile>
<profile>
...
@@ -119,7 +119,7 @@
...
@@ -119,7 +119,7 @@
<properties>
<properties>
<profiles.active>
product
</profiles.active>
<profiles.active>
product
</profiles.active>
<logging.level>
info
</logging.level>
<logging.level>
info
</logging.level>
<
eureka.server.url>
http://admin:123456@127.0.0.1:8800/eureka/
</eureka.serv
er.url>
<
register.url>
http://admin:123456@127.0.0.1:8800/eureka/
</regist
er.url>
</properties>
</properties>
</profile>
</profile>
</profiles>
</profiles>
...
...
user-server/src/main/java/com/zq/user/config/TokenFilter.java
View file @
bd8ef4fc
...
@@ -65,7 +65,10 @@ public class TokenFilter extends GenericFilterBean {
...
@@ -65,7 +65,10 @@ public class TokenFilter extends GenericFilterBean {
ResultVo
<
OnlineUserDto
>
resultVo
=
adminFeignClient
.
getCurrentUser
();
ResultVo
<
OnlineUserDto
>
resultVo
=
adminFeignClient
.
getCurrentUser
();
onlineUserDto
=
resultVo
.
getData
();
onlineUserDto
=
resultVo
.
getData
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
">> 获取当前用户失败:"
+
e
.
getMessage
());
String
requestUri
=
httpServletRequest
.
getRequestURI
();
if
(!
"/error"
.
equals
(
requestUri
))
{
log
.
error
(
">> 获取当前用户失败:[{}] {}"
,
requestUri
,
e
.
getMessage
());
}
}
}
if
(
onlineUserDto
!=
null
&&
StringUtils
.
isNotBlank
(
token
))
{
if
(
onlineUserDto
!=
null
&&
StringUtils
.
isNotBlank
(
token
))
{
Authentication
authentication
=
tokenProvider
.
getAuthentication
(
token
);
Authentication
authentication
=
tokenProvider
.
getAuthentication
(
token
);
...
...
user-server/src/main/java/com/zq/user/controller/admin/UserAdminController.java
View file @
bd8ef4fc
package
com
.
zq
.
user
.
controller
.
admin
;
package
com
.
zq
.
user
.
controller
.
admin
;
import
com.zq.common.annotation.AnonymousAccess
;
import
com.zq.common.vo.PageVo
;
import
com.zq.common.vo.PageVo
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.logging.annotation.Log
;
import
com.zq.logging.annotation.Log
;
...
@@ -28,7 +27,7 @@ public class UserAdminController {
...
@@ -28,7 +27,7 @@ public class UserAdminController {
private
final
UserService
userService
;
private
final
UserService
userService
;
@Log
(
"获取用户列表"
)
@Log
(
"获取用户列表"
)
@AnonymousAccess
//
@AnonymousAccess
@ApiOperation
(
"获取用户列表"
)
@ApiOperation
(
"获取用户列表"
)
@PostMapping
(
value
=
"/getUserList"
)
@PostMapping
(
value
=
"/getUserList"
)
public
ResultVo
<
PageVo
<
AppUser
>>
getUserList
(
@RequestBody
FindAppUserVo
vo
)
{
public
ResultVo
<
PageVo
<
AppUser
>>
getUserList
(
@RequestBody
FindAppUserVo
vo
)
{
...
...
user-server/src/main/resources/bootstrap.yml
View file @
bd8ef4fc
...
@@ -8,13 +8,18 @@ spring:
...
@@ -8,13 +8,18 @@ spring:
discovery
:
discovery
:
enabled
:
true
enabled
:
true
service-id
:
CONFIG-SERVER
service-id
:
CONFIG-SERVER
username
:
admin
password
:
123456
eureka
:
eureka
:
instance
:
instance
:
prefer-ip-address
:
true
prefer-ip-address
:
true
lease-renewal-interval-in-seconds
:
2
#每间隔1s,向服务端发送一次心跳,证明自己依然"存活"
lease-renewal-interval-in-seconds
:
5
#向服务端发送心跳间隔
lease-expiration-duration-in-seconds
:
6
#告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,
将我踢出掉。
lease-expiration-duration-in-seconds
:
15
#告诉服务端多少秒没收到心跳
将我踢出掉。
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
instance-id
:
${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client
:
client
:
service-url
:
# 客户端拉取readOnly缓存的时间间隔,默认是30s
defaultZone
:
@
eureka.server.url@
registry-fetch-interval-seconds
:
3
# 拉取注册表信息间隔时间
serviceUrl
:
defaultZone
:
@
register.url@
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