mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-01-27 04:01:56 +08:00
Compare commits
458 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd30f3d53a | ||
|
|
0c24d59a2c | ||
|
|
4557ca0ace | ||
|
|
18c0b3dec4 | ||
|
|
674b7a0b04 | ||
|
|
d511f1bd94 | ||
|
|
fa75346763 | ||
|
|
79b1717f9a | ||
|
|
6b4d03cb8d | ||
|
|
2d7fd84c57 | ||
|
|
d0a19e5b6f | ||
|
|
14db619b20 | ||
|
|
c166bb0a89 | ||
|
|
4a60f91994 | ||
|
|
d601b5781e | ||
|
|
8223a5dcc4 | ||
|
|
b40e5c19b2 | ||
|
|
5ebc354cfc | ||
|
|
ca5d3e3556 | ||
|
|
c44cf9b9f6 | ||
|
|
cde32b45c0 | ||
|
|
6274bfcd8c | ||
|
|
29fac802f3 | ||
|
|
37597a85d5 | ||
|
|
f46aa17c77 | ||
|
|
6c70291d0a | ||
|
|
14ff957bde | ||
|
|
34439a6532 | ||
|
|
db07f4a354 | ||
|
|
820ea549e3 | ||
|
|
2b42931486 | ||
|
|
9bf5dfdc5f | ||
|
|
a3f8d03611 | ||
|
|
b6f21f451d | ||
|
|
418b74b39d | ||
|
|
919190dedc | ||
|
|
81ccdc49ec | ||
|
|
b006fad9b6 | ||
|
|
74a02ca3dc | ||
|
|
efaaacabb0 | ||
|
|
3410150e28 | ||
|
|
054fd7546f | ||
|
|
1797831afc | ||
|
|
24be94be5e | ||
|
|
33ba42a759 | ||
|
|
1e7b9fb94c | ||
|
|
45e5133e97 | ||
|
|
7713948f5c | ||
|
|
b64507d64a | ||
|
|
b06db48891 | ||
|
|
43f1681f51 | ||
|
|
5c90f0bbb7 | ||
|
|
c1b223e3a7 | ||
|
|
0d7b23a44f | ||
|
|
f91f931c0b | ||
|
|
329e124db0 | ||
|
|
c64b5edf20 | ||
|
|
c049d29eee | ||
|
|
7804d0bd2f | ||
|
|
7901116744 | ||
|
|
eb5df8834b | ||
|
|
711aa763b9 | ||
|
|
3c7018b38a | ||
|
|
2a5091c6f4 | ||
|
|
b6222b9755 | ||
|
|
4db3e90872 | ||
|
|
19ac02fd70 | ||
|
|
9d094587b3 | ||
|
|
2bc2b08bc7 | ||
|
|
f64a5dd5ca | ||
|
|
9f21dbbc5c | ||
|
|
05ce7d92a9 | ||
|
|
2e17d9c084 | ||
|
|
82779f3c70 | ||
|
|
b1bc3ceb27 | ||
|
|
e2a7df4a2c | ||
|
|
2a452a00e0 | ||
|
|
4d4123243c | ||
|
|
2c1bdc9670 | ||
|
|
08885f65cd | ||
|
|
961825d25c | ||
|
|
337d1bab02 | ||
|
|
b6a71fe988 | ||
|
|
786df8e278 | ||
|
|
451d218f4b | ||
|
|
adcb6194c8 | ||
|
|
334f79efe4 | ||
|
|
73b38b143b | ||
|
|
ef541b220b | ||
|
|
173c0e384f | ||
|
|
360ccc7adc | ||
|
|
df760d3504 | ||
|
|
0beecf7ea1 | ||
|
|
aa2821a19d | ||
|
|
2288fa218e | ||
|
|
6adc583c38 | ||
|
|
52111e4bf9 | ||
|
|
68db4092ed | ||
|
|
acf8d9719f | ||
|
|
92e5d2a97a | ||
|
|
e165901506 | ||
|
|
3187b1c46e | ||
|
|
662dec2fe2 | ||
|
|
3901695a6f | ||
|
|
d0a5c25b5d | ||
|
|
9c5c6c6be7 | ||
|
|
d8da1b796c | ||
|
|
e2dfdb2236 | ||
|
|
a8eba6949e | ||
|
|
3e907e8da7 | ||
|
|
af1b557bc8 | ||
|
|
e6c3bd1ce5 | ||
|
|
046d25f35d | ||
|
|
d20d4ffa16 | ||
|
|
76f2273d0b | ||
|
|
dda78c95b7 | ||
|
|
ebbeb047be | ||
|
|
ebd7fd59d0 | ||
|
|
c20c2c221f | ||
|
|
ee33dbdc0e | ||
|
|
5d8d4fa530 | ||
|
|
2021028cad | ||
|
|
7fcb1b2e0a | ||
|
|
f4a2f909a7 | ||
|
|
328630fe5d | ||
|
|
f7ae7e29d1 | ||
|
|
e46ea3ebac | ||
|
|
d565fa4883 | ||
|
|
a627108dfe | ||
|
|
829451f05e | ||
|
|
cae41a8da2 | ||
|
|
a4099cf645 | ||
|
|
0a104689ed | ||
|
|
97d0226c78 | ||
|
|
3a04dda55d | ||
|
|
94310c4f3d | ||
|
|
39e7d8a84b | ||
|
|
e1037ac125 | ||
|
|
a10384c009 | ||
|
|
ab8215d1ce | ||
|
|
524982c7bd | ||
|
|
d6188aa009 | ||
|
|
7e8b08a58c | ||
|
|
14771f0ab4 | ||
|
|
97c0603269 | ||
|
|
a58c430858 | ||
|
|
cd4119b26a | ||
|
|
ea20fa3ce2 | ||
|
|
3b54208ac9 | ||
|
|
d2de744c3f | ||
|
|
655249d67a | ||
|
|
80a890549d | ||
|
|
5da1979ce6 | ||
|
|
642512aa91 | ||
|
|
4a32a8e725 | ||
|
|
bb30ae7086 | ||
|
|
34a6f2e1f1 | ||
|
|
0e51d1e7b1 | ||
|
|
40bdf7b100 | ||
|
|
57f51249b6 | ||
|
|
dcc5dc0d16 | ||
|
|
e87a818706 | ||
|
|
67df97d5a7 | ||
|
|
3f8fd0a0f8 | ||
|
|
961fe9a5f1 | ||
|
|
22f156bbb7 | ||
|
|
22c22c4246 | ||
|
|
994cd62c7a | ||
|
|
1e4ed04a65 | ||
|
|
139b25639e | ||
|
|
13800738cb | ||
|
|
98c538c9e3 | ||
|
|
0e7c45173c | ||
|
|
132b23dc33 | ||
|
|
c3f1dd846c | ||
|
|
7b7abde756 | ||
|
|
aeeb0eb26b | ||
|
|
265a181891 | ||
|
|
22663e1b43 | ||
|
|
24be1a436e | ||
|
|
370c53edfa | ||
|
|
f112133ddf | ||
|
|
93ee021b6e | ||
|
|
e57d2ea17c | ||
|
|
ea038a5437 | ||
|
|
329aa68644 | ||
|
|
887430874d | ||
|
|
52f8693e1d | ||
|
|
8057dcc4fc | ||
|
|
66e0f9a53d | ||
|
|
7a35c474d6 | ||
|
|
892065003d | ||
|
|
ede8353503 | ||
|
|
60796ca8fb | ||
|
|
25e9112ccc | ||
|
|
f6c5c91eb1 | ||
|
|
740da06972 | ||
|
|
2a363f9c17 | ||
|
|
3c649a8814 | ||
|
|
a144bf2bff | ||
|
|
83ee4223be | ||
|
|
8f6c864e96 | ||
|
|
12209ae5a4 | ||
|
|
4e0301a7b2 | ||
|
|
00fa1c3158 | ||
|
|
04edd66199 | ||
|
|
d8896c9054 | ||
|
|
dd70c1950e | ||
|
|
954d208ac6 | ||
|
|
98d25fa16e | ||
|
|
3af7af265b | ||
|
|
436c2154ad | ||
|
|
42e8baa85c | ||
|
|
0dff71bd4d | ||
|
|
20ce9da509 | ||
|
|
a044b0d205 | ||
|
|
698200ecc2 | ||
|
|
883d89ee0b | ||
|
|
fb9a480f3c | ||
|
|
e288710251 | ||
|
|
1019aa58ce | ||
|
|
e9621469b2 | ||
|
|
57c4910605 | ||
|
|
9920957796 | ||
|
|
e798f46876 | ||
|
|
caa7537607 | ||
|
|
8b23c97fdb | ||
|
|
af49ad54f6 | ||
|
|
816479e092 | ||
|
|
7e72849d05 | ||
|
|
99206a5d65 | ||
|
|
114c9f3af6 | ||
|
|
e14fb70c26 | ||
|
|
201149a131 | ||
|
|
2bc80c4c07 | ||
|
|
ee7607bcca | ||
|
|
7e2dbc5608 | ||
|
|
8eac239e48 | ||
|
|
6650397e38 | ||
|
|
1ca4c26d81 | ||
|
|
0b0da91139 | ||
|
|
3d47ec2e73 | ||
|
|
1f21102204 | ||
|
|
58b4600144 | ||
|
|
6146d63f2c | ||
|
|
dbf42739ca | ||
|
|
57f56c2769 | ||
|
|
5c130cfda6 | ||
|
|
df284ff6f5 | ||
|
|
1b7550f9a2 | ||
|
|
195df24b4b | ||
|
|
68de85aa5f | ||
|
|
8b6784d8e2 | ||
|
|
b73c14400c | ||
|
|
54922af7db | ||
|
|
23944b2f9c | ||
|
|
9d0240b831 | ||
|
|
1aef90d506 | ||
|
|
41b7e62b02 | ||
|
|
70a5e47b66 | ||
|
|
8722e184d6 | ||
|
|
819ad04e3e | ||
|
|
ab89a5efcc | ||
|
|
2fbb10bfd2 | ||
|
|
3fba7d5d92 | ||
|
|
d8d8758cfa | ||
|
|
5ba3e031f2 | ||
|
|
cc658b9ece | ||
|
|
1ed627798e | ||
|
|
bc4c7a02d3 | ||
|
|
17493a2a15 | ||
|
|
63d7e816ff | ||
|
|
fc7bd9a35d | ||
|
|
7ebcb4bf8a | ||
|
|
67feb9947e | ||
|
|
af479c7838 | ||
|
|
2f3949d732 | ||
|
|
79c8b17bee | ||
|
|
12d3e3d0d8 | ||
|
|
fc33d88334 | ||
|
|
09b49f46e8 | ||
|
|
379ea3f6bc | ||
|
|
84b975ac7f | ||
|
|
c7b6858433 | ||
|
|
33bae9509b | ||
|
|
d0cc511bbc | ||
|
|
d855fd67b4 | ||
|
|
7f802e8274 | ||
|
|
b48e6fb19a | ||
|
|
de4dd01d97 | ||
|
|
d04a93d75d | ||
|
|
fb8eac7064 | ||
|
|
f26c32881c | ||
|
|
2419815bc1 | ||
|
|
cb9fa33b5a | ||
|
|
eb69f8e614 | ||
|
|
1eb9581d36 | ||
|
|
7789620a15 | ||
|
|
c3ba1a092c | ||
|
|
3ef167e416 | ||
|
|
8e1a9a2433 | ||
|
|
cd73787dc7 | ||
|
|
1624a63cff | ||
|
|
db4a8b0e90 | ||
|
|
d989e4a717 | ||
|
|
a664602e28 | ||
|
|
f44b453d76 | ||
|
|
1298d02379 | ||
|
|
92a93f7cf8 | ||
|
|
94a6a5a7d9 | ||
|
|
2ca3f9b640 | ||
|
|
286bedaa40 | ||
|
|
edd1cfaf43 | ||
|
|
accd7ebc93 | ||
|
|
b7b755f0c6 | ||
|
|
87fcfe0c56 | ||
|
|
89a9188dd4 | ||
|
|
45b0e82432 | ||
|
|
5d3125463c | ||
|
|
1ab84cb0e5 | ||
|
|
e58c159225 | ||
|
|
2edb885ae5 | ||
|
|
b037ee9caf | ||
|
|
27d137a4ae | ||
|
|
25f94db9c5 | ||
|
|
457ec516f7 | ||
|
|
29cd58d3f4 | ||
|
|
262d06ea3a | ||
|
|
0f733b89dc | ||
|
|
265b680a61 | ||
|
|
2b7bb59d12 | ||
|
|
41fa57d778 | ||
|
|
6ad1df166b | ||
|
|
24e7ed38a5 | ||
|
|
fd0e9202d8 | ||
|
|
0922410a22 | ||
|
|
4edaa14e28 | ||
|
|
a2dede8448 | ||
|
|
dc83ba0356 | ||
|
|
60c815ab76 | ||
|
|
48cf4250b4 | ||
|
|
ede8456ea0 | ||
|
|
4dc51fae53 | ||
|
|
192f58e690 | ||
|
|
852b32eabb | ||
|
|
5e167eb6e1 | ||
|
|
31aefd15f7 | ||
|
|
716405d22b | ||
|
|
3c33fe21fa | ||
|
|
e1e05b761a | ||
|
|
1804d4fce6 | ||
|
|
0dcc955ced | ||
|
|
53076612f8 | ||
|
|
f0f2cde0f9 | ||
|
|
0546504cae | ||
|
|
17652c3a2f | ||
|
|
e96d12975f | ||
|
|
a9b51070ed | ||
|
|
a8c7b9102b | ||
|
|
ca04b583a9 | ||
|
|
99390fda05 | ||
|
|
be12108139 | ||
|
|
1dec234174 | ||
|
|
3fc684b346 | ||
|
|
12d8add3e4 | ||
|
|
372b77c662 | ||
|
|
5891960756 | ||
|
|
c5899bfbf0 | ||
|
|
4125f44179 | ||
|
|
09a0058379 | ||
|
|
3fdcac939a | ||
|
|
4cc4e8a8fa | ||
|
|
dee4653b9b | ||
|
|
2c610dc465 | ||
|
|
2c323ca3ff | ||
|
|
a95be9d418 | ||
|
|
a445462153 | ||
|
|
843f08984b | ||
|
|
2b3820223c | ||
|
|
a5d0028b39 | ||
|
|
449704180b | ||
|
|
8a18873b81 | ||
|
|
199228f6cb | ||
|
|
6d0b4f5d16 | ||
|
|
4cc0e2650c | ||
|
|
06074571f5 | ||
|
|
2698ea58d4 | ||
|
|
8c9eb7d6b6 | ||
|
|
79472708d9 | ||
|
|
586908b4d7 | ||
|
|
a7bac940a6 | ||
|
|
e100b0b940 | ||
|
|
161a6249e9 | ||
|
|
e4a6e5ef19 | ||
|
|
7ceb5c3c8f | ||
|
|
bfd33f2412 | ||
|
|
2ddf834552 | ||
|
|
743e59db7a | ||
|
|
88aff5d8a7 | ||
|
|
dbeded1c09 | ||
|
|
e4b8898d0d | ||
|
|
62d7ce5aa9 | ||
|
|
7fd4860ff2 | ||
|
|
ff979772fe | ||
|
|
dddbaeb5c0 | ||
|
|
3c5893074b | ||
|
|
2cde98a01b | ||
|
|
22a825718f | ||
|
|
a0bcaab926 | ||
|
|
1c023fbe7c | ||
|
|
81bf4d28ef | ||
|
|
963d2a0443 | ||
|
|
10de0df04e | ||
|
|
1066713524 | ||
|
|
bcdf270bb0 | ||
|
|
0673eab57e | ||
|
|
5094bba352 | ||
|
|
7523e0475f | ||
|
|
6beb5cadb2 | ||
|
|
5174536744 | ||
|
|
e526e33030 | ||
|
|
e8b19f863a | ||
|
|
91a2f7b16b | ||
|
|
3a9d45a7dd | ||
|
|
073d90ed17 | ||
|
|
689d5b1612 | ||
|
|
c615248ad6 | ||
|
|
20f85a37cf | ||
|
|
b199db3822 | ||
|
|
f5bf01159a | ||
|
|
2c05324108 | ||
|
|
6b36b32e39 | ||
|
|
1abf802a09 | ||
|
|
2bb0eb1edb | ||
|
|
1a12d56cc3 | ||
|
|
45e5395550 | ||
|
|
692cc84693 | ||
|
|
b812e01100 | ||
|
|
594329127f | ||
|
|
cdc813c453 | ||
|
|
3d7fe2a288 | ||
|
|
93920707b5 | ||
|
|
84ffdaefe2 | ||
|
|
0422f858f7 | ||
|
|
01c3019cea | ||
|
|
24fb0b712a | ||
|
|
8fdcd576c9 | ||
|
|
07df90f99b | ||
|
|
7bd762267b | ||
|
|
512c6acebc | ||
|
|
ad928ee719 | ||
|
|
04d8c97c62 | ||
|
|
9fc5d74f6e | ||
|
|
f245105b58 | ||
|
|
c0cc0bdf84 | ||
|
|
c04ea0221a | ||
|
|
d52f6673bc | ||
|
|
dce8ee4236 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
custom: http://doc.ruoyi.vip/ruoyi-cloud/other/donate.html
|
||||||
29
README.md
29
README.md
@@ -1,11 +1,26 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-b99b286755aef70355a7084753f89cdb7c9.png">
|
||||||
|
</p>
|
||||||
|
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi v3.4.0</h1>
|
||||||
|
<h4 align="center">基于 Vue/Element UI 和 Spring Boot/Spring Cloud & Alibaba 前后端分离的分布式微服务架构</h4>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Cloud/stargazers"><img src="https://gitee.com/y_project/RuoYi-Cloud/badge/star.svg?theme=dark"></a>
|
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Cloud"><img src="https://img.shields.io/badge/RuoYi-v3.4.0-brightgreen.svg"></a>
|
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Cloud/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
## 平台简介
|
## 平台简介
|
||||||
|
|
||||||
|
若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。
|
||||||
|
|
||||||
* 采用前后端分离的模式,微服务版本前端(基于 [RuoYi-Vue](https://gitee.com/y_project/RuoYi-Vue))。
|
* 采用前后端分离的模式,微服务版本前端(基于 [RuoYi-Vue](https://gitee.com/y_project/RuoYi-Vue))。
|
||||||
* 后端采用Spring Boot、Spring Cloud & Alibaba。
|
* 后端采用Spring Boot、Spring Cloud & Alibaba。
|
||||||
* 注册中心、配置中心选型Nacos,权限认证使用Redis。
|
* 注册中心、配置中心选型Nacos,权限认证使用Redis。
|
||||||
* 流量控制框架选型Sentinel。
|
* 流量控制框架选型Sentinel,分布式事务选型Seata。
|
||||||
|
* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Cloud-Vue3](https://github.com/yangzongzhuan/RuoYi-Cloud-Vue3),保持同步更新。
|
||||||
* 如需不分离应用,请移步 [RuoYi](https://gitee.com/y_project/RuoYi),如需分离应用,请移步 [RuoYi-Vue](https://gitee.com/y_project/RuoYi-Vue)
|
* 如需不分离应用,请移步 [RuoYi](https://gitee.com/y_project/RuoYi),如需分离应用,请移步 [RuoYi-Vue](https://gitee.com/y_project/RuoYi-Vue)
|
||||||
* 阿里云优惠券:[点我进入](https://www.aliyun.com/minisite/goods?userCode=brki8iof&share_source=copy_link),腾讯云优惠券:[点我领取](https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=198c8df2ed259157187173bc7f4f32fd&from=console)
|
* 阿里云折扣场:[点我进入](http://aly.ruoyi.vip),腾讯云秒杀场:[点我进入](http://txy.ruoyi.vip)
|
||||||
|
* 阿里云优惠券:[点我领取](https://www.aliyun.com/minisite/goods?userCode=brki8iof&share_source=copy_link),腾讯云优惠券:[点我领取](https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=198c8df2ed259157187173bc7f4f32fd&from=console)
|
||||||
|
|
||||||
#### 友情链接 [若依/RuoYi-Cloud](https://gitee.com/zhangmrit/ruoyi-cloud) Ant Design版本。
|
#### 友情链接 [若依/RuoYi-Cloud](https://gitee.com/zhangmrit/ruoyi-cloud) Ant Design版本。
|
||||||
|
|
||||||
@@ -21,6 +36,7 @@ com.ruoyi
|
|||||||
├── ruoyi-common // 通用模块
|
├── ruoyi-common // 通用模块
|
||||||
│ └── ruoyi-common-core // 核心模块
|
│ └── ruoyi-common-core // 核心模块
|
||||||
│ └── ruoyi-common-datascope // 权限范围
|
│ └── ruoyi-common-datascope // 权限范围
|
||||||
|
│ └── ruoyi-common-datasource // 多数据源
|
||||||
│ └── ruoyi-common-log // 日志记录
|
│ └── ruoyi-common-log // 日志记录
|
||||||
│ └── ruoyi-common-redis // 缓存服务
|
│ └── ruoyi-common-redis // 缓存服务
|
||||||
│ └── ruoyi-common-security // 安全模块
|
│ └── ruoyi-common-security // 安全模块
|
||||||
@@ -29,6 +45,7 @@ com.ruoyi
|
|||||||
│ └── ruoyi-system // 系统模块 [9201]
|
│ └── ruoyi-system // 系统模块 [9201]
|
||||||
│ └── ruoyi-gen // 代码生成 [9202]
|
│ └── ruoyi-gen // 代码生成 [9202]
|
||||||
│ └── ruoyi-job // 定时任务 [9203]
|
│ └── ruoyi-job // 定时任务 [9203]
|
||||||
|
│ └── ruoyi-file // 文件服务 [9300]
|
||||||
├── ruoyi-visual // 图形化管理模块
|
├── ruoyi-visual // 图形化管理模块
|
||||||
│ └── ruoyi-visual-monitor // 监控中心 [9100]
|
│ └── ruoyi-visual-monitor // 监控中心 [9100]
|
||||||
├──pom.xml // 公共依赖
|
├──pom.xml // 公共依赖
|
||||||
@@ -36,7 +53,7 @@ com.ruoyi
|
|||||||
|
|
||||||
## 架构图
|
## 架构图
|
||||||
|
|
||||||
<img src="https://oscimg.oschina.net/oscnet/up-aaa2d885b0fba37e52b56f0948edde1c4fe.png"/>
|
<img src="https://oscimg.oschina.net/oscnet/up-82e9722ecb846786405a904bafcf19f73f3.png"/>
|
||||||
|
|
||||||
## 内置功能
|
## 内置功能
|
||||||
|
|
||||||
@@ -102,12 +119,12 @@ com.ruoyi
|
|||||||
<td><img src="https://oscimg.oschina.net/oscnet/up-92ffb7f3835855cff100fa0f754a6be0d99.png"/></td>
|
<td><img src="https://oscimg.oschina.net/oscnet/up-92ffb7f3835855cff100fa0f754a6be0d99.png"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><img src="https://oscimg.oschina.net/oscnet/up-d69a19493e5aff7ecdd5d02410862bcea40.png"/></td>
|
<td><img src="https://oscimg.oschina.net/oscnet/up-ff9e3066561574aca73005c5730c6a41f15.png"/></td>
|
||||||
<td><img src="https://oscimg.oschina.net/oscnet/up-6d73c2140ce694e3de4c05035fdc1868d4c.png"/></td>
|
<td><img src="https://oscimg.oschina.net/oscnet/up-5e4daac0bb59612c5038448acbcef235e3a.png"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
## 若依微服务交流群
|
## 若依微服务交流群
|
||||||
|
|
||||||
QQ群: [](https://jq.qq.com/?_wv=1027&k=yqInfq0S) [](https://jq.qq.com/?_wv=1027&k=Oy1mb3p8) 点击按钮入群。
|
QQ群: [](https://jq.qq.com/?_wv=1027&k=yqInfq0S) [](https://jq.qq.com/?_wv=1027&k=Oy1mb3p8) [](https://jq.qq.com/?_wv=1027&k=rvxkJtXK) [](https://jq.qq.com/?_wv=1027&k=0Ck3PvTe) [](https://jq.qq.com/?_wv=1027&k=FnHHP4TT) [](https://jq.qq.com/?_wv=1027&k=qdT1Ojpz) 点击按钮入群。
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
@echo off
|
@echo off
|
||||||
echo.
|
echo.
|
||||||
echo [信息] 清理生成路径。
|
echo [信息] 清理工程target生成路径。
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
%~d0
|
%~d0
|
||||||
|
|||||||
14
bin/run-auth.bat
Normal file
14
bin/run-auth.bat
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
@echo off
|
||||||
|
echo.
|
||||||
|
echo [信息] 使用Jar命令运行Auth工程。
|
||||||
|
echo.
|
||||||
|
|
||||||
|
cd %~dp0
|
||||||
|
cd ../ruoyi-auth/target
|
||||||
|
|
||||||
|
set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
|
||||||
|
|
||||||
|
java -Dfile.encoding=utf-8 %JAVA_OPTS% -jar ruoyi-auth.jar
|
||||||
|
|
||||||
|
cd bin
|
||||||
|
pause
|
||||||
14
bin/run-gateway.bat
Normal file
14
bin/run-gateway.bat
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
@echo off
|
||||||
|
echo.
|
||||||
|
echo [信息] 使用Jar命令运行Gateway工程。
|
||||||
|
echo.
|
||||||
|
|
||||||
|
cd %~dp0
|
||||||
|
cd ../ruoyi-gateway/target
|
||||||
|
|
||||||
|
set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
|
||||||
|
|
||||||
|
java -Dfile.encoding=utf-8 %JAVA_OPTS% -jar ruoyi-gateway.jar
|
||||||
|
|
||||||
|
cd bin
|
||||||
|
pause
|
||||||
14
bin/run-modules-file.bat
Normal file
14
bin/run-modules-file.bat
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
@echo off
|
||||||
|
echo.
|
||||||
|
echo [信息] 使用Jar命令运行Modules-File工程。
|
||||||
|
echo.
|
||||||
|
|
||||||
|
cd %~dp0
|
||||||
|
cd ../ruoyi-modules/ruoyi-file/target
|
||||||
|
|
||||||
|
set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
|
||||||
|
|
||||||
|
java -Dfile.encoding=utf-8 %JAVA_OPTS% -jar ruoyi-modules-file.jar
|
||||||
|
|
||||||
|
cd bin
|
||||||
|
pause
|
||||||
14
bin/run-modules-gen.bat
Normal file
14
bin/run-modules-gen.bat
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
@echo off
|
||||||
|
echo.
|
||||||
|
echo [信息] 使用Jar命令运行Modules-Gen工程。
|
||||||
|
echo.
|
||||||
|
|
||||||
|
cd %~dp0
|
||||||
|
cd ../ruoyi-modules/ruoyi-gen/target
|
||||||
|
|
||||||
|
set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
|
||||||
|
|
||||||
|
java -Dfile.encoding=utf-8 %JAVA_OPTS% -jar ruoyi-modules-gen.jar
|
||||||
|
|
||||||
|
cd bin
|
||||||
|
pause
|
||||||
14
bin/run-modules-job.bat
Normal file
14
bin/run-modules-job.bat
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
@echo off
|
||||||
|
echo.
|
||||||
|
echo [信息] 使用Jar命令运行Modules-Job工程。
|
||||||
|
echo.
|
||||||
|
|
||||||
|
cd %~dp0
|
||||||
|
cd ../ruoyi-modules/ruoyi-job/target
|
||||||
|
|
||||||
|
set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
|
||||||
|
|
||||||
|
java -Dfile.encoding=utf-8 %JAVA_OPTS% -jar ruoyi-modules-job.jar
|
||||||
|
|
||||||
|
cd bin
|
||||||
|
pause
|
||||||
14
bin/run-modules-system.bat
Normal file
14
bin/run-modules-system.bat
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
@echo off
|
||||||
|
echo.
|
||||||
|
echo [信息] 使用Jar命令运行Modules-System工程。
|
||||||
|
echo.
|
||||||
|
|
||||||
|
cd %~dp0
|
||||||
|
cd ../ruoyi-modules/ruoyi-system/target
|
||||||
|
|
||||||
|
set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
|
||||||
|
|
||||||
|
java -Dfile.encoding=utf-8 %JAVA_OPTS% -jar ruoyi-modules-system.jar
|
||||||
|
|
||||||
|
cd bin
|
||||||
|
pause
|
||||||
14
bin/run-monitor.bat
Normal file
14
bin/run-monitor.bat
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
@echo off
|
||||||
|
echo.
|
||||||
|
echo [信息] 使用Jar命令运行Monitor工程。
|
||||||
|
echo.
|
||||||
|
|
||||||
|
cd %~dp0
|
||||||
|
cd ../ruoyi-visual/ruoyi-monitor/target
|
||||||
|
|
||||||
|
set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
|
||||||
|
|
||||||
|
java -Dfile.encoding=utf-8 %JAVA_OPTS% -jar ruoyi-visual-monitor.jar
|
||||||
|
|
||||||
|
cd bin
|
||||||
|
pause
|
||||||
41
docker/copy.sh
Normal file
41
docker/copy.sh
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# 复制项目的文件到对应docker路径,便于一键生成镜像。
|
||||||
|
usage() {
|
||||||
|
echo "Usage: sh copy.sh"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# copy sql
|
||||||
|
echo "begin copy sql "
|
||||||
|
cp ../sql/ry_20210908.sql ./mysql/db
|
||||||
|
cp ../sql/ry_config_20211118.sql ./mysql/db
|
||||||
|
|
||||||
|
# copy html
|
||||||
|
echo "begin copy html "
|
||||||
|
cp -r ../ruoyi-ui/dist/** ./nginx/html/dist
|
||||||
|
|
||||||
|
|
||||||
|
# copy jar
|
||||||
|
echo "begin copy ruoyi-gateway "
|
||||||
|
cp ../ruoyi-gateway/target/ruoyi-gateway.jar ./ruoyi/gateway/jar
|
||||||
|
|
||||||
|
echo "begin copy ruoyi-auth "
|
||||||
|
cp ../ruoyi-auth/target/ruoyi-auth.jar ./ruoyi/auth/jar
|
||||||
|
|
||||||
|
echo "begin copy ruoyi-visual "
|
||||||
|
cp ../ruoyi-visual/ruoyi-monitor/target/ruoyi-visual-monitor.jar ./ruoyi/visual/monitor/jar
|
||||||
|
|
||||||
|
echo "begin copy ruoyi-modules-system "
|
||||||
|
cp ../ruoyi-modules/ruoyi-system/target/ruoyi-modules-system.jar ./ruoyi/modules/system/jar
|
||||||
|
|
||||||
|
echo "begin copy ruoyi-modules-file "
|
||||||
|
cp ../ruoyi-modules/ruoyi-file/target/ruoyi-modules-file.jar ./ruoyi/modules/file/jar
|
||||||
|
|
||||||
|
echo "begin copy ruoyi-modules-job "
|
||||||
|
cp ../ruoyi-modules/ruoyi-job/target/ruoyi-modules-job.jar ./ruoyi/modules/job/jar
|
||||||
|
|
||||||
|
echo "begin copy ruoyi-modules-gen "
|
||||||
|
cp ../ruoyi-modules/ruoyi-gen/target/ruoyi-modules-gen.jar ./ruoyi/modules/gen/jar
|
||||||
|
|
||||||
67
docker/deploy.sh
Normal file
67
docker/deploy.sh
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# 使用说明,用来提示输入参数
|
||||||
|
usage() {
|
||||||
|
echo "Usage: sh 执行脚本.sh [port|base|modules|stop|rm]"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# 开启所需端口
|
||||||
|
port(){
|
||||||
|
firewall-cmd --add-port=80/tcp --permanent
|
||||||
|
firewall-cmd --add-port=8080/tcp --permanent
|
||||||
|
firewall-cmd --add-port=8848/tcp --permanent
|
||||||
|
firewall-cmd --add-port=9848/tcp --permanent
|
||||||
|
firewall-cmd --add-port=9849/tcp --permanent
|
||||||
|
firewall-cmd --add-port=6379/tcp --permanent
|
||||||
|
firewall-cmd --add-port=3306/tcp --permanent
|
||||||
|
firewall-cmd --add-port=9100/tcp --permanent
|
||||||
|
firewall-cmd --add-port=9200/tcp --permanent
|
||||||
|
firewall-cmd --add-port=9201/tcp --permanent
|
||||||
|
firewall-cmd --add-port=9202/tcp --permanent
|
||||||
|
firewall-cmd --add-port=9203/tcp --permanent
|
||||||
|
firewall-cmd --add-port=9300/tcp --permanent
|
||||||
|
service firewalld restart
|
||||||
|
}
|
||||||
|
|
||||||
|
# 启动基础环境(必须)
|
||||||
|
base(){
|
||||||
|
docker-compose up -d ruoyi-mysql ruoyi-redis ruoyi-nacos
|
||||||
|
}
|
||||||
|
|
||||||
|
# 启动程序模块(必须)
|
||||||
|
modules(){
|
||||||
|
docker-compose up -d ruoyi-nginx ruoyi-gateway ruoyi-auth ruoyi-modules-system
|
||||||
|
}
|
||||||
|
|
||||||
|
# 关闭所有环境/模块
|
||||||
|
stop(){
|
||||||
|
docker-compose stop
|
||||||
|
}
|
||||||
|
|
||||||
|
# 删除所有环境/模块
|
||||||
|
rm(){
|
||||||
|
docker-compose rm
|
||||||
|
}
|
||||||
|
|
||||||
|
# 根据输入参数,选择执行对应方法,不输入则执行使用说明
|
||||||
|
case "$1" in
|
||||||
|
"port")
|
||||||
|
port
|
||||||
|
;;
|
||||||
|
"base")
|
||||||
|
base
|
||||||
|
;;
|
||||||
|
"modules")
|
||||||
|
modules
|
||||||
|
;;
|
||||||
|
"stop")
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
"rm")
|
||||||
|
rm
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
140
docker/docker-compose.yml
Normal file
140
docker/docker-compose.yml
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
version : '3.8'
|
||||||
|
services:
|
||||||
|
ruoyi-nacos:
|
||||||
|
container_name: ruoyi-nacos
|
||||||
|
image: nacos/nacos-server
|
||||||
|
build:
|
||||||
|
context: ./nacos
|
||||||
|
environment:
|
||||||
|
- MODE=standalone
|
||||||
|
volumes:
|
||||||
|
- ./nacos/logs/:/home/nacos/logs
|
||||||
|
- ./nacos/conf/application.properties:/home/nacos/conf/application.properties
|
||||||
|
ports:
|
||||||
|
- "8848:8848"
|
||||||
|
- "9848:9848"
|
||||||
|
- "9849:9849"
|
||||||
|
depends_on:
|
||||||
|
- ruoyi-mysql
|
||||||
|
ruoyi-mysql:
|
||||||
|
container_name: ruoyi-mysql
|
||||||
|
image: mysql:5.7
|
||||||
|
build:
|
||||||
|
context: ./mysql
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
volumes:
|
||||||
|
- ./mysql/conf:/etc/mysql/conf.d
|
||||||
|
- ./mysql/logs:/logs
|
||||||
|
- ./mysql/data:/var/lib/mysql
|
||||||
|
command: [
|
||||||
|
'mysqld',
|
||||||
|
'--innodb-buffer-pool-size=80M',
|
||||||
|
'--character-set-server=utf8mb4',
|
||||||
|
'--collation-server=utf8mb4_unicode_ci',
|
||||||
|
'--default-time-zone=+8:00',
|
||||||
|
'--lower-case-table-names=1'
|
||||||
|
]
|
||||||
|
environment:
|
||||||
|
MYSQL_DATABASE: 'ry-cloud'
|
||||||
|
MYSQL_ROOT_PASSWORD: password
|
||||||
|
ruoyi-redis:
|
||||||
|
container_name: ruoyi-redis
|
||||||
|
image: redis
|
||||||
|
build:
|
||||||
|
context: ./redis
|
||||||
|
ports:
|
||||||
|
- "6379:6379"
|
||||||
|
volumes:
|
||||||
|
- ./redis/conf/redis.conf:/home/ruoyi/redis/redis.conf
|
||||||
|
- ./redis/data:/data
|
||||||
|
command: redis-server /home/ruoyi/redis/redis.conf
|
||||||
|
ruoyi-nginx:
|
||||||
|
container_name: ruoyi-nginx
|
||||||
|
image: nginx
|
||||||
|
build:
|
||||||
|
context: ./nginx
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
volumes:
|
||||||
|
- ./nginx/html/dist:/home/ruoyi/projects/ruoyi-ui
|
||||||
|
- ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
|
||||||
|
- ./nginx/logs:/var/log/nginx
|
||||||
|
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||||
|
depends_on:
|
||||||
|
- ruoyi-gateway
|
||||||
|
links:
|
||||||
|
- ruoyi-gateway
|
||||||
|
ruoyi-gateway:
|
||||||
|
container_name: ruoyi-gateway
|
||||||
|
build:
|
||||||
|
context: ./ruoyi/gateway
|
||||||
|
dockerfile: dockerfile
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
depends_on:
|
||||||
|
- ruoyi-redis
|
||||||
|
links:
|
||||||
|
- ruoyi-redis
|
||||||
|
ruoyi-auth:
|
||||||
|
container_name: ruoyi-auth
|
||||||
|
build:
|
||||||
|
context: ./ruoyi/auth
|
||||||
|
dockerfile: dockerfile
|
||||||
|
ports:
|
||||||
|
- "9200:9200"
|
||||||
|
depends_on:
|
||||||
|
- ruoyi-redis
|
||||||
|
links:
|
||||||
|
- ruoyi-redis
|
||||||
|
ruoyi-modules-system:
|
||||||
|
container_name: ruoyi-modules-system
|
||||||
|
build:
|
||||||
|
context: ./ruoyi/modules/system
|
||||||
|
dockerfile: dockerfile
|
||||||
|
ports:
|
||||||
|
- "9201:9201"
|
||||||
|
depends_on:
|
||||||
|
- ruoyi-redis
|
||||||
|
- ruoyi-mysql
|
||||||
|
links:
|
||||||
|
- ruoyi-redis
|
||||||
|
- ruoyi-mysql
|
||||||
|
ruoyi-modules-gen:
|
||||||
|
container_name: ruoyi-modules-gen
|
||||||
|
build:
|
||||||
|
context: ./ruoyi/modules/gen
|
||||||
|
dockerfile: dockerfile
|
||||||
|
ports:
|
||||||
|
- "9202:9202"
|
||||||
|
depends_on:
|
||||||
|
- ruoyi-mysql
|
||||||
|
links:
|
||||||
|
- ruoyi-mysql
|
||||||
|
ruoyi-modules-job:
|
||||||
|
container_name: ruoyi-modules-job
|
||||||
|
build:
|
||||||
|
context: ./ruoyi/modules/job
|
||||||
|
dockerfile: dockerfile
|
||||||
|
ports:
|
||||||
|
- "9203:9203"
|
||||||
|
depends_on:
|
||||||
|
- ruoyi-mysql
|
||||||
|
links:
|
||||||
|
- ruoyi-mysql
|
||||||
|
ruoyi-modules-file:
|
||||||
|
container_name: ruoyi-modules-file
|
||||||
|
build:
|
||||||
|
context: ./ruoyi/modules/file
|
||||||
|
dockerfile: dockerfile
|
||||||
|
ports:
|
||||||
|
- "9300:9300"
|
||||||
|
volumes:
|
||||||
|
- ./ruoyi/uploadPath:/home/ruoyi/uploadPath
|
||||||
|
ruoyi-visual-monitor:
|
||||||
|
container_name: ruoyi-visual-monitor
|
||||||
|
build:
|
||||||
|
context: ./ruoyi/visual/monitor
|
||||||
|
dockerfile: dockerfile
|
||||||
|
ports:
|
||||||
|
- "9100:9100"
|
||||||
1
docker/mysql/db/readme.txt
Normal file
1
docker/mysql/db/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放sql目录下的所有脚本,用于docker自动执行。
|
||||||
7
docker/mysql/dockerfile
Normal file
7
docker/mysql/dockerfile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM mysql:5.7
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 执行sql脚本
|
||||||
|
ADD ./db/*.sql /docker-entrypoint-initdb.d/
|
||||||
32
docker/nacos/conf/application.properties
Normal file
32
docker/nacos/conf/application.properties
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
spring.datasource.platform=mysql
|
||||||
|
db.num=1
|
||||||
|
db.url.0=jdbc:mysql://ruoyi-mysql:3306/ry-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
|
||||||
|
db.user=root
|
||||||
|
db.password=password
|
||||||
|
|
||||||
|
nacos.naming.empty-service.auto-clean=true
|
||||||
|
nacos.naming.empty-service.clean.initial-delay-ms=50000
|
||||||
|
nacos.naming.empty-service.clean.period-time-ms=30000
|
||||||
|
|
||||||
|
management.endpoints.web.exposure.include=*
|
||||||
|
|
||||||
|
management.metrics.export.elastic.enabled=false
|
||||||
|
management.metrics.export.influx.enabled=false
|
||||||
|
|
||||||
|
server.tomcat.accesslog.enabled=true
|
||||||
|
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
|
||||||
|
|
||||||
|
server.tomcat.basedir=
|
||||||
|
|
||||||
|
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
|
||||||
|
|
||||||
|
nacos.core.auth.system.type=nacos
|
||||||
|
nacos.core.auth.enabled=false
|
||||||
|
nacos.core.auth.default.token.expire.seconds=18000
|
||||||
|
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
|
||||||
|
nacos.core.auth.caching.enabled=true
|
||||||
|
nacos.core.auth.enable.userAgentAuthWhite=false
|
||||||
|
nacos.core.auth.server.identity.key=serverIdentity
|
||||||
|
nacos.core.auth.server.identity.value=security
|
||||||
|
|
||||||
|
nacos.istio.mcp.server.enabled=false
|
||||||
7
docker/nacos/dockerfile
Normal file
7
docker/nacos/dockerfile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM nacos/nacos-server
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 复制conf文件到路径
|
||||||
|
COPY ./conf/application.properties /home/nacos/conf/application.properties
|
||||||
36
docker/nginx/conf/nginx.conf
Normal file
36
docker/nginx/conf/nginx.conf
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
worker_processes 1;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
sendfile on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /home/ruoyi/projects/ruoyi-ui;
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
index index.html index.htm;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /prod-api/{
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header REMOTE-HOST $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_pass http://ruoyi-gateway:8080/;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}# requirepass 123456
|
||||||
15
docker/nginx/dockerfile
Normal file
15
docker/nginx/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM nginx
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi/projects/ruoyi-ui
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi/projects/ruoyi-ui
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi/projects/ruoyi-ui
|
||||||
|
# 复制conf文件到路径
|
||||||
|
COPY ./conf/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
# 复制html文件到路径
|
||||||
|
COPY ./html/dist /home/ruoyi/projects/ruoyi-ui
|
||||||
1
docker/nginx/html/dist/readme.txt
vendored
Normal file
1
docker/nginx/html/dist/readme.txt
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放前端ruoyi-ui构建好的静态文件,用于nginx请求访问。
|
||||||
1
docker/redis/conf/redis.conf
Normal file
1
docker/redis/conf/redis.conf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# requirepass 123456
|
||||||
13
docker/redis/dockerfile
Normal file
13
docker/redis/dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM redis
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi/redis
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi/redis
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi/redis
|
||||||
|
# 复制conf文件到路径
|
||||||
|
COPY ./conf/redis.conf /home/ruoyi/redis/redis.conf
|
||||||
15
docker/ruoyi/auth/dockerfile
Normal file
15
docker/ruoyi/auth/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM openjdk:8-jre
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi
|
||||||
|
# 复制jar文件到路径
|
||||||
|
COPY ./jar/ruoyi-auth.jar /home/ruoyi/ruoyi-auth.jar
|
||||||
|
# 启动认证服务
|
||||||
|
ENTRYPOINT ["java","-jar","ruoyi-auth.jar"]
|
||||||
1
docker/ruoyi/auth/jar/readme.txt
Normal file
1
docker/ruoyi/auth/jar/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放认证中心打包好的jar文件,用于docker启动应用。
|
||||||
15
docker/ruoyi/gateway/dockerfile
Normal file
15
docker/ruoyi/gateway/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM openjdk:8-jre
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi
|
||||||
|
# 复制jar文件到路径
|
||||||
|
COPY ./jar/ruoyi-gateway.jar /home/ruoyi/ruoyi-gateway.jar
|
||||||
|
# 启动网关服务
|
||||||
|
ENTRYPOINT ["java","-jar","ruoyi-gateway.jar"]
|
||||||
1
docker/ruoyi/gateway/jar/readme.txt
Normal file
1
docker/ruoyi/gateway/jar/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放网关模块打包好的jar文件,用于docker启动应用。
|
||||||
15
docker/ruoyi/modules/file/dockerfile
Normal file
15
docker/ruoyi/modules/file/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM openjdk:8-jre
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi
|
||||||
|
# 复制jar文件到路径
|
||||||
|
COPY ./jar/ruoyi-modules-file.jar /home/ruoyi/ruoyi-modules-file.jar
|
||||||
|
# 启动文件服务
|
||||||
|
ENTRYPOINT ["java","-jar","ruoyi-modules-file.jar"]
|
||||||
1
docker/ruoyi/modules/file/jar/readme.txt
Normal file
1
docker/ruoyi/modules/file/jar/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放文件服务打包好的jar文件,用于docker启动应用。
|
||||||
15
docker/ruoyi/modules/gen/dockerfile
Normal file
15
docker/ruoyi/modules/gen/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM openjdk:8-jre
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi
|
||||||
|
# 复制jar文件到路径
|
||||||
|
COPY ./jar/ruoyi-modules-gen.jar /home/ruoyi/ruoyi-modules-gen.jar
|
||||||
|
# 启动代码生成服务
|
||||||
|
ENTRYPOINT ["java","-jar","ruoyi-modules-gen.jar"]
|
||||||
1
docker/ruoyi/modules/gen/jar/readme.txt
Normal file
1
docker/ruoyi/modules/gen/jar/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放代码生成打包好的jar文件,用于docker启动应用。
|
||||||
15
docker/ruoyi/modules/job/dockerfile
Normal file
15
docker/ruoyi/modules/job/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM openjdk:8-jre
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi
|
||||||
|
# 复制jar文件到路径
|
||||||
|
COPY ./jar/ruoyi-modules-job.jar /home/ruoyi/ruoyi-modules-job.jar
|
||||||
|
# 启动定时任务服务
|
||||||
|
ENTRYPOINT ["java","-jar","ruoyi-modules-job.jar"]
|
||||||
1
docker/ruoyi/modules/job/jar/readme.txt
Normal file
1
docker/ruoyi/modules/job/jar/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放定时任务打包好的jar文件,用于docker启动应用。
|
||||||
15
docker/ruoyi/modules/system/dockerfile
Normal file
15
docker/ruoyi/modules/system/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM openjdk:8-jre
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi
|
||||||
|
# 复制jar文件到路径
|
||||||
|
COPY ./jar/ruoyi-modules-system.jar /home/ruoyi/ruoyi-modules-system.jar
|
||||||
|
# 启动系统服务
|
||||||
|
ENTRYPOINT ["java","-jar","ruoyi-modules-system.jar"]
|
||||||
1
docker/ruoyi/modules/system/jar/readme.txt
Normal file
1
docker/ruoyi/modules/system/jar/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放系统模块打包好的jar文件,用于docker启动应用。
|
||||||
15
docker/ruoyi/visual/monitor/dockerfile
Normal file
15
docker/ruoyi/visual/monitor/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 基础镜像
|
||||||
|
FROM openjdk:8-jre
|
||||||
|
# author
|
||||||
|
MAINTAINER ruoyi
|
||||||
|
|
||||||
|
# 挂载目录
|
||||||
|
VOLUME /home/ruoyi
|
||||||
|
# 创建目录
|
||||||
|
RUN mkdir -p /home/ruoyi
|
||||||
|
# 指定路径
|
||||||
|
WORKDIR /home/ruoyi
|
||||||
|
# 复制jar文件到路径
|
||||||
|
COPY ./jar/ruoyi-visual-monitor.jar /home/ruoyi/ruoyi-visual-monitor.jar
|
||||||
|
# 启动系统服务
|
||||||
|
ENTRYPOINT ["java","-jar","ruoyi-visual-monitor.jar"]
|
||||||
1
docker/ruoyi/visual/monitor/jar/readme.txt
Normal file
1
docker/ruoyi/visual/monitor/jar/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
存放监控中心打包好的jar文件,用于docker启动应用。
|
||||||
128
pom.xml
128
pom.xml
@@ -6,32 +6,39 @@
|
|||||||
|
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>3.4.0</version>
|
||||||
|
|
||||||
<name>ruoyi</name>
|
<name>ruoyi</name>
|
||||||
<url>http://www.ruoyi.vip</url>
|
<url>http://www.ruoyi.vip</url>
|
||||||
<description>若依微服务系统</description>
|
<description>若依微服务系统</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<ruoyi.version>2.2.0</ruoyi.version>
|
<ruoyi.version>3.4.0</ruoyi.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<spring-boot.version>2.3.4.RELEASE</spring-boot.version>
|
<spring-boot.version>2.6.3</spring-boot.version>
|
||||||
<spring-cloud.version>Hoxton.SR8</spring-cloud.version>
|
<spring-cloud.version>2021.0.0</spring-cloud.version>
|
||||||
<spring-cloud-alibaba.version>2.2.3.RELEASE</spring-cloud-alibaba.version>
|
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
|
||||||
<spring-boot-admin.version>2.3.0</spring-boot-admin.version>
|
<alibaba.nacos.version>2.0.4</alibaba.nacos.version>
|
||||||
<spring-boot.mybatis>2.1.2</spring-boot.mybatis>
|
<spring-boot-admin.version>2.6.2</spring-boot-admin.version>
|
||||||
<swagger.fox.version>2.9.2</swagger.fox.version>
|
<spring-boot.mybatis>2.2.0</spring-boot.mybatis>
|
||||||
<swagger.core.version>1.5.24</swagger.core.version>
|
<swagger.fox.version>3.0.0</swagger.fox.version>
|
||||||
|
<swagger.core.version>1.6.2</swagger.core.version>
|
||||||
|
<tobato.version>1.27.2</tobato.version>
|
||||||
<kaptcha.version>2.3.2</kaptcha.version>
|
<kaptcha.version>2.3.2</kaptcha.version>
|
||||||
<pagehelper.boot.version>1.2.12</pagehelper.boot.version>
|
<pagehelper.boot.version>1.4.1</pagehelper.boot.version>
|
||||||
<commons.io.version>2.5</commons.io.version>
|
<druid.version>1.2.8</druid.version>
|
||||||
<commons.fileupload.version>1.3.3</commons.fileupload.version>
|
<dynamic-ds.version>3.5.0</dynamic-ds.version>
|
||||||
<velocity.version>1.7</velocity.version>
|
<commons.io.version>2.11.0</commons.io.version>
|
||||||
<fastjson.version>1.2.73</fastjson.version>
|
<commons.fileupload.version>1.4</commons.fileupload.version>
|
||||||
<poi.version>3.17</poi.version>
|
<velocity.version>2.3</velocity.version>
|
||||||
<common-pool.version>2.6.2</common-pool.version>
|
<fastjson.version>1.2.79</fastjson.version>
|
||||||
|
<jjwt.version>0.9.1</jjwt.version>
|
||||||
|
<minio.version>8.2.2</minio.version>
|
||||||
|
<poi.version>4.1.2</poi.version>
|
||||||
|
<commons-collections.version>3.2.2</commons-collections.version>
|
||||||
|
<transmittable-thread-local.version>2.12.2</transmittable-thread-local.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- 依赖声明 -->
|
<!-- 依赖声明 -->
|
||||||
@@ -47,7 +54,7 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba 微服务 -->
|
<!-- SpringCloud Alibaba 微服务 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
@@ -56,6 +63,13 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Alibaba Nacos 配置 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
|
<artifactId>nacos-client</artifactId>
|
||||||
|
<version>${alibaba.nacos.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringBoot 依赖配置 -->
|
<!-- SpringBoot 依赖配置 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -64,21 +78,28 @@
|
|||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringBoot 监控客户端 -->
|
<!-- SpringBoot 监控客户端 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.codecentric</groupId>
|
<groupId>de.codecentric</groupId>
|
||||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
<artifactId>spring-boot-admin-starter-client</artifactId>
|
||||||
<version>${spring-boot-admin.version}</version>
|
<version>${spring-boot-admin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- FastDFS 分布式文件系统 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.tobato</groupId>
|
||||||
|
<artifactId>fastdfs-client</artifactId>
|
||||||
|
<version>${tobato.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Mybatis 依赖配置 -->
|
<!-- Mybatis 依赖配置 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
<version>${spring-boot.mybatis}</version>
|
<version>${spring-boot.mybatis}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger 依赖配置 -->
|
<!-- Swagger 依赖配置 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
@@ -129,88 +150,113 @@
|
|||||||
<!-- 代码生成使用模板 -->
|
<!-- 代码生成使用模板 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.velocity</groupId>
|
<groupId>org.apache.velocity</groupId>
|
||||||
<artifactId>velocity</artifactId>
|
<artifactId>velocity-engine-core</artifactId>
|
||||||
<version>${velocity.version}</version>
|
<version>${velocity.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Collection 增强Java集合框架 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-collections</groupId>
|
||||||
|
<artifactId>commons-collections</artifactId>
|
||||||
|
<version>${commons-collections.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- JSON 解析器和生成器 -->
|
<!-- JSON 解析器和生成器 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>${fastjson.version}</version>
|
<version>${fastjson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 公共资源池 -->
|
<!-- JWT -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
<artifactId>commons-pool2</artifactId>
|
<artifactId>jjwt</artifactId>
|
||||||
<version>${common-pool.version}</version>
|
<version>${jjwt.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 线程传递值 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>transmittable-thread-local</artifactId>
|
||||||
|
<version>${transmittable-thread-local.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 核心模块 -->
|
<!-- 核心模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-core</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 接口模块 -->
|
<!-- 接口模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-swagger</artifactId>
|
<artifactId>ruoyi-common-swagger</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 安全模块 -->
|
<!-- 安全模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-security</artifactId>
|
<artifactId>ruoyi-common-security</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 权限范围 -->
|
<!-- 权限范围 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-datascope</artifactId>
|
<artifactId>ruoyi-common-datascope</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 多数据源 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-datasource</artifactId>
|
||||||
|
<version>${ruoyi.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 日志记录 -->
|
<!-- 日志记录 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-log</artifactId>
|
<artifactId>ruoyi-common-log</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 缓存服务 -->
|
<!-- 缓存服务 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-redis</artifactId>
|
<artifactId>ruoyi-common-redis</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 系统接口 -->
|
<!-- 系统接口 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-api-system</artifactId>
|
<artifactId>ruoyi-api-system</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>ruoyi-auth</module>
|
<module>ruoyi-auth</module>
|
||||||
<module>ruoyi-gateway</module>
|
<module>ruoyi-gateway</module>
|
||||||
<module>ruoyi-visual</module>
|
<module>ruoyi-visual</module>
|
||||||
<module>ruoyi-modules</module>
|
<module>ruoyi-modules</module>
|
||||||
<module>ruoyi-api</module>
|
<module>ruoyi-api</module>
|
||||||
<module>ruoyi-common</module>
|
<module>ruoyi-common</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- bootstrap 启动器 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>3.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-api</artifactId>
|
<artifactId>ruoyi-api</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>3.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.ruoyi.system.api;
|
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestPart;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.system.api.domain.SysFile;
|
||||||
|
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件服务
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
|
||||||
|
public interface RemoteFileService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*
|
||||||
|
* @param file 文件信息
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);
|
||||||
|
}
|
||||||
@@ -3,9 +3,11 @@ package com.ruoyi.system.api;
|
|||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.system.api.domain.SysLogininfor;
|
||||||
import com.ruoyi.system.api.domain.SysOperLog;
|
import com.ruoyi.system.api.domain.SysOperLog;
|
||||||
import com.ruoyi.system.api.factory.RemoteLogFallbackFactory;
|
import com.ruoyi.system.api.factory.RemoteLogFallbackFactory;
|
||||||
|
|
||||||
@@ -21,20 +23,19 @@ public interface RemoteLogService
|
|||||||
* 保存系统日志
|
* 保存系统日志
|
||||||
*
|
*
|
||||||
* @param sysOperLog 日志实体
|
* @param sysOperLog 日志实体
|
||||||
|
* @param source 请求来源
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/operlog")
|
@PostMapping("/operlog")
|
||||||
R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog);
|
public R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存访问记录
|
* 保存访问记录
|
||||||
*
|
*
|
||||||
* @param username 用户名称
|
* @param sysLogininfor 访问实体
|
||||||
* @param status 状态
|
* @param source 请求来源
|
||||||
* @param message 消息
|
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/logininfor")
|
@PostMapping("/logininfor")
|
||||||
R<Boolean> saveLogininfor(@RequestParam("username") String username, @RequestParam("status") String status,
|
public R<Boolean> saveLogininfor(@RequestBody SysLogininfor sysLogininfor, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
@RequestParam("message") String message);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,13 @@ package com.ruoyi.system.api;
|
|||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.system.api.domain.SysUser;
|
||||||
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
|
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
import com.ruoyi.system.api.model.LoginUser;
|
||||||
|
|
||||||
@@ -20,8 +25,19 @@ public interface RemoteUserService
|
|||||||
* 通过用户名查询用户信息
|
* 通过用户名查询用户信息
|
||||||
*
|
*
|
||||||
* @param username 用户名
|
* @param username 用户名
|
||||||
|
* @param source 请求来源
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/user/info/{username}")
|
@GetMapping("/user/info/{username}")
|
||||||
public R<LoginUser> getUserInfo(@PathVariable("username") String username);
|
public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册用户信息
|
||||||
|
*
|
||||||
|
* @param sysUser 用户信息
|
||||||
|
* @param source 请求来源
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/user/register")
|
||||||
|
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.ruoyi.system.domain;
|
package com.ruoyi.system.api.domain;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.ruoyi.system.domain;
|
package com.ruoyi.system.api.domain;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.ruoyi.system.api.domain;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件信息
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class SysFile
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 文件名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件地址
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl()
|
||||||
|
{
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url)
|
||||||
|
{
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
.append("name", getName())
|
||||||
|
.append("url", getUrl())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.ruoyi.system.domain;
|
package com.ruoyi.system.api.domain;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
@@ -33,8 +33,8 @@ public class SysRole extends BaseEntity
|
|||||||
@Excel(name = "角色排序")
|
@Excel(name = "角色排序")
|
||||||
private String roleSort;
|
private String roleSort;
|
||||||
|
|
||||||
/** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限) */
|
/** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) */
|
||||||
@Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限")
|
@Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限")
|
||||||
private String dataScope;
|
private String dataScope;
|
||||||
|
|
||||||
/** 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) */
|
/** 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) */
|
||||||
@@ -203,7 +203,8 @@ public class SysRole extends BaseEntity
|
|||||||
{
|
{
|
||||||
this.deptIds = deptIds;
|
this.deptIds = deptIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
.append("roleId", getRoleId())
|
.append("roleId", getRoleId())
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package com.ruoyi.system.api.domain;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.*;
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
@@ -13,6 +11,7 @@ import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
|||||||
import com.ruoyi.common.core.annotation.Excel.Type;
|
import com.ruoyi.common.core.annotation.Excel.Type;
|
||||||
import com.ruoyi.common.core.annotation.Excels;
|
import com.ruoyi.common.core.annotation.Excels;
|
||||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||||
|
import com.ruoyi.common.core.xss.Xss;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户对象 sys_user
|
* 用户对象 sys_user
|
||||||
@@ -57,9 +56,6 @@ public class SysUser extends BaseEntity
|
|||||||
/** 密码 */
|
/** 密码 */
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
/** 盐加密 */
|
|
||||||
private String salt;
|
|
||||||
|
|
||||||
/** 帐号状态(0正常 1停用) */
|
/** 帐号状态(0正常 1停用) */
|
||||||
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
||||||
private String status;
|
private String status;
|
||||||
@@ -91,6 +87,9 @@ public class SysUser extends BaseEntity
|
|||||||
/** 岗位组 */
|
/** 岗位组 */
|
||||||
private Long[] postIds;
|
private Long[] postIds;
|
||||||
|
|
||||||
|
/** 角色ID */
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
public SysUser()
|
public SysUser()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -131,6 +130,7 @@ public class SysUser extends BaseEntity
|
|||||||
this.deptId = deptId;
|
this.deptId = deptId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Xss(message = "用户昵称不能包含脚本字符")
|
||||||
@Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
|
@Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
|
||||||
public String getNickName()
|
public String getNickName()
|
||||||
{
|
{
|
||||||
@@ -142,6 +142,7 @@ public class SysUser extends BaseEntity
|
|||||||
this.nickName = nickName;
|
this.nickName = nickName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Xss(message = "用户账号不能包含脚本字符")
|
||||||
@NotBlank(message = "用户账号不能为空")
|
@NotBlank(message = "用户账号不能为空")
|
||||||
@Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
|
@Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
|
||||||
public String getUserName()
|
public String getUserName()
|
||||||
@@ -208,16 +209,6 @@ public class SysUser extends BaseEntity
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSalt()
|
|
||||||
{
|
|
||||||
return salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSalt(String salt)
|
|
||||||
{
|
|
||||||
this.salt = salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatus()
|
public String getStatus()
|
||||||
{
|
{
|
||||||
return status;
|
return status;
|
||||||
@@ -297,7 +288,16 @@ public class SysUser extends BaseEntity
|
|||||||
{
|
{
|
||||||
this.postIds = postIds;
|
this.postIds = postIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getRoleId()
|
||||||
|
{
|
||||||
|
return roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleId(Long roleId)
|
||||||
|
{
|
||||||
|
this.roleId = roleId;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
@@ -310,7 +310,6 @@ public class SysUser extends BaseEntity
|
|||||||
.append("sex", getSex())
|
.append("sex", getSex())
|
||||||
.append("avatar", getAvatar())
|
.append("avatar", getAvatar())
|
||||||
.append("password", getPassword())
|
.append("password", getPassword())
|
||||||
.append("salt", getSalt())
|
|
||||||
.append("status", getStatus())
|
.append("status", getStatus())
|
||||||
.append("delFlag", getDelFlag())
|
.append("delFlag", getDelFlag())
|
||||||
.append("loginIp", getLoginIp())
|
.append("loginIp", getLoginIp())
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.ruoyi.system.api.factory;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.system.api.RemoteFileService;
|
||||||
|
import com.ruoyi.system.api.domain.SysFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件服务降级处理
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService>
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteFileService create(Throwable throwable)
|
||||||
|
{
|
||||||
|
log.error("文件服务调用失败:{}", throwable.getMessage());
|
||||||
|
return new RemoteFileService()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public R<SysFile> upload(MultipartFile file)
|
||||||
|
{
|
||||||
|
return R.fail("上传文件失败:" + throwable.getMessage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,11 +2,12 @@ package com.ruoyi.system.api.factory;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.system.api.RemoteLogService;
|
import com.ruoyi.system.api.RemoteLogService;
|
||||||
|
import com.ruoyi.system.api.domain.SysLogininfor;
|
||||||
import com.ruoyi.system.api.domain.SysOperLog;
|
import com.ruoyi.system.api.domain.SysOperLog;
|
||||||
import feign.hystrix.FallbackFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志服务降级处理
|
* 日志服务降级处理
|
||||||
@@ -25,13 +26,13 @@ public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogServic
|
|||||||
return new RemoteLogService()
|
return new RemoteLogService()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public R<Boolean> saveLog(SysOperLog sysOperLog)
|
public R<Boolean> saveLog(SysOperLog sysOperLog, String source)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R<Boolean> saveLogininfor(String username, String status, String message)
|
public R<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ package com.ruoyi.system.api.factory;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.system.api.RemoteUserService;
|
import com.ruoyi.system.api.RemoteUserService;
|
||||||
|
import com.ruoyi.system.api.domain.SysUser;
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
import com.ruoyi.system.api.model.LoginUser;
|
||||||
import feign.hystrix.FallbackFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户服务降级处理
|
* 用户服务降级处理
|
||||||
@@ -25,10 +26,16 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||||||
return new RemoteUserService()
|
return new RemoteUserService()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public R<LoginUser> getUserInfo(String username)
|
public R<LoginUser> getUserInfo(String username, String source)
|
||||||
{
|
{
|
||||||
return R.fail("获取用户失败:" + throwable.getMessage());
|
return R.fail("获取用户失败:" + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<Boolean> registerUserInfo(SysUser sysUser, String source)
|
||||||
|
{
|
||||||
|
return R.fail("注册用户失败:" + throwable.getMessage());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
com.ruoyi.system.api.factory.RemoteUserFallbackFactory,\
|
com.ruoyi.system.api.factory.RemoteUserFallbackFactory,\
|
||||||
com.ruoyi.system.api.factory.RemoteLogFallbackFactory
|
com.ruoyi.system.api.factory.RemoteLogFallbackFactory, \
|
||||||
|
com.ruoyi.system.api.factory.RemoteFileFallbackFactory
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>3.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -16,19 +16,19 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- SpringCloud Ailibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringCloud Ailibaba Nacos Config -->
|
<!-- SpringCloud Alibaba Nacos Config -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringCloud Ailibaba Sentinel -->
|
<!-- SpringCloud Alibaba Sentinel -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
@@ -45,12 +45,6 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Mysql Connector -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- RuoYi Common Security-->
|
<!-- RuoYi Common Security-->
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -61,6 +55,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.ruoyi.auth;
|
package com.ruoyi.auth;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.cloud.client.SpringCloudApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,7 +11,7 @@ import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
|||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@EnableRyFeignClients
|
@EnableRyFeignClients
|
||||||
@SpringCloudApplication
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
|
||||||
public class RuoYiAuthApplication
|
public class RuoYiAuthApplication
|
||||||
{
|
{
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
|
|||||||
@@ -7,10 +7,14 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.ruoyi.auth.form.LoginBody;
|
import com.ruoyi.auth.form.LoginBody;
|
||||||
|
import com.ruoyi.auth.form.RegisterBody;
|
||||||
import com.ruoyi.auth.service.SysLoginService;
|
import com.ruoyi.auth.service.SysLoginService;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.utils.JwtUtils;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.security.auth.AuthUtil;
|
||||||
import com.ruoyi.common.security.service.TokenService;
|
import com.ruoyi.common.security.service.TokenService;
|
||||||
|
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
import com.ruoyi.system.api.model.LoginUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,12 +43,12 @@ public class TokenController
|
|||||||
@DeleteMapping("logout")
|
@DeleteMapping("logout")
|
||||||
public R<?> logout(HttpServletRequest request)
|
public R<?> logout(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
String token = SecurityUtils.getToken(request);
|
||||||
if (StringUtils.isNotNull(loginUser))
|
if (StringUtils.isNotEmpty(token))
|
||||||
{
|
{
|
||||||
String username = loginUser.getUsername();
|
String username = JwtUtils.getUserName(token);
|
||||||
// 删除用户缓存记录
|
// 删除用户缓存记录
|
||||||
tokenService.delLoginUser(loginUser.getToken());
|
AuthUtil.logoutByToken(token);
|
||||||
// 记录用户退出日志
|
// 记录用户退出日志
|
||||||
sysLoginService.logout(username);
|
sysLoginService.logout(username);
|
||||||
}
|
}
|
||||||
@@ -63,4 +67,12 @@ public class TokenController
|
|||||||
}
|
}
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("register")
|
||||||
|
public R<?> register(@RequestBody RegisterBody registerBody)
|
||||||
|
{
|
||||||
|
// 用户注册
|
||||||
|
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,16 +17,6 @@ public class LoginBody
|
|||||||
*/
|
*/
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码
|
|
||||||
*/
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 唯一标识
|
|
||||||
*/
|
|
||||||
private String uuid = "";
|
|
||||||
|
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
{
|
{
|
||||||
return username;
|
return username;
|
||||||
@@ -46,24 +36,4 @@ public class LoginBody
|
|||||||
{
|
{
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCode()
|
|
||||||
{
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(String code)
|
|
||||||
{
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUuid()
|
|
||||||
{
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUuid(String uuid)
|
|
||||||
{
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.ruoyi.auth.form;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注册对象
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class RegisterBody extends LoginBody
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,14 +3,18 @@ package com.ruoyi.auth.service;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.enums.UserStatus;
|
import com.ruoyi.common.core.enums.UserStatus;
|
||||||
import com.ruoyi.common.core.exception.BaseException;
|
import com.ruoyi.common.core.exception.ServiceException;
|
||||||
|
import com.ruoyi.common.core.utils.ServletUtils;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.core.utils.ip.IpUtils;
|
||||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||||
import com.ruoyi.system.api.RemoteLogService;
|
import com.ruoyi.system.api.RemoteLogService;
|
||||||
import com.ruoyi.system.api.RemoteUserService;
|
import com.ruoyi.system.api.RemoteUserService;
|
||||||
|
import com.ruoyi.system.api.domain.SysLogininfor;
|
||||||
import com.ruoyi.system.api.domain.SysUser;
|
import com.ruoyi.system.api.domain.SysUser;
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
import com.ruoyi.system.api.model.LoginUser;
|
||||||
|
|
||||||
@@ -36,60 +40,120 @@ public class SysLoginService
|
|||||||
// 用户名或密码为空 错误
|
// 用户名或密码为空 错误
|
||||||
if (StringUtils.isAnyBlank(username, password))
|
if (StringUtils.isAnyBlank(username, password))
|
||||||
{
|
{
|
||||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
||||||
throw new BaseException("用户/密码必须填写");
|
throw new ServiceException("用户/密码必须填写");
|
||||||
}
|
}
|
||||||
// 密码如果不在指定范围内 错误
|
// 密码如果不在指定范围内 错误
|
||||||
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||||
{
|
{
|
||||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
||||||
throw new BaseException("用户密码不在指定范围");
|
throw new ServiceException("用户密码不在指定范围");
|
||||||
}
|
}
|
||||||
// 用户名不在指定范围内 错误
|
// 用户名不在指定范围内 错误
|
||||||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||||
{
|
{
|
||||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
||||||
throw new BaseException("用户名不在指定范围");
|
throw new ServiceException("用户名不在指定范围");
|
||||||
}
|
}
|
||||||
// 查询用户信息
|
// 查询用户信息
|
||||||
R<LoginUser> userResult = remoteUserService.getUserInfo(username);
|
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||||
|
|
||||||
if (R.FAIL == userResult.getCode())
|
if (R.FAIL == userResult.getCode())
|
||||||
{
|
{
|
||||||
throw new BaseException(userResult.getMsg());
|
throw new ServiceException(userResult.getMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
|
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
|
||||||
{
|
{
|
||||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||||
throw new BaseException("登录用户:" + username + " 不存在");
|
throw new ServiceException("登录用户:" + username + " 不存在");
|
||||||
}
|
}
|
||||||
LoginUser userInfo = userResult.getData();
|
LoginUser userInfo = userResult.getData();
|
||||||
SysUser user = userResult.getData().getSysUser();
|
SysUser user = userResult.getData().getSysUser();
|
||||||
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
||||||
{
|
{
|
||||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
||||||
|
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
||||||
throw new BaseException("对不起,您的账号:" + username + " 已被删除");
|
|
||||||
}
|
}
|
||||||
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
||||||
{
|
{
|
||||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
||||||
throw new BaseException("对不起,您的账号:" + username + " 已停用");
|
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
||||||
}
|
}
|
||||||
if (!SecurityUtils.matchesPassword(password, user.getPassword()))
|
if (!SecurityUtils.matchesPassword(password, user.getPassword()))
|
||||||
{
|
{
|
||||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
|
||||||
throw new BaseException("用户不存在/密码错误");
|
throw new ServiceException("用户不存在/密码错误");
|
||||||
}
|
}
|
||||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logout(String loginName)
|
public void logout(String loginName)
|
||||||
{
|
{
|
||||||
remoteLogService.saveLogininfor(loginName, Constants.LOGOUT, "退出成功");
|
recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册
|
||||||
|
*/
|
||||||
|
public void register(String username, String password)
|
||||||
|
{
|
||||||
|
// 用户名或密码为空 错误
|
||||||
|
if (StringUtils.isAnyBlank(username, password))
|
||||||
|
{
|
||||||
|
throw new ServiceException("用户/密码必须填写");
|
||||||
|
}
|
||||||
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||||
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||||
|
{
|
||||||
|
throw new ServiceException("账户长度必须在2到20个字符之间");
|
||||||
|
}
|
||||||
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||||
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||||
|
{
|
||||||
|
throw new ServiceException("密码长度必须在5到20个字符之间");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注册用户信息
|
||||||
|
SysUser sysUser = new SysUser();
|
||||||
|
sysUser.setUserName(username);
|
||||||
|
sysUser.setNickName(username);
|
||||||
|
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
||||||
|
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
|
||||||
|
|
||||||
|
if (R.FAIL == registerResult.getCode())
|
||||||
|
{
|
||||||
|
throw new ServiceException(registerResult.getMsg());
|
||||||
|
}
|
||||||
|
recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录登录信息
|
||||||
|
*
|
||||||
|
* @param username 用户名
|
||||||
|
* @param status 状态
|
||||||
|
* @param message 消息内容
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void recordLogininfor(String username, String status, String message)
|
||||||
|
{
|
||||||
|
SysLogininfor logininfor = new SysLogininfor();
|
||||||
|
logininfor.setUserName(username);
|
||||||
|
logininfor.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
||||||
|
logininfor.setMsg(message);
|
||||||
|
// 日志状态
|
||||||
|
if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER))
|
||||||
|
{
|
||||||
|
logininfor.setStatus("0");
|
||||||
|
}
|
||||||
|
else if (Constants.LOGIN_FAIL.equals(status))
|
||||||
|
{
|
||||||
|
logininfor.setStatus("1");
|
||||||
|
}
|
||||||
|
remoteLogService.saveLogininfor(logininfor, SecurityConstants.INNER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,4 +21,5 @@ spring:
|
|||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
|||||||
74
ruoyi-auth/src/main/resources/logback.xml
Normal file
74
ruoyi-auth/src/main/resources/logback.xml
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
<!-- 日志存放路径 -->
|
||||||
|
<property name="log.path" value="logs/ruoyi-auth" />
|
||||||
|
<!-- 日志输出格式 -->
|
||||||
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统日志输出 -->
|
||||||
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/info.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>INFO</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/error.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>ERROR</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统模块日志级别控制 -->
|
||||||
|
<logger name="com.ruoyi" level="info" />
|
||||||
|
<!-- Spring日志级别控制 -->
|
||||||
|
<logger name="org.springframework" level="warn" />
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<!--系统操作日志-->
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="file_info" />
|
||||||
|
<appender-ref ref="file_error" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>3.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
<module>ruoyi-common-swagger</module>
|
<module>ruoyi-common-swagger</module>
|
||||||
<module>ruoyi-common-security</module>
|
<module>ruoyi-common-security</module>
|
||||||
<module>ruoyi-common-datascope</module>
|
<module>ruoyi-common-datascope</module>
|
||||||
|
<module>ruoyi-common-datasource</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>3.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -17,28 +17,34 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- SpringCloud Openfeign -->
|
<!-- SpringCloud Openfeign -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringCloud Loadbalancer -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Context Support -->
|
<!-- Spring Context Support -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context-support</artifactId>
|
<artifactId>spring-context-support</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Web -->
|
<!-- Spring Web -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Apache Commons Pool2 -->
|
<!-- Transmittable ThreadLocal -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>commons-pool2</artifactId>
|
<artifactId>transmittable-thread-local</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Pagehelper -->
|
<!-- Pagehelper -->
|
||||||
@@ -65,6 +71,18 @@
|
|||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Jwt -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Jaxb -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Apache Lang3 -->
|
<!-- Apache Lang3 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import com.ruoyi.common.core.utils.poi.ExcelHandlerAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义导出Excel数据注解
|
* 自定义导出Excel数据注解
|
||||||
@@ -100,6 +101,37 @@ public @interface Excel
|
|||||||
*/
|
*/
|
||||||
public boolean isStatistics() default false;
|
public boolean isStatistics() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出字段对齐方式(0:默认;1:靠左;2:居中;3:靠右)
|
||||||
|
*/
|
||||||
|
public Align align() default Align.AUTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义数据处理器
|
||||||
|
*/
|
||||||
|
public Class<?> handler() default ExcelHandlerAdapter.class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义数据处理器参数
|
||||||
|
*/
|
||||||
|
public String[] args() default {};
|
||||||
|
|
||||||
|
public enum Align
|
||||||
|
{
|
||||||
|
AUTO(0), LEFT(1), CENTER(2), RIGHT(3);
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
Align(int value)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int value()
|
||||||
|
{
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
||||||
*/
|
*/
|
||||||
@@ -123,7 +155,7 @@ public @interface Excel
|
|||||||
|
|
||||||
public enum ColumnType
|
public enum ColumnType
|
||||||
{
|
{
|
||||||
NUMERIC(0), STRING(1);
|
NUMERIC(0), STRING(1), IMAGE(2);
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
ColumnType(int value)
|
ColumnType(int value)
|
||||||
|
|||||||
@@ -8,27 +8,17 @@ package com.ruoyi.common.core.constant;
|
|||||||
public class CacheConstants
|
public class CacheConstants
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 令牌自定义标识
|
* 缓存有效期,默认720(分钟)
|
||||||
*/
|
*/
|
||||||
public static final String HEADER = "Authorization";
|
public final static long EXPIRATION = 720;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 令牌前缀
|
* 缓存刷新时间,默认120(分钟)
|
||||||
*/
|
*/
|
||||||
public static final String TOKEN_PREFIX = "Bearer ";
|
public final static long REFRESH_TIME = 120;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限缓存前缀
|
* 权限缓存前缀
|
||||||
*/
|
*/
|
||||||
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
|
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户ID字段
|
|
||||||
*/
|
|
||||||
public static final String DETAILS_USER_ID = "user_id";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户名字段
|
|
||||||
*/
|
|
||||||
public static final String DETAILS_USERNAME = "username";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,21 @@ public class Constants
|
|||||||
*/
|
*/
|
||||||
public static final String GBK = "GBK";
|
public static final String GBK = "GBK";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RMI 远程方法调用
|
||||||
|
*/
|
||||||
|
public static final String LOOKUP_RMI = "rmi:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LDAP 远程方法调用
|
||||||
|
*/
|
||||||
|
public static final String LOOKUP_LDAP = "ldap:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LDAPS 远程方法调用
|
||||||
|
*/
|
||||||
|
public static final String LOOKUP_LDAPS = "ldaps:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http请求
|
* http请求
|
||||||
*/
|
*/
|
||||||
@@ -87,10 +102,6 @@ public class Constants
|
|||||||
*/
|
*/
|
||||||
public static final long CAPTCHA_EXPIRATION = 2;
|
public static final long CAPTCHA_EXPIRATION = 2;
|
||||||
|
|
||||||
/**
|
|
||||||
* 令牌有效期(分钟)
|
|
||||||
*/
|
|
||||||
public final static long TOKEN_EXPIRE = 720;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数管理 cache key
|
* 参数管理 cache key
|
||||||
@@ -106,4 +117,15 @@ public class Constants
|
|||||||
* 资源映射路径 前缀
|
* 资源映射路径 前缀
|
||||||
*/
|
*/
|
||||||
public static final String RESOURCE_PREFIX = "/profile";
|
public static final String RESOURCE_PREFIX = "/profile";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
|
||||||
|
*/
|
||||||
|
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务违规的字符
|
||||||
|
*/
|
||||||
|
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
|
||||||
|
"org.springframework", "org.apache", "com.ruoyi.common.core.utils.file" };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ public class GenConstants
|
|||||||
/** 树表(增删改查) */
|
/** 树表(增删改查) */
|
||||||
public static final String TPL_TREE = "tree";
|
public static final String TPL_TREE = "tree";
|
||||||
|
|
||||||
|
/** 主子表(增删改查) */
|
||||||
|
public static final String TPL_SUB = "sub";
|
||||||
|
|
||||||
/** 树编码字段 */
|
/** 树编码字段 */
|
||||||
public static final String TREE_CODE = "treeCode";
|
public static final String TREE_CODE = "treeCode";
|
||||||
|
|
||||||
@@ -29,15 +32,17 @@ public class GenConstants
|
|||||||
public static final String PARENT_MENU_NAME = "parentMenuName";
|
public static final String PARENT_MENU_NAME = "parentMenuName";
|
||||||
|
|
||||||
/** 数据库字符串类型 */
|
/** 数据库字符串类型 */
|
||||||
public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2", "tinytext", "text",
|
public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" };
|
||||||
"mediumtext", "longtext" };
|
|
||||||
|
/** 数据库文本类型 */
|
||||||
|
public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" };
|
||||||
|
|
||||||
/** 数据库时间类型 */
|
/** 数据库时间类型 */
|
||||||
public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" };
|
public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" };
|
||||||
|
|
||||||
/** 数据库数字类型 */
|
/** 数据库数字类型 */
|
||||||
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||||
"bigint", "float", "float", "double", "decimal" };
|
"bigint", "float", "double", "decimal" };
|
||||||
|
|
||||||
/** 页面不需要编辑字段 */
|
/** 页面不需要编辑字段 */
|
||||||
public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" };
|
public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" };
|
||||||
@@ -74,6 +79,12 @@ public class GenConstants
|
|||||||
/** 日期控件 */
|
/** 日期控件 */
|
||||||
public static final String HTML_DATETIME = "datetime";
|
public static final String HTML_DATETIME = "datetime";
|
||||||
|
|
||||||
|
/** 图片上传控件 */
|
||||||
|
public static final String HTML_IMAGE_UPLOAD = "imageUpload";
|
||||||
|
|
||||||
|
/** 文件上传控件 */
|
||||||
|
public static final String HTML_FILE_UPLOAD = "fileUpload";
|
||||||
|
|
||||||
/** 富文本控件 */
|
/** 富文本控件 */
|
||||||
public static final String HTML_EDITOR = "editor";
|
public static final String HTML_EDITOR = "editor";
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.ruoyi.common.core.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限相关通用常量
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class SecurityConstants
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用户ID字段
|
||||||
|
*/
|
||||||
|
public static final String DETAILS_USER_ID = "user_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名字段
|
||||||
|
*/
|
||||||
|
public static final String DETAILS_USERNAME = "username";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 授权信息字段
|
||||||
|
*/
|
||||||
|
public static final String AUTHORIZATION_HEADER = "authorization";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求来源
|
||||||
|
*/
|
||||||
|
public static final String FROM_SOURCE = "from-source";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部请求
|
||||||
|
*/
|
||||||
|
public static final String INNER = "inner";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户标识
|
||||||
|
*/
|
||||||
|
public static final String USER_KEY = "user_key";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录用户
|
||||||
|
*/
|
||||||
|
public static final String LOGIN_USER = "login_user";
|
||||||
|
}
|
||||||
@@ -16,4 +16,9 @@ public class ServiceNameConstants
|
|||||||
* 系统模块的serviceid
|
* 系统模块的serviceid
|
||||||
*/
|
*/
|
||||||
public static final String SYSTEM_SERVICE = "ruoyi-system";
|
public static final String SYSTEM_SERVICE = "ruoyi-system";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件服务的serviceid
|
||||||
|
*/
|
||||||
|
public static final String FILE_SERVICE = "ruoyi-file";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.ruoyi.common.core.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token的Key常量
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class TokenConstants
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 令牌自定义标识
|
||||||
|
*/
|
||||||
|
public static final String AUTHENTICATION = "Authorization";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 令牌前缀
|
||||||
|
*/
|
||||||
|
public static final String PREFIX = "Bearer ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 令牌秘钥
|
||||||
|
*/
|
||||||
|
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -54,6 +54,12 @@ public class UserConstants
|
|||||||
/** Layout组件标识 */
|
/** Layout组件标识 */
|
||||||
public final static String LAYOUT = "Layout";
|
public final static String LAYOUT = "Layout";
|
||||||
|
|
||||||
|
/** ParentView组件标识 */
|
||||||
|
public final static String PARENT_VIEW = "ParentView";
|
||||||
|
|
||||||
|
/** InnerLink组件标识 */
|
||||||
|
public final static String INNER_LINK = "InnerLink";
|
||||||
|
|
||||||
/** 校验返回结果码 */
|
/** 校验返回结果码 */
|
||||||
public final static String UNIQUE = "0";
|
public final static String UNIQUE = "0";
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package com.ruoyi.common.core.context;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||||
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前线程变量中的 用户id、用户名称、Token等信息
|
||||||
|
* 注意: 必须在网关通过请求头的方法传入,同时在HeaderInterceptor拦截器设置值。 否则这里无法获取
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class SecurityContextHolder
|
||||||
|
{
|
||||||
|
private static final TransmittableThreadLocal<Map<String, Object>> THREAD_LOCAL = new TransmittableThreadLocal<>();
|
||||||
|
|
||||||
|
public static void set(String key, Object value)
|
||||||
|
{
|
||||||
|
Map<String, Object> map = getLocalMap();
|
||||||
|
map.put(key, value == null ? StringUtils.EMPTY : value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String get(String key)
|
||||||
|
{
|
||||||
|
Map<String, Object> map = getLocalMap();
|
||||||
|
return Convert.toStr(map.getOrDefault(key, StringUtils.EMPTY));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T get(String key, Class<T> clazz)
|
||||||
|
{
|
||||||
|
Map<String, Object> map = getLocalMap();
|
||||||
|
return StringUtils.cast(map.getOrDefault(key, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> getLocalMap()
|
||||||
|
{
|
||||||
|
Map<String, Object> map = THREAD_LOCAL.get();
|
||||||
|
if (map == null)
|
||||||
|
{
|
||||||
|
map = new ConcurrentHashMap<String, Object>();
|
||||||
|
THREAD_LOCAL.set(map);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLocalMap(Map<String, Object> threadLocalMap)
|
||||||
|
{
|
||||||
|
THREAD_LOCAL.set(threadLocalMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long getUserId()
|
||||||
|
{
|
||||||
|
return Convert.toLong(get(SecurityConstants.DETAILS_USER_ID), 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setUserId(String account)
|
||||||
|
{
|
||||||
|
set(SecurityConstants.DETAILS_USER_ID, account);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUserName()
|
||||||
|
{
|
||||||
|
return get(SecurityConstants.DETAILS_USERNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setUserName(String username)
|
||||||
|
{
|
||||||
|
set(SecurityConstants.DETAILS_USERNAME, username);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUserKey()
|
||||||
|
{
|
||||||
|
return get(SecurityConstants.USER_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setUserKey(String userKey)
|
||||||
|
{
|
||||||
|
set(SecurityConstants.USER_KEY, userKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void remove()
|
||||||
|
{
|
||||||
|
THREAD_LOCAL.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.ruoyi.common.core.exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义异常
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public class CustomException extends RuntimeException
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private Integer code;
|
|
||||||
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
public CustomException(String message)
|
|
||||||
{
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomException(String message, Integer code)
|
|
||||||
{
|
|
||||||
this.message = message;
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomException(String message, Throwable e)
|
|
||||||
{
|
|
||||||
super(message, e);
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage()
|
|
||||||
{
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCode()
|
|
||||||
{
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.ruoyi.common.core.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局异常
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class GlobalException extends RuntimeException
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误提示
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误明细,内部调试错误
|
||||||
|
*
|
||||||
|
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
|
||||||
|
*/
|
||||||
|
private String detailMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空构造方法,避免反序列化问题
|
||||||
|
*/
|
||||||
|
public GlobalException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalException(String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDetailMessage()
|
||||||
|
{
|
||||||
|
return detailMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalException setDetailMessage(String detailMessage)
|
||||||
|
{
|
||||||
|
this.detailMessage = detailMessage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalException setMessage(String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.common.core.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部认证异常
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class InnerAuthException extends RuntimeException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public InnerAuthException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package com.ruoyi.common.core.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务异常
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public final class ServiceException extends RuntimeException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码
|
||||||
|
*/
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误提示
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误明细,内部调试错误
|
||||||
|
*
|
||||||
|
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
|
||||||
|
*/
|
||||||
|
private String detailMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空构造方法,避免反序列化问题
|
||||||
|
*/
|
||||||
|
public ServiceException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceException(String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceException(String message, Integer code)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDetailMessage()
|
||||||
|
{
|
||||||
|
return detailMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode()
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceException setMessage(String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceException setDetailMessage(String detailMessage)
|
||||||
|
{
|
||||||
|
this.detailMessage = detailMessage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.common.core.exception.auth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未能通过的登录认证异常
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class NotLoginException extends RuntimeException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public NotLoginException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.ruoyi.common.core.exception.auth;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未能通过的权限认证异常
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class NotPermissionException extends RuntimeException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public NotPermissionException(String permission)
|
||||||
|
{
|
||||||
|
super(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotPermissionException(String[] permissions)
|
||||||
|
{
|
||||||
|
super(StringUtils.join(permissions, ","));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.ruoyi.common.core.exception.auth;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未能通过的角色认证异常
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class NotRoleException extends RuntimeException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public NotRoleException(String role)
|
||||||
|
{
|
||||||
|
super(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotRoleException(String[] roles)
|
||||||
|
{
|
||||||
|
super(StringUtils.join(roles, ","));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,79 +1,79 @@
|
|||||||
package com.ruoyi.common.core.exception;
|
package com.ruoyi.common.core.exception.base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础异常
|
* 基础异常
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class BaseException extends RuntimeException
|
public class BaseException extends RuntimeException
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所属模块
|
* 所属模块
|
||||||
*/
|
*/
|
||||||
private String module;
|
private String module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误码
|
* 错误码
|
||||||
*/
|
*/
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误码对应的参数
|
* 错误码对应的参数
|
||||||
*/
|
*/
|
||||||
private Object[] args;
|
private Object[] args;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误消息
|
* 错误消息
|
||||||
*/
|
*/
|
||||||
private String defaultMessage;
|
private String defaultMessage;
|
||||||
|
|
||||||
public BaseException(String module, String code, Object[] args, String defaultMessage)
|
public BaseException(String module, String code, Object[] args, String defaultMessage)
|
||||||
{
|
{
|
||||||
this.module = module;
|
this.module = module;
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
this.defaultMessage = defaultMessage;
|
this.defaultMessage = defaultMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseException(String module, String code, Object[] args)
|
public BaseException(String module, String code, Object[] args)
|
||||||
{
|
{
|
||||||
this(module, code, args, null);
|
this(module, code, args, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseException(String module, String defaultMessage)
|
public BaseException(String module, String defaultMessage)
|
||||||
{
|
{
|
||||||
this(module, null, null, defaultMessage);
|
this(module, null, null, defaultMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseException(String code, Object[] args)
|
public BaseException(String code, Object[] args)
|
||||||
{
|
{
|
||||||
this(null, code, args, null);
|
this(null, code, args, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseException(String defaultMessage)
|
public BaseException(String defaultMessage)
|
||||||
{
|
{
|
||||||
this(null, null, null, defaultMessage);
|
this(null, null, null, defaultMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModule()
|
public String getModule()
|
||||||
{
|
{
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCode()
|
public String getCode()
|
||||||
{
|
{
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getArgs()
|
public Object[] getArgs()
|
||||||
{
|
{
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultMessage()
|
public String getDefaultMessage()
|
||||||
{
|
{
|
||||||
return defaultMessage;
|
return defaultMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.ruoyi.common.core.exception.file;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.exception.base.BaseException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件信息异常类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class FileException extends BaseException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public FileException(String code, Object[] args)
|
||||||
|
{
|
||||||
|
super("file", code, args, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.common.core.exception.file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名称超长限制异常类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class FileNameLengthLimitExceededException extends FileException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public FileNameLengthLimitExceededException(int defaultFileNameLength)
|
||||||
|
{
|
||||||
|
super("upload.filename.exceed.length", new Object[] { defaultFileNameLength });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.common.core.exception.file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名大小限制异常类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class FileSizeLimitExceededException extends FileException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public FileSizeLimitExceededException(long defaultMaxSize)
|
||||||
|
{
|
||||||
|
super("upload.exceed.maxSize", new Object[] { defaultMaxSize });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package com.ruoyi.common.core.exception.file;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import org.apache.commons.fileupload.FileUploadException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传 误异常类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class InvalidExtensionException extends FileUploadException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String[] allowedExtension;
|
||||||
|
private String extension;
|
||||||
|
private String filename;
|
||||||
|
|
||||||
|
public InvalidExtensionException(String[] allowedExtension, String extension, String filename)
|
||||||
|
{
|
||||||
|
super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
|
||||||
|
this.allowedExtension = allowedExtension;
|
||||||
|
this.extension = extension;
|
||||||
|
this.filename = filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getAllowedExtension()
|
||||||
|
{
|
||||||
|
return allowedExtension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExtension()
|
||||||
|
{
|
||||||
|
return extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilename()
|
||||||
|
{
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InvalidImageExtensionException extends InvalidExtensionException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename)
|
||||||
|
{
|
||||||
|
super(allowedExtension, extension, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InvalidFlashExtensionException extends InvalidExtensionException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename)
|
||||||
|
{
|
||||||
|
super(allowedExtension, extension, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InvalidMediaExtensionException extends InvalidExtensionException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename)
|
||||||
|
{
|
||||||
|
super(allowedExtension, extension, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InvalidVideoExtensionException extends InvalidExtensionException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename)
|
||||||
|
{
|
||||||
|
super(allowedExtension, extension, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.ruoyi.common.core.exception.user;
|
package com.ruoyi.common.core.exception.user;
|
||||||
|
|
||||||
import com.ruoyi.common.core.exception.BaseException;
|
import com.ruoyi.common.core.exception.base.BaseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息异常类
|
* 用户信息异常类
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class CharsetKit
|
|||||||
|
|
||||||
if (null == destCharset)
|
if (null == destCharset)
|
||||||
{
|
{
|
||||||
srcCharset = StandardCharsets.UTF_8;
|
destCharset = StandardCharsets.UTF_8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset))
|
if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset))
|
||||||
|
|||||||
@@ -797,7 +797,21 @@ public class Convert
|
|||||||
}
|
}
|
||||||
else if (obj instanceof byte[] || obj instanceof Byte[])
|
else if (obj instanceof byte[] || obj instanceof Byte[])
|
||||||
{
|
{
|
||||||
return str((Byte[]) obj, charset);
|
if (obj instanceof byte[])
|
||||||
|
{
|
||||||
|
return str((byte[]) obj, charset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Byte[] bytes = (Byte[]) obj;
|
||||||
|
int length = bytes.length;
|
||||||
|
byte[] dest = new byte[length];
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
dest[i] = bytes[i];
|
||||||
|
}
|
||||||
|
return str(dest, charset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (obj instanceof ByteBuffer)
|
else if (obj instanceof ByteBuffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class ExceptionUtil
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRootErrorMseeage(Exception e)
|
public static String getRootErrorMessage(Exception e)
|
||||||
{
|
{
|
||||||
Throwable root = ExceptionUtils.getRootCause(e);
|
Throwable root = ExceptionUtils.getRootCause(e);
|
||||||
root = (root == null ? e : root);
|
root = (root == null ? e : root);
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.ruoyi.common.core.utils;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
|
import com.ruoyi.common.core.constant.TokenConstants;
|
||||||
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import io.jsonwebtoken.Jwts;
|
||||||
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jwt工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class JwtUtils
|
||||||
|
{
|
||||||
|
public static String secret = TokenConstants.SECRET;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从数据声明生成令牌
|
||||||
|
*
|
||||||
|
* @param claims 数据声明
|
||||||
|
* @return 令牌
|
||||||
|
*/
|
||||||
|
public static String createToken(Map<String, Object> claims)
|
||||||
|
{
|
||||||
|
String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact();
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从令牌中获取数据声明
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 数据声明
|
||||||
|
*/
|
||||||
|
public static Claims parseToken(String token)
|
||||||
|
{
|
||||||
|
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户标识
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserKey(String token)
|
||||||
|
{
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, SecurityConstants.USER_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户标识
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserKey(Claims claims)
|
||||||
|
{
|
||||||
|
return getValue(claims, SecurityConstants.USER_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户ID
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserId(String token)
|
||||||
|
{
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, SecurityConstants.DETAILS_USER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取用户ID
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserId(Claims claims)
|
||||||
|
{
|
||||||
|
return getValue(claims, SecurityConstants.DETAILS_USER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户名
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户名
|
||||||
|
*/
|
||||||
|
public static String getUserName(String token)
|
||||||
|
{
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取用户名
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户名
|
||||||
|
*/
|
||||||
|
public static String getUserName(Claims claims)
|
||||||
|
{
|
||||||
|
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取键值
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @param key 键
|
||||||
|
* @return 值
|
||||||
|
*/
|
||||||
|
public static String getValue(Claims claims, String key)
|
||||||
|
{
|
||||||
|
return Convert.toStr(claims.get(key), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.ruoyi.common.core.utils;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.ruoyi.common.core.utils.sql.SqlUtil;
|
||||||
|
import com.ruoyi.common.core.web.page.PageDomain;
|
||||||
|
import com.ruoyi.common.core.web.page.TableSupport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class PageUtils extends PageHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 设置请求分页数据
|
||||||
|
*/
|
||||||
|
public static void startPage()
|
||||||
|
{
|
||||||
|
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||||
|
Integer pageNum = pageDomain.getPageNum();
|
||||||
|
Integer pageSize = pageDomain.getPageSize();
|
||||||
|
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize))
|
||||||
|
{
|
||||||
|
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
|
||||||
|
Boolean reasonable = pageDomain.getReasonable();
|
||||||
|
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,28 @@
|
|||||||
package com.ruoyi.common.core.utils;
|
package com.ruoyi.common.core.utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
import org.springframework.web.context.request.RequestAttributes;
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端工具类
|
* 客户端工具类
|
||||||
@@ -48,12 +63,35 @@ public class ServletUtils
|
|||||||
return Convert.toInt(getRequest().getParameter(name), defaultValue);
|
return Convert.toInt(getRequest().getParameter(name), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Boolean参数
|
||||||
|
*/
|
||||||
|
public static Boolean getParameterToBool(String name)
|
||||||
|
{
|
||||||
|
return Convert.toBool(getRequest().getParameter(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Boolean参数
|
||||||
|
*/
|
||||||
|
public static Boolean getParameterToBool(String name, Boolean defaultValue)
|
||||||
|
{
|
||||||
|
return Convert.toBool(getRequest().getParameter(name), defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取request
|
* 获取request
|
||||||
*/
|
*/
|
||||||
public static HttpServletRequest getRequest()
|
public static HttpServletRequest getRequest()
|
||||||
{
|
{
|
||||||
return getRequestAttributes().getRequest();
|
try
|
||||||
|
{
|
||||||
|
return getRequestAttributes().getRequest();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,7 +99,14 @@ public class ServletUtils
|
|||||||
*/
|
*/
|
||||||
public static HttpServletResponse getResponse()
|
public static HttpServletResponse getResponse()
|
||||||
{
|
{
|
||||||
return getRequestAttributes().getResponse();
|
try
|
||||||
|
{
|
||||||
|
return getRequestAttributes().getResponse();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,8 +119,41 @@ public class ServletUtils
|
|||||||
|
|
||||||
public static ServletRequestAttributes getRequestAttributes()
|
public static ServletRequestAttributes getRequestAttributes()
|
||||||
{
|
{
|
||||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
try
|
||||||
return (ServletRequestAttributes) attributes;
|
{
|
||||||
|
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||||
|
return (ServletRequestAttributes) attributes;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHeader(HttpServletRequest request, String name)
|
||||||
|
{
|
||||||
|
String value = request.getHeader(name);
|
||||||
|
if (StringUtils.isEmpty(value))
|
||||||
|
{
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
return urlDecode(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> getHeaders(HttpServletRequest request)
|
||||||
|
{
|
||||||
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
|
Enumeration<String> enumeration = request.getHeaderNames();
|
||||||
|
if (enumeration != null)
|
||||||
|
{
|
||||||
|
while (enumeration.hasMoreElements())
|
||||||
|
{
|
||||||
|
String key = enumeration.nextElement();
|
||||||
|
String value = request.getHeader(key);
|
||||||
|
map.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,4 +211,98 @@ public class ServletUtils
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容编码
|
||||||
|
*
|
||||||
|
* @param str 内容
|
||||||
|
* @return 编码后的内容
|
||||||
|
*/
|
||||||
|
public static String urlEncode(String str)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return URLEncoder.encode(str, Constants.UTF8);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e)
|
||||||
|
{
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容解码
|
||||||
|
*
|
||||||
|
* @param str 内容
|
||||||
|
* @return 解码后的内容
|
||||||
|
*/
|
||||||
|
public static String urlDecode(String str)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return URLDecoder.decode(str, Constants.UTF8);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e)
|
||||||
|
{
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置webflux模型响应
|
||||||
|
*
|
||||||
|
* @param response ServerHttpResponse
|
||||||
|
* @param value 响应内容
|
||||||
|
* @return Mono<Void>
|
||||||
|
*/
|
||||||
|
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value)
|
||||||
|
{
|
||||||
|
return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置webflux模型响应
|
||||||
|
*
|
||||||
|
* @param response ServerHttpResponse
|
||||||
|
* @param code 响应状态码
|
||||||
|
* @param value 响应内容
|
||||||
|
* @return Mono<Void>
|
||||||
|
*/
|
||||||
|
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code)
|
||||||
|
{
|
||||||
|
return webFluxResponseWriter(response, HttpStatus.OK, value, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置webflux模型响应
|
||||||
|
*
|
||||||
|
* @param response ServerHttpResponse
|
||||||
|
* @param status http状态码
|
||||||
|
* @param code 响应状态码
|
||||||
|
* @param value 响应内容
|
||||||
|
* @return Mono<Void>
|
||||||
|
*/
|
||||||
|
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code)
|
||||||
|
{
|
||||||
|
return webFluxResponseWriter(response, MediaType.APPLICATION_JSON_VALUE, status, value, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置webflux模型响应
|
||||||
|
*
|
||||||
|
* @param response ServerHttpResponse
|
||||||
|
* @param contentType content-type
|
||||||
|
* @param status http状态码
|
||||||
|
* @param code 响应状态码
|
||||||
|
* @param value 响应内容
|
||||||
|
* @return Mono<Void>
|
||||||
|
*/
|
||||||
|
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code)
|
||||||
|
{
|
||||||
|
response.setStatusCode(status);
|
||||||
|
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
|
||||||
|
R<?> result = R.fail(code, value.toString());
|
||||||
|
DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(result).getBytes());
|
||||||
|
return response.writeWith(Mono.just(dataBuffer));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.ruoyi.common.core.utils;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
import com.ruoyi.common.core.text.StrFormatter;
|
import com.ruoyi.common.core.text.StrFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,9 +20,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
/** 下划线 */
|
/** 下划线 */
|
||||||
private static final char SEPARATOR = '_';
|
private static final char SEPARATOR = '_';
|
||||||
|
|
||||||
/** 星号 */
|
|
||||||
private static final String START = "*";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取参数不为空值
|
* 获取参数不为空值
|
||||||
*
|
*
|
||||||
@@ -238,6 +237,30 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
return str.substring(start, end);
|
return str.substring(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否为空,并且不是空白字符
|
||||||
|
*
|
||||||
|
* @param str 要判断的value
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static boolean hasText(String str)
|
||||||
|
{
|
||||||
|
return (str != null && !str.isEmpty() && containsText(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsText(CharSequence str)
|
||||||
|
{
|
||||||
|
int strLen = str.length();
|
||||||
|
for (int i = 0; i < strLen; i++)
|
||||||
|
{
|
||||||
|
if (!Character.isWhitespace(str.charAt(i)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化文本, {} 表示占位符<br>
|
* 格式化文本, {} 表示占位符<br>
|
||||||
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
|
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
|
||||||
@@ -261,7 +284,18 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下划线转驼峰命名
|
* 是否为http(s)://开头
|
||||||
|
*
|
||||||
|
* @param link 链接
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static boolean ishttp(String link)
|
||||||
|
{
|
||||||
|
return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驼峰转下划线命名
|
||||||
*/
|
*/
|
||||||
public static String toUnderScoreCase(String str)
|
public static String toUnderScoreCase(String str)
|
||||||
{
|
{
|
||||||
@@ -413,9 +447,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (String testStr : strs)
|
for (String pattern : strs)
|
||||||
{
|
{
|
||||||
if (matches(str, testStr))
|
if (isMatch(pattern, str))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -424,95 +458,19 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找指定字符串是否匹配指定字符串数组中的任意一个字符串
|
* 判断url是否与规则配置:
|
||||||
|
* ? 表示单个字符;
|
||||||
|
* * 表示一层路径内的任意字符串,不可跨层级;
|
||||||
|
* ** 表示任意层路径;
|
||||||
*
|
*
|
||||||
* @param str 指定字符串
|
* @param pattern 匹配规则
|
||||||
* @param strs 需要检查的字符串数组
|
* @param url 需要匹配的url
|
||||||
* @return 是否匹配
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean matches(String str, String... strs)
|
public static boolean isMatch(String pattern, String url)
|
||||||
{
|
{
|
||||||
if (isEmpty(str) || isEmpty(strs))
|
AntPathMatcher matcher = new AntPathMatcher();
|
||||||
{
|
return matcher.match(pattern, url);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (String testStr : strs)
|
|
||||||
{
|
|
||||||
if (matches(str, testStr))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查找指定字符串是否匹配
|
|
||||||
*
|
|
||||||
* @param str 指定字符串
|
|
||||||
* @param pattern 需要检查的字符串
|
|
||||||
* @return 是否匹配
|
|
||||||
*/
|
|
||||||
public static boolean matches(String str, String pattern)
|
|
||||||
{
|
|
||||||
if (isEmpty(pattern) || isEmpty(str))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pattern = pattern.replaceAll("\\s*", ""); // 替换空格
|
|
||||||
int beginOffset = 0; // pattern截取开始位置
|
|
||||||
int formerStarOffset = -1; // 前星号的偏移位置
|
|
||||||
int latterStarOffset = -1; // 后星号的偏移位置
|
|
||||||
|
|
||||||
String remainingURI = str;
|
|
||||||
String prefixPattern = "";
|
|
||||||
String suffixPattern = "";
|
|
||||||
|
|
||||||
boolean result = false;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
formerStarOffset = indexOf(pattern, START, beginOffset);
|
|
||||||
prefixPattern = substring(pattern, beginOffset, formerStarOffset > -1 ? formerStarOffset : pattern.length());
|
|
||||||
|
|
||||||
// 匹配前缀Pattern
|
|
||||||
result = remainingURI.contains(prefixPattern);
|
|
||||||
// 已经没有星号,直接返回
|
|
||||||
if (formerStarOffset == -1)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 匹配失败,直接返回
|
|
||||||
if (!result)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!isEmpty(prefixPattern))
|
|
||||||
{
|
|
||||||
remainingURI = substringAfter(str, prefixPattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 匹配后缀Pattern
|
|
||||||
latterStarOffset = indexOf(pattern, START, formerStarOffset + 1);
|
|
||||||
suffixPattern = substring(pattern, formerStarOffset + 1, latterStarOffset > -1 ? latterStarOffset : pattern.length());
|
|
||||||
|
|
||||||
result = remainingURI.contains(suffixPattern);
|
|
||||||
// 匹配失败,直接返回
|
|
||||||
if (!result)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!isEmpty(suffixPattern))
|
|
||||||
{
|
|
||||||
remainingURI = substringAfter(str, suffixPattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移动指针
|
|
||||||
beginOffset = latterStarOffset + 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
while (!isEmpty(suffixPattern) && !isEmpty(remainingURI));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi.common.core.utils.bean;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import javax.validation.Validator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bean对象属性验证
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class BeanValidators
|
||||||
|
{
|
||||||
|
public static void validateWithException(Validator validator, Object object, Class<?>... groups)
|
||||||
|
throws ConstraintViolationException
|
||||||
|
{
|
||||||
|
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
|
||||||
|
if (!constraintViolations.isEmpty())
|
||||||
|
{
|
||||||
|
throw new ConstraintViolationException(constraintViolations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.ruoyi.common.core.utils.file;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件类型工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class FileTypeUtils
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取文件类型
|
||||||
|
* <p>
|
||||||
|
* 例如: ruoyi.txt, 返回: txt
|
||||||
|
*
|
||||||
|
* @param file 文件名
|
||||||
|
* @return 后缀(不含".")
|
||||||
|
*/
|
||||||
|
public static String getFileType(File file)
|
||||||
|
{
|
||||||
|
if (null == file)
|
||||||
|
{
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
return getFileType(file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件类型
|
||||||
|
* <p>
|
||||||
|
* 例如: ruoyi.txt, 返回: txt
|
||||||
|
*
|
||||||
|
* @param fileName 文件名
|
||||||
|
* @return 后缀(不含".")
|
||||||
|
*/
|
||||||
|
public static String getFileType(String fileName)
|
||||||
|
{
|
||||||
|
int separatorIndex = fileName.lastIndexOf(".");
|
||||||
|
if (separatorIndex < 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return fileName.substring(separatorIndex + 1).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件类型
|
||||||
|
*
|
||||||
|
* @param photoByte 文件字节码
|
||||||
|
* @return 后缀(不含".")
|
||||||
|
*/
|
||||||
|
public static String getFileExtendName(byte[] photoByte)
|
||||||
|
{
|
||||||
|
String strFileExtendName = "JPG";
|
||||||
|
if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56)
|
||||||
|
&& ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97))
|
||||||
|
{
|
||||||
|
strFileExtendName = "GIF";
|
||||||
|
}
|
||||||
|
else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70))
|
||||||
|
{
|
||||||
|
strFileExtendName = "JPG";
|
||||||
|
}
|
||||||
|
else if ((photoByte[0] == 66) && (photoByte[1] == 77))
|
||||||
|
{
|
||||||
|
strFileExtendName = "BMP";
|
||||||
|
}
|
||||||
|
else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71))
|
||||||
|
{
|
||||||
|
strFileExtendName = "PNG";
|
||||||
|
}
|
||||||
|
return strFileExtendName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,15 +7,25 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件处理工具类
|
* 文件处理工具类
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class FileUtils extends org.apache.commons.io.FileUtils
|
public class FileUtils
|
||||||
{
|
{
|
||||||
|
/** 字符常量:斜杠 {@code '/'} */
|
||||||
|
public static final char SLASH = '/';
|
||||||
|
|
||||||
|
/** 字符常量:反斜杠 {@code '\\'} */
|
||||||
|
public static final char BACKSLASH = '\\';
|
||||||
|
|
||||||
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
|
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,6 +114,30 @@ public class FileUtils extends org.apache.commons.io.FileUtils
|
|||||||
return filename.matches(FILENAME_PATTERN);
|
return filename.matches(FILENAME_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查文件是否可下载
|
||||||
|
*
|
||||||
|
* @param resource 需要下载的文件
|
||||||
|
* @return true 正常 false 非法
|
||||||
|
*/
|
||||||
|
public static boolean checkAllowDownload(String resource)
|
||||||
|
{
|
||||||
|
// 禁止目录上跳级别
|
||||||
|
if (StringUtils.contains(resource, ".."))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查允许下载的文件规则
|
||||||
|
if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不在允许下载的文件规则
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件名重新编码
|
* 下载文件名重新编码
|
||||||
*
|
*
|
||||||
@@ -111,8 +145,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils
|
|||||||
* @param fileName 文件名
|
* @param fileName 文件名
|
||||||
* @return 编码后的文件名
|
* @return 编码后的文件名
|
||||||
*/
|
*/
|
||||||
public static String setFileDownloadHeader(HttpServletRequest request, String fileName)
|
public static String setFileDownloadHeader(HttpServletRequest request, String fileName) throws UnsupportedEncodingException
|
||||||
throws UnsupportedEncodingException
|
|
||||||
{
|
{
|
||||||
final String agent = request.getHeader("USER-AGENT");
|
final String agent = request.getHeader("USER-AGENT");
|
||||||
String filename = fileName;
|
String filename = fileName;
|
||||||
@@ -139,4 +172,90 @@ public class FileUtils extends org.apache.commons.io.FileUtils
|
|||||||
}
|
}
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回文件名
|
||||||
|
*
|
||||||
|
* @param filePath 文件
|
||||||
|
* @return 文件名
|
||||||
|
*/
|
||||||
|
public static String getName(String filePath)
|
||||||
|
{
|
||||||
|
if (null == filePath)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int len = filePath.length();
|
||||||
|
if (0 == len)
|
||||||
|
{
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
if (isFileSeparator(filePath.charAt(len - 1)))
|
||||||
|
{
|
||||||
|
// 以分隔符结尾的去掉结尾分隔符
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
int begin = 0;
|
||||||
|
char c;
|
||||||
|
for (int i = len - 1; i > -1; i--)
|
||||||
|
{
|
||||||
|
c = filePath.charAt(i);
|
||||||
|
if (isFileSeparator(c))
|
||||||
|
{
|
||||||
|
// 查找最后一个路径分隔符(/或者\)
|
||||||
|
begin = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePath.substring(begin, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为Windows或者Linux(Unix)文件分隔符<br>
|
||||||
|
* Windows平台下分隔符为\,Linux(Unix)为/
|
||||||
|
*
|
||||||
|
* @param c 字符
|
||||||
|
* @return 是否为Windows或者Linux(Unix)文件分隔符
|
||||||
|
*/
|
||||||
|
public static boolean isFileSeparator(char c)
|
||||||
|
{
|
||||||
|
return SLASH == c || BACKSLASH == c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载文件名重新编码
|
||||||
|
*
|
||||||
|
* @param response 响应对象
|
||||||
|
* @param realFileName 真实文件名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException
|
||||||
|
{
|
||||||
|
String percentEncodedFileName = percentEncode(realFileName);
|
||||||
|
|
||||||
|
StringBuilder contentDispositionValue = new StringBuilder();
|
||||||
|
contentDispositionValue.append("attachment; filename=")
|
||||||
|
.append(percentEncodedFileName)
|
||||||
|
.append(";")
|
||||||
|
.append("filename*=")
|
||||||
|
.append("utf-8''")
|
||||||
|
.append(percentEncodedFileName);
|
||||||
|
|
||||||
|
response.setHeader("Content-disposition", contentDispositionValue.toString());
|
||||||
|
response.setHeader("download-filename", percentEncodedFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 百分号编码工具方法
|
||||||
|
*
|
||||||
|
* @param s 需要百分号编码的字符串
|
||||||
|
* @return 百分号编码后的字符串
|
||||||
|
*/
|
||||||
|
public static String percentEncode(String s) throws UnsupportedEncodingException
|
||||||
|
{
|
||||||
|
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
|
||||||
|
return encode.replaceAll("\\+", "%20");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.ruoyi.common.core.utils.file;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片处理工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class ImageUtils
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ImageUtils.class);
|
||||||
|
|
||||||
|
public static byte[] getImage(String imagePath)
|
||||||
|
{
|
||||||
|
InputStream is = getFile(imagePath);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return IOUtils.toByteArray(is);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
log.error("图片加载异常 {}", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtils.closeQuietly(is);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InputStream getFile(String imagePath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] result = readFile(imagePath);
|
||||||
|
result = Arrays.copyOf(result, result.length);
|
||||||
|
return new ByteArrayInputStream(result);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
log.error("获取图片异常 {}", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取文件为字节数据
|
||||||
|
*
|
||||||
|
* @param key 地址
|
||||||
|
* @return 字节数据
|
||||||
|
*/
|
||||||
|
public static byte[] readFile(String url)
|
||||||
|
{
|
||||||
|
InputStream in = null;
|
||||||
|
ByteArrayOutputStream baos = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 网络地址
|
||||||
|
URL urlObj = new URL(url);
|
||||||
|
URLConnection urlConnection = urlObj.openConnection();
|
||||||
|
urlConnection.setConnectTimeout(30 * 1000);
|
||||||
|
urlConnection.setReadTimeout(60 * 1000);
|
||||||
|
urlConnection.setDoInput(true);
|
||||||
|
in = urlConnection.getInputStream();
|
||||||
|
return IOUtils.toByteArray(in);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
log.error("访问文件异常 {}", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtils.closeQuietly(in);
|
||||||
|
IOUtils.closeQuietly(baos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.ruoyi.common.core.utils.file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 媒体类型工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class MimeTypeUtils
|
||||||
|
{
|
||||||
|
public static final String IMAGE_PNG = "image/png";
|
||||||
|
|
||||||
|
public static final String IMAGE_JPG = "image/jpg";
|
||||||
|
|
||||||
|
public static final String IMAGE_JPEG = "image/jpeg";
|
||||||
|
|
||||||
|
public static final String IMAGE_BMP = "image/bmp";
|
||||||
|
|
||||||
|
public static final String IMAGE_GIF = "image/gif";
|
||||||
|
|
||||||
|
public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png" };
|
||||||
|
|
||||||
|
public static final String[] FLASH_EXTENSION = { "swf", "flv" };
|
||||||
|
|
||||||
|
public static final String[] MEDIA_EXTENSION = { "swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg",
|
||||||
|
"asf", "rm", "rmvb" };
|
||||||
|
|
||||||
|
public static final String[] VIDEO_EXTENSION = { "mp4", "avi", "rmvb" };
|
||||||
|
|
||||||
|
public static final String[] DEFAULT_ALLOWED_EXTENSION = {
|
||||||
|
// 图片
|
||||||
|
"bmp", "gif", "jpg", "jpeg", "png",
|
||||||
|
// word excel powerpoint
|
||||||
|
"doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
|
||||||
|
// 压缩文件
|
||||||
|
"rar", "zip", "gz", "bz2",
|
||||||
|
// 视频格式
|
||||||
|
"mp4", "avi", "rmvb",
|
||||||
|
// pdf
|
||||||
|
"pdf" };
|
||||||
|
|
||||||
|
public static String getExtension(String prefix)
|
||||||
|
{
|
||||||
|
switch (prefix)
|
||||||
|
{
|
||||||
|
case IMAGE_PNG:
|
||||||
|
return "png";
|
||||||
|
case IMAGE_JPG:
|
||||||
|
return "jpg";
|
||||||
|
case IMAGE_JPEG:
|
||||||
|
return "jpeg";
|
||||||
|
case IMAGE_BMP:
|
||||||
|
return "bmp";
|
||||||
|
case IMAGE_GIF:
|
||||||
|
return "gif";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
package com.ruoyi.common.core.utils.html;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转义和反转义工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class EscapeUtil
|
||||||
|
{
|
||||||
|
public static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
|
||||||
|
|
||||||
|
private static final char[][] TEXT = new char[64][];
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 64; i++)
|
||||||
|
{
|
||||||
|
TEXT[i] = new char[] { (char) i };
|
||||||
|
}
|
||||||
|
|
||||||
|
// special HTML characters
|
||||||
|
TEXT['\''] = "'".toCharArray(); // 单引号
|
||||||
|
TEXT['"'] = """.toCharArray(); // 双引号
|
||||||
|
TEXT['&'] = "&".toCharArray(); // &符
|
||||||
|
TEXT['<'] = "<".toCharArray(); // 小于号
|
||||||
|
TEXT['>'] = ">".toCharArray(); // 大于号
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转义文本中的HTML字符为安全的字符
|
||||||
|
*
|
||||||
|
* @param text 被转义的文本
|
||||||
|
* @return 转义后的文本
|
||||||
|
*/
|
||||||
|
public static String escape(String text)
|
||||||
|
{
|
||||||
|
return encode(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 还原被转义的HTML特殊字符
|
||||||
|
*
|
||||||
|
* @param content 包含转义符的HTML内容
|
||||||
|
* @return 转换后的字符串
|
||||||
|
*/
|
||||||
|
public static String unescape(String content)
|
||||||
|
{
|
||||||
|
return decode(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有HTML标签,但是不删除标签内的内容
|
||||||
|
*
|
||||||
|
* @param content 文本
|
||||||
|
* @return 清除标签后的文本
|
||||||
|
*/
|
||||||
|
public static String clean(String content)
|
||||||
|
{
|
||||||
|
return new HTMLFilter().filter(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape编码
|
||||||
|
*
|
||||||
|
* @param text 被编码的文本
|
||||||
|
* @return 编码后的字符
|
||||||
|
*/
|
||||||
|
private static String encode(String text)
|
||||||
|
{
|
||||||
|
if (StringUtils.isEmpty(text))
|
||||||
|
{
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringBuilder tmp = new StringBuilder(text.length() * 6);
|
||||||
|
char c;
|
||||||
|
for (int i = 0; i < text.length(); i++)
|
||||||
|
{
|
||||||
|
c = text.charAt(i);
|
||||||
|
if (c < 256)
|
||||||
|
{
|
||||||
|
tmp.append("%");
|
||||||
|
if (c < 16)
|
||||||
|
{
|
||||||
|
tmp.append("0");
|
||||||
|
}
|
||||||
|
tmp.append(Integer.toString(c, 16));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp.append("%u");
|
||||||
|
if (c <= 0xfff)
|
||||||
|
{
|
||||||
|
// issue#I49JU8@Gitee
|
||||||
|
tmp.append("0");
|
||||||
|
}
|
||||||
|
tmp.append(Integer.toString(c, 16));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tmp.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape解码
|
||||||
|
*
|
||||||
|
* @param content 被转义的内容
|
||||||
|
* @return 解码后的字符串
|
||||||
|
*/
|
||||||
|
public static String decode(String content)
|
||||||
|
{
|
||||||
|
if (StringUtils.isEmpty(content))
|
||||||
|
{
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder tmp = new StringBuilder(content.length());
|
||||||
|
int lastPos = 0, pos = 0;
|
||||||
|
char ch;
|
||||||
|
while (lastPos < content.length())
|
||||||
|
{
|
||||||
|
pos = content.indexOf("%", lastPos);
|
||||||
|
if (pos == lastPos)
|
||||||
|
{
|
||||||
|
if (content.charAt(pos + 1) == 'u')
|
||||||
|
{
|
||||||
|
ch = (char) Integer.parseInt(content.substring(pos + 2, pos + 6), 16);
|
||||||
|
tmp.append(ch);
|
||||||
|
lastPos = pos + 6;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ch = (char) Integer.parseInt(content.substring(pos + 1, pos + 3), 16);
|
||||||
|
tmp.append(ch);
|
||||||
|
lastPos = pos + 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pos == -1)
|
||||||
|
{
|
||||||
|
tmp.append(content.substring(lastPos));
|
||||||
|
lastPos = content.length();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp.append(content.substring(lastPos, pos));
|
||||||
|
lastPos = pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tmp.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
String html = "<script>alert(1);</script>";
|
||||||
|
String escape = EscapeUtil.escape(html);
|
||||||
|
// String html = "<scr<script>ipt>alert(\"XSS\")</scr<script>ipt>";
|
||||||
|
// String html = "<123";
|
||||||
|
// String html = "123>";
|
||||||
|
System.out.println("clean: " + EscapeUtil.clean(html));
|
||||||
|
System.out.println("escape: " + escape);
|
||||||
|
System.out.println("unescape: " + EscapeUtil.unescape(escape));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,570 @@
|
|||||||
|
package com.ruoyi.common.core.utils.html;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML过滤器,用于去除XSS漏洞隐患。
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public final class HTMLFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* regex flag union representing /si modifiers in php
|
||||||
|
**/
|
||||||
|
private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL;
|
||||||
|
private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL);
|
||||||
|
private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI);
|
||||||
|
private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL);
|
||||||
|
private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI);
|
||||||
|
private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI);
|
||||||
|
private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI);
|
||||||
|
private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI);
|
||||||
|
private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI);
|
||||||
|
private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?");
|
||||||
|
private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?");
|
||||||
|
private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?");
|
||||||
|
private static final Pattern P_VALID_ENTITIES = Pattern.compile("&([^&;]*)(?=(;|&|$))");
|
||||||
|
private static final Pattern P_VALID_QUOTES = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL);
|
||||||
|
private static final Pattern P_END_ARROW = Pattern.compile("^>");
|
||||||
|
private static final Pattern P_BODY_TO_END = Pattern.compile("<([^>]*?)(?=<|$)");
|
||||||
|
private static final Pattern P_XML_CONTENT = Pattern.compile("(^|>)([^<]*?)(?=>)");
|
||||||
|
private static final Pattern P_STRAY_LEFT_ARROW = Pattern.compile("<([^>]*?)(?=<|$)");
|
||||||
|
private static final Pattern P_STRAY_RIGHT_ARROW = Pattern.compile("(^|>)([^<]*?)(?=>)");
|
||||||
|
private static final Pattern P_AMP = Pattern.compile("&");
|
||||||
|
private static final Pattern P_QUOTE = Pattern.compile("\"");
|
||||||
|
private static final Pattern P_LEFT_ARROW = Pattern.compile("<");
|
||||||
|
private static final Pattern P_RIGHT_ARROW = Pattern.compile(">");
|
||||||
|
private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>");
|
||||||
|
|
||||||
|
// @xxx could grow large... maybe use sesat's ReferenceMap
|
||||||
|
private static final ConcurrentMap<String, Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>();
|
||||||
|
private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set of allowed html elements, along with allowed attributes for each element
|
||||||
|
**/
|
||||||
|
private final Map<String, List<String>> vAllowed;
|
||||||
|
/**
|
||||||
|
* counts of open tags for each (allowable) html element
|
||||||
|
**/
|
||||||
|
private final Map<String, Integer> vTagCounts = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* html elements which must always be self-closing (e.g. "<img />")
|
||||||
|
**/
|
||||||
|
private final String[] vSelfClosingTags;
|
||||||
|
/**
|
||||||
|
* html elements which must always have separate opening and closing tags (e.g. "<b></b>")
|
||||||
|
**/
|
||||||
|
private final String[] vNeedClosingTags;
|
||||||
|
/**
|
||||||
|
* set of disallowed html elements
|
||||||
|
**/
|
||||||
|
private final String[] vDisallowed;
|
||||||
|
/**
|
||||||
|
* attributes which should be checked for valid protocols
|
||||||
|
**/
|
||||||
|
private final String[] vProtocolAtts;
|
||||||
|
/**
|
||||||
|
* allowed protocols
|
||||||
|
**/
|
||||||
|
private final String[] vAllowedProtocols;
|
||||||
|
/**
|
||||||
|
* tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />")
|
||||||
|
**/
|
||||||
|
private final String[] vRemoveBlanks;
|
||||||
|
/**
|
||||||
|
* entities allowed within html markup
|
||||||
|
**/
|
||||||
|
private final String[] vAllowedEntities;
|
||||||
|
/**
|
||||||
|
* flag determining whether comments are allowed in input String.
|
||||||
|
*/
|
||||||
|
private final boolean stripComment;
|
||||||
|
private final boolean encodeQuotes;
|
||||||
|
/**
|
||||||
|
* flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>"
|
||||||
|
* becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped.
|
||||||
|
*/
|
||||||
|
private final boolean alwaysMakeTags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public HTMLFilter()
|
||||||
|
{
|
||||||
|
vAllowed = new HashMap<>();
|
||||||
|
|
||||||
|
final ArrayList<String> a_atts = new ArrayList<>();
|
||||||
|
a_atts.add("href");
|
||||||
|
a_atts.add("target");
|
||||||
|
vAllowed.put("a", a_atts);
|
||||||
|
|
||||||
|
final ArrayList<String> img_atts = new ArrayList<>();
|
||||||
|
img_atts.add("src");
|
||||||
|
img_atts.add("width");
|
||||||
|
img_atts.add("height");
|
||||||
|
img_atts.add("alt");
|
||||||
|
vAllowed.put("img", img_atts);
|
||||||
|
|
||||||
|
final ArrayList<String> no_atts = new ArrayList<>();
|
||||||
|
vAllowed.put("b", no_atts);
|
||||||
|
vAllowed.put("strong", no_atts);
|
||||||
|
vAllowed.put("i", no_atts);
|
||||||
|
vAllowed.put("em", no_atts);
|
||||||
|
|
||||||
|
vSelfClosingTags = new String[] { "img" };
|
||||||
|
vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" };
|
||||||
|
vDisallowed = new String[] {};
|
||||||
|
vAllowedProtocols = new String[] { "http", "mailto", "https" }; // no ftp.
|
||||||
|
vProtocolAtts = new String[] { "src", "href" };
|
||||||
|
vRemoveBlanks = new String[] { "a", "b", "strong", "i", "em" };
|
||||||
|
vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" };
|
||||||
|
stripComment = true;
|
||||||
|
encodeQuotes = true;
|
||||||
|
alwaysMakeTags = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map-parameter configurable constructor.
|
||||||
|
*
|
||||||
|
* @param conf map containing configuration. keys match field names.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public HTMLFilter(final Map<String, Object> conf)
|
||||||
|
{
|
||||||
|
|
||||||
|
assert conf.containsKey("vAllowed") : "configuration requires vAllowed";
|
||||||
|
assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags";
|
||||||
|
assert conf.containsKey("vNeedClosingTags") : "configuration requires vNeedClosingTags";
|
||||||
|
assert conf.containsKey("vDisallowed") : "configuration requires vDisallowed";
|
||||||
|
assert conf.containsKey("vAllowedProtocols") : "configuration requires vAllowedProtocols";
|
||||||
|
assert conf.containsKey("vProtocolAtts") : "configuration requires vProtocolAtts";
|
||||||
|
assert conf.containsKey("vRemoveBlanks") : "configuration requires vRemoveBlanks";
|
||||||
|
assert conf.containsKey("vAllowedEntities") : "configuration requires vAllowedEntities";
|
||||||
|
|
||||||
|
vAllowed = Collections.unmodifiableMap((HashMap<String, List<String>>) conf.get("vAllowed"));
|
||||||
|
vSelfClosingTags = (String[]) conf.get("vSelfClosingTags");
|
||||||
|
vNeedClosingTags = (String[]) conf.get("vNeedClosingTags");
|
||||||
|
vDisallowed = (String[]) conf.get("vDisallowed");
|
||||||
|
vAllowedProtocols = (String[]) conf.get("vAllowedProtocols");
|
||||||
|
vProtocolAtts = (String[]) conf.get("vProtocolAtts");
|
||||||
|
vRemoveBlanks = (String[]) conf.get("vRemoveBlanks");
|
||||||
|
vAllowedEntities = (String[]) conf.get("vAllowedEntities");
|
||||||
|
stripComment = conf.containsKey("stripComment") ? (Boolean) conf.get("stripComment") : true;
|
||||||
|
encodeQuotes = conf.containsKey("encodeQuotes") ? (Boolean) conf.get("encodeQuotes") : true;
|
||||||
|
alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reset()
|
||||||
|
{
|
||||||
|
vTagCounts.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// my versions of some PHP library functions
|
||||||
|
public static String chr(final int decimal)
|
||||||
|
{
|
||||||
|
return String.valueOf((char) decimal);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String htmlSpecialChars(final String s)
|
||||||
|
{
|
||||||
|
String result = s;
|
||||||
|
result = regexReplace(P_AMP, "&", result);
|
||||||
|
result = regexReplace(P_QUOTE, """, result);
|
||||||
|
result = regexReplace(P_LEFT_ARROW, "<", result);
|
||||||
|
result = regexReplace(P_RIGHT_ARROW, ">", result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given a user submitted input String, filter out any invalid or restricted html.
|
||||||
|
*
|
||||||
|
* @param input text (i.e. submitted by a user) than may contain html
|
||||||
|
* @return "clean" version of input, with only valid, whitelisted html elements allowed
|
||||||
|
*/
|
||||||
|
public String filter(final String input)
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
String s = input;
|
||||||
|
|
||||||
|
s = escapeComments(s);
|
||||||
|
|
||||||
|
s = balanceHTML(s);
|
||||||
|
|
||||||
|
s = checkTags(s);
|
||||||
|
|
||||||
|
s = processRemoveBlanks(s);
|
||||||
|
|
||||||
|
// s = validateEntities(s);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAlwaysMakeTags()
|
||||||
|
{
|
||||||
|
return alwaysMakeTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStripComments()
|
||||||
|
{
|
||||||
|
return stripComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String escapeComments(final String s)
|
||||||
|
{
|
||||||
|
final Matcher m = P_COMMENTS.matcher(s);
|
||||||
|
final StringBuffer buf = new StringBuffer();
|
||||||
|
if (m.find())
|
||||||
|
{
|
||||||
|
final String match = m.group(1); // (.*?)
|
||||||
|
m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
|
||||||
|
}
|
||||||
|
m.appendTail(buf);
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String balanceHTML(String s)
|
||||||
|
{
|
||||||
|
if (alwaysMakeTags)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// try and form html
|
||||||
|
//
|
||||||
|
s = regexReplace(P_END_ARROW, "", s);
|
||||||
|
// 不追加结束标签
|
||||||
|
s = regexReplace(P_BODY_TO_END, "<$1>", s);
|
||||||
|
s = regexReplace(P_XML_CONTENT, "$1<$2", s);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// escape stray brackets
|
||||||
|
//
|
||||||
|
s = regexReplace(P_STRAY_LEFT_ARROW, "<$1", s);
|
||||||
|
s = regexReplace(P_STRAY_RIGHT_ARROW, "$1$2><", s);
|
||||||
|
|
||||||
|
//
|
||||||
|
// the last regexp causes '<>' entities to appear
|
||||||
|
// (we need to do a lookahead assertion so that the last bracket can
|
||||||
|
// be used in the next pass of the regexp)
|
||||||
|
//
|
||||||
|
s = regexReplace(P_BOTH_ARROWS, "", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String checkTags(String s)
|
||||||
|
{
|
||||||
|
Matcher m = P_TAGS.matcher(s);
|
||||||
|
|
||||||
|
final StringBuffer buf = new StringBuffer();
|
||||||
|
while (m.find())
|
||||||
|
{
|
||||||
|
String replaceStr = m.group(1);
|
||||||
|
replaceStr = processTag(replaceStr);
|
||||||
|
m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr));
|
||||||
|
}
|
||||||
|
m.appendTail(buf);
|
||||||
|
|
||||||
|
// these get tallied in processTag
|
||||||
|
// (remember to reset before subsequent calls to filter method)
|
||||||
|
final StringBuilder sBuilder = new StringBuilder(buf.toString());
|
||||||
|
for (String key : vTagCounts.keySet())
|
||||||
|
{
|
||||||
|
for (int ii = 0; ii < vTagCounts.get(key); ii++)
|
||||||
|
{
|
||||||
|
sBuilder.append("</").append(key).append(">");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s = sBuilder.toString();
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String processRemoveBlanks(final String s)
|
||||||
|
{
|
||||||
|
String result = s;
|
||||||
|
for (String tag : vRemoveBlanks)
|
||||||
|
{
|
||||||
|
if (!P_REMOVE_PAIR_BLANKS.containsKey(tag))
|
||||||
|
{
|
||||||
|
P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?></" + tag + ">"));
|
||||||
|
}
|
||||||
|
result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result);
|
||||||
|
if (!P_REMOVE_SELF_BLANKS.containsKey(tag))
|
||||||
|
{
|
||||||
|
P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>"));
|
||||||
|
}
|
||||||
|
result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s)
|
||||||
|
{
|
||||||
|
Matcher m = regex_pattern.matcher(s);
|
||||||
|
return m.replaceAll(replacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String processTag(final String s)
|
||||||
|
{
|
||||||
|
// ending tags
|
||||||
|
Matcher m = P_END_TAG.matcher(s);
|
||||||
|
if (m.find())
|
||||||
|
{
|
||||||
|
final String name = m.group(1).toLowerCase();
|
||||||
|
if (allowed(name))
|
||||||
|
{
|
||||||
|
if (false == inArray(name, vSelfClosingTags))
|
||||||
|
{
|
||||||
|
if (vTagCounts.containsKey(name))
|
||||||
|
{
|
||||||
|
vTagCounts.put(name, vTagCounts.get(name) - 1);
|
||||||
|
return "</" + name + ">";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// starting tags
|
||||||
|
m = P_START_TAG.matcher(s);
|
||||||
|
if (m.find())
|
||||||
|
{
|
||||||
|
final String name = m.group(1).toLowerCase();
|
||||||
|
final String body = m.group(2);
|
||||||
|
String ending = m.group(3);
|
||||||
|
|
||||||
|
// debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" );
|
||||||
|
if (allowed(name))
|
||||||
|
{
|
||||||
|
final StringBuilder params = new StringBuilder();
|
||||||
|
|
||||||
|
final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body);
|
||||||
|
final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body);
|
||||||
|
final List<String> paramNames = new ArrayList<>();
|
||||||
|
final List<String> paramValues = new ArrayList<>();
|
||||||
|
while (m2.find())
|
||||||
|
{
|
||||||
|
paramNames.add(m2.group(1)); // ([a-z0-9]+)
|
||||||
|
paramValues.add(m2.group(3)); // (.*?)
|
||||||
|
}
|
||||||
|
while (m3.find())
|
||||||
|
{
|
||||||
|
paramNames.add(m3.group(1)); // ([a-z0-9]+)
|
||||||
|
paramValues.add(m3.group(3)); // ([^\"\\s']+)
|
||||||
|
}
|
||||||
|
|
||||||
|
String paramName, paramValue;
|
||||||
|
for (int ii = 0; ii < paramNames.size(); ii++)
|
||||||
|
{
|
||||||
|
paramName = paramNames.get(ii).toLowerCase();
|
||||||
|
paramValue = paramValues.get(ii);
|
||||||
|
|
||||||
|
// debug( "paramName='" + paramName + "'" );
|
||||||
|
// debug( "paramValue='" + paramValue + "'" );
|
||||||
|
// debug( "allowed? " + vAllowed.get( name ).contains( paramName ) );
|
||||||
|
|
||||||
|
if (allowedAttribute(name, paramName))
|
||||||
|
{
|
||||||
|
if (inArray(paramName, vProtocolAtts))
|
||||||
|
{
|
||||||
|
paramValue = processParamProtocol(paramValue);
|
||||||
|
}
|
||||||
|
params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inArray(name, vSelfClosingTags))
|
||||||
|
{
|
||||||
|
ending = " /";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inArray(name, vNeedClosingTags))
|
||||||
|
{
|
||||||
|
ending = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ending == null || ending.length() < 1)
|
||||||
|
{
|
||||||
|
if (vTagCounts.containsKey(name))
|
||||||
|
{
|
||||||
|
vTagCounts.put(name, vTagCounts.get(name) + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vTagCounts.put(name, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ending = " /";
|
||||||
|
}
|
||||||
|
return "<" + name + params + ending + ">";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// comments
|
||||||
|
m = P_COMMENT.matcher(s);
|
||||||
|
if (!stripComment && m.find())
|
||||||
|
{
|
||||||
|
return "<" + m.group() + ">";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String processParamProtocol(String s)
|
||||||
|
{
|
||||||
|
s = decodeEntities(s);
|
||||||
|
final Matcher m = P_PROTOCOL.matcher(s);
|
||||||
|
if (m.find())
|
||||||
|
{
|
||||||
|
final String protocol = m.group(1);
|
||||||
|
if (!inArray(protocol, vAllowedProtocols))
|
||||||
|
{
|
||||||
|
// bad protocol, turn into local anchor link instead
|
||||||
|
s = "#" + s.substring(protocol.length() + 1);
|
||||||
|
if (s.startsWith("#//"))
|
||||||
|
{
|
||||||
|
s = "#" + s.substring(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String decodeEntities(String s)
|
||||||
|
{
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
|
Matcher m = P_ENTITY.matcher(s);
|
||||||
|
while (m.find())
|
||||||
|
{
|
||||||
|
final String match = m.group(1);
|
||||||
|
final int decimal = Integer.decode(match).intValue();
|
||||||
|
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
||||||
|
}
|
||||||
|
m.appendTail(buf);
|
||||||
|
s = buf.toString();
|
||||||
|
|
||||||
|
buf = new StringBuffer();
|
||||||
|
m = P_ENTITY_UNICODE.matcher(s);
|
||||||
|
while (m.find())
|
||||||
|
{
|
||||||
|
final String match = m.group(1);
|
||||||
|
final int decimal = Integer.valueOf(match, 16).intValue();
|
||||||
|
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
||||||
|
}
|
||||||
|
m.appendTail(buf);
|
||||||
|
s = buf.toString();
|
||||||
|
|
||||||
|
buf = new StringBuffer();
|
||||||
|
m = P_ENCODE.matcher(s);
|
||||||
|
while (m.find())
|
||||||
|
{
|
||||||
|
final String match = m.group(1);
|
||||||
|
final int decimal = Integer.valueOf(match, 16).intValue();
|
||||||
|
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
||||||
|
}
|
||||||
|
m.appendTail(buf);
|
||||||
|
s = buf.toString();
|
||||||
|
|
||||||
|
s = validateEntities(s);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String validateEntities(final String s)
|
||||||
|
{
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
|
// validate entities throughout the string
|
||||||
|
Matcher m = P_VALID_ENTITIES.matcher(s);
|
||||||
|
while (m.find())
|
||||||
|
{
|
||||||
|
final String one = m.group(1); // ([^&;]*)
|
||||||
|
final String two = m.group(2); // (?=(;|&|$))
|
||||||
|
m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two)));
|
||||||
|
}
|
||||||
|
m.appendTail(buf);
|
||||||
|
|
||||||
|
return encodeQuotes(buf.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String encodeQuotes(final String s)
|
||||||
|
{
|
||||||
|
if (encodeQuotes)
|
||||||
|
{
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
Matcher m = P_VALID_QUOTES.matcher(s);
|
||||||
|
while (m.find())
|
||||||
|
{
|
||||||
|
final String one = m.group(1); // (>|^)
|
||||||
|
final String two = m.group(2); // ([^<]+?)
|
||||||
|
final String three = m.group(3); // (<|$)
|
||||||
|
// 不替换双引号为",防止json格式无效 regexReplace(P_QUOTE, """, two)
|
||||||
|
m.appendReplacement(buf, Matcher.quoteReplacement(one + two + three));
|
||||||
|
}
|
||||||
|
m.appendTail(buf);
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String checkEntity(final String preamble, final String term)
|
||||||
|
{
|
||||||
|
|
||||||
|
return ";".equals(term) && isValidEntity(preamble) ? '&' + preamble : "&" + preamble;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isValidEntity(final String entity)
|
||||||
|
{
|
||||||
|
return inArray(entity, vAllowedEntities);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean inArray(final String s, final String[] array)
|
||||||
|
{
|
||||||
|
for (String item : array)
|
||||||
|
{
|
||||||
|
if (item != null && item.equals(s))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean allowed(final String name)
|
||||||
|
{
|
||||||
|
return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean allowedAttribute(final String name, final String paramName)
|
||||||
|
{
|
||||||
|
return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,11 @@ public class IpUtils
|
|||||||
{
|
{
|
||||||
public static String getIpAddr(HttpServletRequest request)
|
public static String getIpAddr(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
|
if (request == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String ip = null;
|
String ip = null;
|
||||||
|
|
||||||
// X-Forwarded-For:Squid 服务代理
|
// X-Forwarded-For:Squid 服务代理
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.ruoyi.common.core.utils.poi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excel数据格式处理适配器
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public interface ExcelHandlerAdapter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 格式化
|
||||||
|
*
|
||||||
|
* @param value 单元格数据值
|
||||||
|
* @param args excel注解args参数组
|
||||||
|
*
|
||||||
|
* @return 处理后的值
|
||||||
|
*/
|
||||||
|
Object format(Object value, String[] args);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user