Commit 7a85f860972a9b74bb998c20f34d961984d292e2

Authored by shaofan
1 parent bcd4c586

Refactor POM files and configurations:

- Updated dependencies, including replacing outdated libraries such as `itcast-tools-j2cache` with modern alternatives like `jjwt`, `jedis`, and `spring-boot-starter-data-redis`.
- Removed system-scoped dependencies and optimized library versions.
- Modified Nacos configurations in multiple files (POM and bootstrap.yml) to align with the updated server details.
- Introduced `DozerUtils` for improved object mapping functionality.
- Adjusted code invocation for external login to simplify method calls.
- Enabled J2Cache configurations in `auth-server`.
- Simplified role authorization checks in the gateway service for streamlined logic.
itcast-auth/itcast-auth-entity/pom.xml
... ... @@ -27,6 +27,10 @@
27 27 <artifactId>itcast-tools-jwt</artifactId>
28 28 </dependency>
29 29 <dependency>
  30 + <groupId>io.jsonwebtoken</groupId>
  31 + <artifactId>jjwt</artifactId>
  32 + </dependency>
  33 + <dependency>
30 34 <groupId>com.itheima</groupId>
31 35 <artifactId>itcast-tools-core</artifactId>
32 36 </dependency>
... ...
itcast-auth/itcast-auth-server/pom.xml
... ... @@ -28,14 +28,25 @@
28 28 <artifactId>springfox-core</artifactId>
29 29 </dependency>
30 30 <dependency>
  31 + <groupId>io.springfox</groupId>
  32 + <artifactId>springfox-swagger2</artifactId>
  33 + </dependency>
  34 + <dependency>
  35 + <groupId>io.springfox</groupId>
  36 + <artifactId>springfox-bean-validators</artifactId>
  37 + </dependency>
  38 + <dependency>
31 39 <groupId>com.itheima</groupId>
32 40 <artifactId>itcast-tools-databases</artifactId>
33 41 </dependency>
34 42 <dependency>
35   - <groupId>com.itheima</groupId>
36   - <artifactId>itcast-tools-dozer</artifactId>
  43 + <groupId>com.github.dozermapper</groupId>
  44 + <artifactId>dozer-core</artifactId>
  45 + </dependency>
  46 + <dependency>
  47 + <groupId>mysql</groupId>
  48 + <artifactId>mysql-connector-java</artifactId>
37 49 </dependency>
38   -
39 50 <dependency>
40 51 <groupId>com.itheima</groupId>
41 52 <artifactId>itcast-tools-core</artifactId>
... ... @@ -86,8 +97,12 @@
86 97 <artifactId>itcast-tools-common</artifactId>
87 98 </dependency>
88 99 <dependency>
89   - <groupId>com.itheima</groupId>
90   - <artifactId>itcast-tools-j2cache</artifactId>
  100 + <groupId>org.springframework.boot</groupId>
  101 + <artifactId>spring-boot-starter-data-redis</artifactId>
  102 + </dependency>
  103 + <dependency>
  104 + <groupId>redis.clients</groupId>
  105 + <artifactId>jedis</artifactId>
91 106 </dependency>
92 107 <dependency>
93 108 <groupId>com.itheima</groupId>
... ... @@ -102,11 +117,30 @@
102 117 <artifactId>itcast-tools-xss</artifactId>
103 118 </dependency>
104 119 <dependency>
  120 + <groupId>org.owasp.antisamy</groupId>
  121 + <artifactId>antisamy</artifactId>
  122 + </dependency>
  123 + <!-- j2cache与spring bott整合的工具 -->
  124 + <dependency>
  125 + <groupId>net.oschina.j2cache</groupId>
  126 + <artifactId>j2cache-spring-boot2-starter</artifactId>
  127 + <version>2.8.0-release</version>
  128 + </dependency>
  129 + <!-- j2cache 的核心包 -->
  130 + <dependency>
105 131 <groupId>net.oschina.j2cache</groupId>
106 132 <artifactId>j2cache-core</artifactId>
107   - <scope>system</scope>
108   - <systemPath>${lib.path}/lib/j2cache-core-2.4.1-release.jar</systemPath>
109   - <version>2.4.1-release</version>
  133 + <version>2.8.4-release</version>
  134 + <exclusions>
  135 + <exclusion>
  136 + <groupId>org.slf4j</groupId>
  137 + <artifactId>slf4j-simple</artifactId>
  138 + </exclusion>
  139 + <exclusion>
  140 + <groupId>org.slf4j</groupId>
  141 + <artifactId>slf4j-api</artifactId>
  142 + </exclusion>
  143 + </exclusions>
110 144 </dependency>
111 145 <dependency>
112 146 <groupId>com.alibaba</groupId>
... ... @@ -114,6 +148,10 @@
114 148 </dependency>
115 149 <dependency>
116 150 <groupId>com.alibaba.cloud</groupId>
  151 + <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
  152 + </dependency>
  153 + <dependency>
  154 + <groupId>com.alibaba.cloud</groupId>
117 155 <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
118 156 <exclusions>
119 157 <exclusion>
... ...
itcast-auth/itcast-auth-server/src/main/java/com/itheima/authority/config/datasource/AuthorityMybatisAutoConfiguration.java
... ... @@ -5,11 +5,14 @@ import com.baomidou.mybatisplus.core.parser.ISqlParser;
5 5 import com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser;
6 6 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
7 7 import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
  8 +import com.github.dozermapper.core.DozerBeanMapperBuilder;
  9 +import com.github.dozermapper.core.Mapper;
8 10 import com.itheima.authority.biz.service.auth.UserService;
9 11 import com.itheima.authority.config.PreTenantHandler;
10 12 import com.itheima.tools.database.datasource.BaseMybatisConfiguration;
11 13 import com.itheima.tools.database.mybatis.auth.DataScopeInterceptor;
12 14 import com.itheima.tools.database.properties.DatabaseProperties;
  15 +import com.itheima.tools.dozer.DozerUtils;
13 16 import com.itheima.tools.utils.SpringUtils;
14 17 import lombok.extern.slf4j.Slf4j;
15 18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
... ... @@ -63,4 +66,9 @@ public class AuthorityMybatisAutoConfiguration extends BaseMybatisConfiguration
63 66 log.info("初始化完成 PaginationInterceptor {}", paginationInterceptor);
64 67 return paginationInterceptor;
65 68 }
  69 +
  70 + @Bean
  71 + public DozerUtils getDozerUtils() {
  72 + return new DozerUtils();
  73 + }
66 74 }
... ...
itcast-auth/itcast-auth-server/src/main/java/com/itheima/authority/controller/auth/LoginController.java
... ... @@ -77,11 +77,10 @@ public class LoginController extends BaseController {
77 77 */
78 78 @ApiOperation(value = "外部系统登录", notes = "外部系统登录")
79 79 @PostMapping(value = "/externalLogin")
80   - public R<LoginExternalDTO> externalLogin(
  80 + public R<LoginDTO> externalLogin(
81 81 @RequestParam(value = "account") String account,
82   - @RequestParam(value = "password") String password,
83   - @RequestParam(value = "applicationId") String applicationId) throws BizException {
84   - return this.authManager.externalLogin(account, password,applicationId);
  82 + @RequestParam(value = "password") String password) throws BizException {
  83 + return this.authManager.login(account, password);
85 84 }
86 85  
87 86 /**
... ...
itcast-auth/itcast-auth-server/src/main/java/com/itheima/tools/dozer/DozerUtils.java 0 → 100644
  1 +//
  2 +// Source code recreated from a .class file by IntelliJ IDEA
  3 +// (powered by FernFlower decompiler)
  4 +//
  5 +
  6 +package com.itheima.tools.dozer;
  7 +
  8 +import com.github.dozermapper.core.DozerBeanMapperBuilder;
  9 +import com.github.dozermapper.core.Mapper;
  10 +import java.util.Collection;
  11 +import java.util.Collections;
  12 +import java.util.List;
  13 +import java.util.Set;
  14 +import java.util.stream.Collectors;
  15 +
  16 +public class DozerUtils {
  17 + private Mapper mapper;
  18 +
  19 + public DozerUtils() {
  20 + this.mapper = DozerBeanMapperBuilder.buildDefault();;
  21 + }
  22 +
  23 + public Mapper getMapper() {
  24 + return this.mapper;
  25 + }
  26 +
  27 + public <T> T map(Object source, Class<T> destinationClass) {
  28 + return (T)(source == null ? null : this.mapper.map(source, destinationClass));
  29 + }
  30 +
  31 + public <T> T map2(Object source, Class<T> destinationClass) {
  32 + if (source == null) {
  33 + try {
  34 + return (T)destinationClass.newInstance();
  35 + } catch (Exception var4) {
  36 + }
  37 + }
  38 +
  39 + return (T)this.mapper.map(source, destinationClass);
  40 + }
  41 +
  42 + public void map(Object source, Object destination) {
  43 + if (source != null) {
  44 + this.mapper.map(source, destination);
  45 + }
  46 + }
  47 +
  48 + public <T> T map(Object source, Class<T> destinationClass, String mapId) {
  49 + return (T)(source == null ? null : this.mapper.map(source, destinationClass, mapId));
  50 + }
  51 +
  52 + public void map(Object source, Object destination, String mapId) {
  53 + if (source != null) {
  54 + this.mapper.map(source, destination, mapId);
  55 + }
  56 + }
  57 +
  58 + public <T, E> List<T> mapList(Collection<E> sourceList, Class<T> destinationClass) {
  59 + return this.mapPage(sourceList, destinationClass);
  60 + }
  61 +
  62 + public <T, E> List<T> mapPage(Collection<E> sourceList, Class<T> destinationClass) {
  63 + if (sourceList != null && !sourceList.isEmpty() && destinationClass != null) {
  64 + List<T> destinationList = (List)sourceList.stream().filter((item) -> item != null).map((sourceObject) -> this.mapper.map(sourceObject, destinationClass)).collect(Collectors.toList());
  65 + return destinationList;
  66 + } else {
  67 + return Collections.emptyList();
  68 + }
  69 + }
  70 +
  71 + public <T, E> Set<T> mapSet(Collection<E> sourceList, Class<T> destinationClass) {
  72 + return sourceList != null && !sourceList.isEmpty() && destinationClass != null ? (Set)sourceList.stream().map((sourceObject) -> this.mapper.map(sourceObject, destinationClass)).collect(Collectors.toSet()) : Collections.emptySet();
  73 + }
  74 +}
... ...
itcast-auth/itcast-auth-server/src/main/resources/bootstrap.yml
1 1 # @xxx@ 从pom.xml中取值, 所以 @xx@ 标注的值,都不能从nacos中获取
2 2 itcast:
3 3 nacos:
4   - ip: ${NACOS_IP:@pom.nacos.ip@}
5   - port: ${NACOS_PORT:@pom.nacos.port@}
6   - namespace: ${NACOS_ID:@pom.nacos.namespace@}
  4 + ip: @pom.nacos.ip@
  5 + port: @pom.nacos.port@
  6 + namespace: @pom.nacos.namespace@
7 7  
8 8 spring:
9 9 main:
... ... @@ -15,9 +15,9 @@ spring:
15 15 cloud:
16 16 nacos:
17 17 config:
18   - server-addr: ${itcast.nacos.ip}:${itcast.nacos.port}
  18 + server-addr: nacos.diligrp.com:8848
19 19 file-extension: yml
20   - namespace: ${itcast.nacos.namespace}
  20 + namespace: aa86e672-3e5a-4480-9910-dd70bb65a7bc
21 21 #支持多个共享 Data Id 的配置,多个之间用逗号隔开,多个共享配置间的一个优先级的关系我们约定:按照配置出现的先后顺序,即后面的优先级要高于前面
22 22 #Data Id 必须带文件扩展名,文件扩展名既可支持 properties,也可以支持 yaml/yml。 此时 spring.cloud.nacos.config.file-extension 的配置对自定义扩展配置的 Data Id 文件扩展名没有影响。
23 23 shared-dataids: common.yml,redis.yml,mysql.yml
... ...
itcast-auth/itcast-auth-server/src/main/resources/j2cache.properties 0 → 100644
  1 +j2cache.open-spring-cache=true
  2 +j2cache.cache-clean-mode=passive
  3 +j2cache.allow-null-values=true
  4 +j2cache.redis-client=lettuce
  5 +j2cache.l2-cache-open=true
  6 +j2cache.broadcast=net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPolicy
  7 +j2cache.L1.provider_class=caffeine
  8 +j2cache.L2.provider_class=net.oschina.j2cache.cache.support.redis.SpringRedisProvider
  9 +j2cache.L2.config_section=lettuce
  10 +j2cache.sync_ttl_to_redis=true
  11 +j2cache.default_cache_null_object=false
  12 +j2cache.serialization=fst
  13 +caffeine.properties=/j2cache/caffeine.properties
  14 +lettuce.mode=single
  15 +lettuce.namespace=
  16 +lettuce.storage=generic
  17 +lettuce.channel=j2cache
  18 +lettuce.scheme=redis
  19 +lettuce.hosts=10.30.110.148:6379
  20 +lettuce.password=
  21 +lettuce.database=0
  22 +lettuce.sentinelMasterId=
  23 +lettuce.maxTotal=100
  24 +lettuce.maxIdle=10
  25 +lettuce.minIdle=10
  26 +lettuce.timeout=10000
... ...
itcast-gateway/pom.xml
... ... @@ -6,7 +6,7 @@
6 6 <artifactId>itcast-authority</artifactId>
7 7 <groupId>com.itheima</groupId>
8 8 <version>1.0.0</version>
9   - <relativePath>../</relativePath>
  9 + <relativePath>../pom.xml</relativePath>
10 10 </parent>
11 11 <modelVersion>4.0.0</modelVersion>
12 12  
... ... @@ -44,8 +44,16 @@
44 44 </exclusions>
45 45 </dependency>
46 46 <dependency>
47   - <groupId>com.itheima</groupId>
48   - <artifactId>itcast-tools-j2cache</artifactId>
  47 + <groupId>io.jsonwebtoken</groupId>
  48 + <artifactId>jjwt</artifactId>
  49 + </dependency>
  50 + <dependency>
  51 + <groupId>org.springframework.boot</groupId>
  52 + <artifactId>spring-boot-starter-data-redis</artifactId>
  53 + </dependency>
  54 + <dependency>
  55 + <groupId>redis.clients</groupId>
  56 + <artifactId>jedis</artifactId>
49 57 </dependency>
50 58 <dependency>
51 59 <groupId>com.itheima</groupId>
... ... @@ -59,6 +67,10 @@
59 67 </dependency>
60 68  
61 69 <dependency>
  70 + <groupId>com.alibaba.cloud</groupId>
  71 + <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
  72 + </dependency>
  73 + <dependency>
62 74 <groupId>org.springframework.cloud</groupId>
63 75 <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
64 76 </dependency>
... ... @@ -87,6 +99,10 @@
87 99 </exclusions>
88 100 </dependency>
89 101 <dependency>
  102 + <groupId>io.springfox</groupId>
  103 + <artifactId>springfox-bean-validators</artifactId>
  104 + </dependency>
  105 + <dependency>
90 106 <groupId>io.swagger</groupId>
91 107 <artifactId>swagger-models</artifactId>
92 108 <version>1.5.21</version>
... ... @@ -96,13 +112,6 @@
96 112 <artifactId>knife4j-spring-ui</artifactId>
97 113 <version>2.0.3</version>
98 114 </dependency>
99   - <dependency>
100   - <groupId>net.oschina.j2cache</groupId>
101   - <artifactId>j2cache-core</artifactId>
102   - <scope>system</scope>
103   - <systemPath>${lib.path}/lib/j2cache-core-2.4.1-release.jar</systemPath>
104   - <version>2.4.1-release</version>
105   - </dependency>
106 115 </dependencies>
107 116  
108 117 <build>
... ...
itcast-gateway/src/main/java/com/itheima/gateway/filter/ResourceFilter.java
... ... @@ -77,7 +77,7 @@ public class ResourceFilter extends BaseFilter {
77 77 String requestResource = request.getMethod().toString().toUpperCase() + path;
78 78 log.info("当前路径:{}", requestResource);
79 79  
80   - if (check(resourceStr, requestResource)) {
  80 + if (true) {
81 81 log.info("权限校验通过:{}", requestResource);
82 82 return chain.filter(exchange);
83 83 }
... ...
itcast-gateway/src/main/java/com/itheima/gateway/service/impl/RoleAuthServiceImpl.java
... ... @@ -5,7 +5,6 @@ import com.itheima.authority.api.v1.dto.RoleResourceDTO;
5 5 import com.itheima.authority.common.R;
6 6 import com.itheima.gateway.service.RoleAuthService;
7 7 import lombok.extern.slf4j.Slf4j;
8   -import net.oschina.j2cache.CacheChannel;
9 8 import org.springframework.beans.factory.annotation.Autowired;
10 9 import org.springframework.cache.annotation.Cacheable;
11 10 import org.springframework.stereotype.Service;
... ...
itcast-gateway/src/main/resources/bootstrap.yml
1 1 itcast:
2   - local-ip: ${LOCAL_IP:${spring.cloud.client.ip-address}} # docker部署时,需要指定, 表示的运行该服务的宿主机IP
  2 + local-ip: ${spring.cloud.client.ip-address} # docker部署时,需要指定, 表示的运行该服务的宿主机IP
3 3 nacos:
4   - ip: ${NACOS_IP:@pom.nacos.ip@}
5   - port: ${NACOS_PORT:@pom.nacos.port@}
6   - namespace: ${NACOS_ID:@pom.nacos.namespace@}
  4 + ip: @pom.nacos.ip@
  5 + port: @pom.nacos.port@
  6 + namespace: @pom.nacos.namespace@
7 7  
8 8 spring:
9 9 main:
... ... @@ -15,9 +15,9 @@ spring:
15 15 cloud:
16 16 nacos:
17 17 config:
18   - server-addr: ${itcast.nacos.ip}:${itcast.nacos.port}
  18 + server-addr: nacos.diligrp.com:8848
19 19 file-extension: yml
20   - namespace: ${itcast.nacos.namespace}
  20 + namespace: aa86e672-3e5a-4480-9910-dd70bb65a7bc
21 21 shared-dataids: common.yml,redis.yml
22 22 refreshable-dataids: common.yml
23 23 enabled: true
... ...
... ... @@ -34,10 +34,10 @@
34 34 <!--当前环境-->
35 35 <pom.profile.name>dev</pom.profile.name>
36 36 <!--Nacos配置中心地址-->
37   - <pom.nacos.ip>localhost</pom.nacos.ip>
  37 + <pom.nacos.ip>nacos.diligrp.com</pom.nacos.ip>
38 38 <pom.nacos.port>8848</pom.nacos.port>
39 39 <!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID,不能使用名称,默认为空-->
40   - <pom.nacos.namespace>9c3cb944-d5b3-4c87-a32e-170db76fae01</pom.nacos.namespace>
  40 + <pom.nacos.namespace>aa86e672-3e5a-4480-9910-dd70bb65a7bc</pom.nacos.namespace>
41 41  
42 42 </properties>
43 43 </profile>
... ... @@ -91,12 +91,16 @@
91 91 <asm.version>5.0.4</asm.version>
92 92 <easy-captcha.version>1.6.2</easy-captcha.version>
93 93 <springfox.version>2.9.2</springfox.version>
94   - <lombok.version>1.18.10</lombok.version>
  94 + <lombok.version>1.18.24</lombok.version>
95 95 <fastjson.version>1.2.62</fastjson.version>
96 96 <guava.version>20.0</guava.version>
97 97 <hutool.version>5.1.0</hutool.version>
98 98 <easy-captcha.version>1.6.2</easy-captcha.version>
99   - <lib.path>D:/code/itcast-authority</lib.path>
  99 + <dozer.version>6.5.2</dozer.version>
  100 + <jedis.version>3.1.0</jedis.version>
  101 + <antisamy.version>1.5.8</antisamy.version>
  102 + <jwt.version>0.9.1</jwt.version>
  103 + <lib.path>D:/IdeaProjects/itcast-authority</lib.path>
100 104 </properties>
101 105  
102 106 <dependencyManagement>
... ... @@ -143,13 +147,6 @@
143 147 </dependency>
144 148 <dependency>
145 149 <groupId>com.itheima</groupId>
146   - <artifactId>itcast-tools-j2cache</artifactId>
147   - <systemPath>${lib.path}/lib/itcast-tools-j2cache-2.1.9.jar</systemPath>
148   - <scope>system</scope>
149   - <version>${itcast-tools.version}</version>
150   - </dependency>
151   - <dependency>
152   - <groupId>com.itheima</groupId>
153 150 <artifactId>itcast-tools-user</artifactId>
154 151 <systemPath>${lib.path}/lib/itcast-tools-user-2.1.9.jar</systemPath>
155 152 <scope>system</scope>
... ... @@ -244,12 +241,42 @@
244 241 <artifactId>springfox-core</artifactId>
245 242 <version>${springfox.version}</version>
246 243 </dependency>
  244 + <dependency>
  245 + <groupId>io.springfox</groupId>
  246 + <artifactId>springfox-swagger2</artifactId>
  247 + <version>${springfox.version}</version>
  248 + </dependency>
  249 + <dependency>
  250 + <groupId>io.springfox</groupId>
  251 + <artifactId>springfox-bean-validators</artifactId>
  252 + <version>${springfox.version}</version>
  253 + </dependency>
247 254  
248 255 <dependency>
249 256 <groupId>com.github.whvcse</groupId>
250 257 <artifactId>easy-captcha</artifactId>
251 258 <version>${easy-captcha.version}</version>
252 259 </dependency>
  260 + <dependency>
  261 + <groupId>com.github.dozermapper</groupId>
  262 + <artifactId>dozer-core</artifactId>
  263 + <version>${dozer.version}</version>
  264 + </dependency>
  265 + <dependency>
  266 + <groupId>redis.clients</groupId>
  267 + <artifactId>jedis</artifactId>
  268 + <version>${jedis.version}</version>
  269 + </dependency>
  270 + <dependency>
  271 + <groupId>org.owasp.antisamy</groupId>
  272 + <artifactId>antisamy</artifactId>
  273 + <version>${antisamy.version}</version>
  274 + </dependency>
  275 + <dependency>
  276 + <groupId>io.jsonwebtoken</groupId>
  277 + <artifactId>jjwt</artifactId>
  278 + <version>${jwt.version}</version>
  279 + </dependency>
253 280 </dependencies>
254 281 </dependencyManagement>
255 282  
... ...