From 42e55f0d06fd9468e80202330bab785c78e09f4d Mon Sep 17 00:00:00 2001 From: zhuyijun Date: Wed, 21 Sep 2022 20:14:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Epostgresql=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/{ => mysql}/nacos.sql | 0 db/{ => mysql}/zyjblogs_rbac.sql | 4 +- db/postgres/zyjblogs_rbac.sql | 65 +++++ pom.xml | 5 + .../{gateway => }/GatewayApplication.java | 2 +- .../{gateway => }/filter/AuthFilter.java | 2 +- .../filter/WhiteListProperties.java | 2 +- .../{oauth => }/OauthApplication.java | 4 +- .../handler/ResourceAccessDeniedHandler.java | 2 +- .../ResourceAuthenticationEntryPoint.java | 2 +- .../config/rsa/OauthAutoConfiguration.java | 2 +- .../config/rsa/RsaKeyProperties.java | 2 +- .../AuthorizationServerConfiguration.java | 13 +- .../config/security/JwtTokenConfig.java | 4 +- .../config/security/JwtTokenEnhancer.java | 4 +- .../security/OauthAccessTokenConverter.java | 2 +- .../security/OauthAuthenticationProvider.java | 18 +- .../OauthResponseExceptionTranslator.java | 2 +- .../OauthUserAuthenticationConverter.java | 7 +- .../security/PasswordEncoderConfig.java | 2 +- .../config/security/ResourceServerConfig.java | 6 +- .../security/WebSecurityConfiguration.java | 4 +- .../server/user/po/OauthClientDetail.java | 78 ----- .../server/user/service/LoginService.java | 56 ---- .../client/constant/ClientConstant.java | 8 + .../mapper/OauthClientDetailsMapper.java | 12 + .../server/client/po/OauthClientDetail.java | 275 ++++++++++++++++++ .../impl/OauthClientDetailsServiceImpl.java | 79 +++++ .../server/demo/DemoController.java | 2 +- .../server/user/constant/CommonConstant.java | 2 +- .../server/user/constant/LoginEnum.java | 37 +++ .../server/user/constant/UserEnum.java | 2 +- .../user/controller/AutoController.java} | 35 +-- .../user/controller/LoginController.java | 36 +++ .../server/user/dto/AuthorizationCodeDto.java | 2 +- .../server/user/dto/OAuth2AccessTokenDto.java | 2 +- .../server/user/dto/UserLoginDto.java | 8 +- .../server/user/mapper/UserMapper.java | 4 +- .../server/user/po/OauthUserDetails.java | 6 +- .../{oauth => }/server/user/po/Role.java | 2 +- .../{oauth => }/server/user/po/UserPo.java | 14 +- .../server/user/service/AuthService.java | 33 +++ .../server/user/service/LoginService.java | 31 ++ .../server/user/service/UserService.java | 4 +- .../user/service/impl/AuthServiceImpl.java} | 84 +----- .../user/service/impl/LoginServiceImpl.java | 78 +++++ .../impl/OauthUserDetailsServiceImpl.java | 13 +- .../user/service/impl/UserServiceImpl.java | 11 +- .../server/user/vo/OAuth2AccessTokenVo.java | 20 +- .../src/main/resources/bootstrap.yml | 8 +- .../main/resources/mapper/user/UserMapper.xml | 14 + .../zyjblogs/{rbac => }/RbacApplication.java | 2 +- .../role/controller/RoleController.java | 10 +- .../server/role/dto/RolePageDto.java | 2 +- .../server/role/mapper/RoleMapper.java | 8 +- .../{rbac => }/server/role/po/RolePo.java | 11 +- .../server/role/service/RoleService.java | 8 +- .../role/service/impl/RoleServiceImpl.java | 12 +- .../{rbac => }/server/role/vo/RoleVo.java | 11 +- .../user/controller/UserController.java | 10 +- .../server/user/dto/UserPageDto.java | 2 +- .../server/user/mapper/UserMapper.java | 8 +- .../{rbac => }/server/user/po/UserPo.java | 14 +- .../server/user/service/UserService.java | 8 +- .../user/service/impl/UserServiceImpl.java | 12 +- .../{rbac => }/server/user/vo/UserVo.java | 12 +- .../src/main/resources/bootstrap.yml | 6 + .../main/resources/mapper/role/RoleMapper.xml | 4 +- .../main/resources/mapper/user/UserMapper.xml | 34 ++- .../pom.xml | 4 + .../MyBatisPlusConfig.java | 2 +- .../main/resources/META-INF/spring.factories | 2 +- .../pom.xml | 4 + .../GenericJackson2JsonRedisSerializerEx.java | 65 +++++ .../starter/redis/config/RedisConfig.java | 16 +- .../zyjblogs-web-spring-boot-starter/pom.xml | 4 + ...obalExceptionHandlerAutoConfiguration.java | 21 ++ .../web/hander/GlobalExceptionHandler.java | 59 ++-- .../main/resources/META-INF/spring.factories | 4 +- 79 files changed, 1065 insertions(+), 400 deletions(-) rename db/{ => mysql}/nacos.sql (100%) rename db/{ => mysql}/zyjblogs_rbac.sql (57%) create mode 100644 db/postgres/zyjblogs_rbac.sql rename server/zyjblogs-gateway/src/main/java/cn/zyjblogs/{gateway => }/GatewayApplication.java (96%) rename server/zyjblogs-gateway/src/main/java/cn/zyjblogs/{gateway => }/filter/AuthFilter.java (99%) rename server/zyjblogs-gateway/src/main/java/cn/zyjblogs/{gateway => }/filter/WhiteListProperties.java (88%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/OauthApplication.java (82%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/handler/ResourceAccessDeniedHandler.java (96%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/handler/ResourceAuthenticationEntryPoint.java (96%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/rsa/OauthAutoConfiguration.java (88%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/rsa/RsaKeyProperties.java (92%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/AuthorizationServerConfiguration.java (91%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/JwtTokenConfig.java (95%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/JwtTokenEnhancer.java (94%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/OauthAccessTokenConverter.java (97%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/OauthAuthenticationProvider.java (82%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/OauthResponseExceptionTranslator.java (97%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/OauthUserAuthenticationConverter.java (90%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/PasswordEncoderConfig.java (93%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/ResourceServerConfig.java (92%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/config/security/WebSecurityConfiguration.java (95%) delete mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/OauthClientDetail.java delete mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/LoginService.java create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/constant/ClientConstant.java create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/mapper/OauthClientDetailsMapper.java create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/po/OauthClientDetail.java create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/service/impl/OauthClientDetailsServiceImpl.java rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/demo/DemoController.java (92%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/constant/CommonConstant.java (76%) create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/LoginEnum.java rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/constant/UserEnum.java (85%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth/server/user/controller/LoginController.java => server/user/controller/AutoController.java} (52%) create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/controller/LoginController.java rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/dto/AuthorizationCodeDto.java (93%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/dto/OAuth2AccessTokenDto.java (91%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/dto/UserLoginDto.java (73%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/mapper/UserMapper.java (67%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/po/OauthUserDetails.java (95%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/po/Role.java (92%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/po/UserPo.java (77%) create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/AuthService.java create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/LoginService.java rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/service/UserService.java (56%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth/server/user/service/impl/LoginServiceImpl.java => server/user/service/impl/AuthServiceImpl.java} (51%) create mode 100644 server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/LoginServiceImpl.java rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/service/impl/OauthUserDetailsServiceImpl.java (77%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/service/impl/UserServiceImpl.java (56%) rename server/zyjblogs-oauth/src/main/java/cn/zyjblogs/{oauth => }/server/user/vo/OAuth2AccessTokenVo.java (68%) create mode 100644 server/zyjblogs-oauth/src/main/resources/mapper/user/UserMapper.xml rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/RbacApplication.java (95%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/role/controller/RoleController.java (89%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/role/dto/RolePageDto.java (97%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/role/mapper/RoleMapper.java (78%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/role/po/RolePo.java (71%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/role/service/RoleService.java (74%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/role/service/impl/RoleServiceImpl.java (84%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/role/vo/RoleVo.java (71%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/user/controller/UserController.java (89%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/user/dto/UserPageDto.java (94%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/user/mapper/UserMapper.java (81%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/user/po/UserPo.java (77%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/user/service/UserService.java (78%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/user/service/impl/UserServiceImpl.java (84%) rename server/zyjblogs-rbac/src/main/java/cn/zyjblogs/{rbac => }/server/user/vo/UserVo.java (65%) rename stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/{config => autoconfigure}/MyBatisPlusConfig.java (97%) create mode 100644 stater/zyjblogs-redis-spring-boot-starter/src/main/java/cn/zyjblogs/starter/redis/config/GenericJackson2JsonRedisSerializerEx.java create mode 100644 stater/zyjblogs-web-spring-boot-starter/src/main/java/cn/zyjblogs/starter/web/autoconfig/GlobalExceptionHandlerAutoConfiguration.java diff --git a/db/nacos.sql b/db/mysql/nacos.sql similarity index 100% rename from db/nacos.sql rename to db/mysql/nacos.sql diff --git a/db/zyjblogs_rbac.sql b/db/mysql/zyjblogs_rbac.sql similarity index 57% rename from db/zyjblogs_rbac.sql rename to db/mysql/zyjblogs_rbac.sql index a437476..9656867 100644 --- a/db/zyjblogs_rbac.sql +++ b/db/mysql/zyjblogs_rbac.sql @@ -72,7 +72,7 @@ CREATE TABLE `oauth_code` ( LOCK TABLES `oauth_code` WRITE; /*!40000 ALTER TABLE `oauth_code` DISABLE KEYS */; -INSERT INTO `oauth_code` (`create_time`, `code`, `authentication`) VALUES ('2022-08-18 01:01:55','AeocBw',_binary '¬\í\0sr\0Aorg.springframework.security.oauth2.provider.OAuth2Authentication½@ bR\0L\0\rstoredRequestt\0£qi½\0L\0clientIdq\0~\0L\0requestParametersq\0~\0L\0scopeq\0~\0xpt\0\rzyjblogs-rbacsr\0%java.util.Collections$UnmodifiableMap\ñ¥¨þt\õB\0L\0mq\0~\0xpsr\0java.util.HashMap\ÚÁ\Ã`\Ñ\0F\0\nloadFactorI\0 thresholdxp?@\0\0\0\0\0w\0\0\0\0\0\0t\0\rresponse_typet\0codet\0 client_idq\0~\0t\0 redirect_urlt\0https://www.baidu.comt\0scopet\0allxsr\0%java.util.Collections$UnmodifiableSet€’Ñ›€U\0\0xq\0~\0 sr\0java.util.LinkedHashSet\Øl\×Z•\Ý*\0\0xr\0java.util.HashSetºD…•–¸·4\0\0xpw \0\0\0?@\0\0\0\0\0q\0~\0xsq\0~\0#w \0\0\0?@\0\0\0\0\0\0xsq\0~\0?@\0\0\0\0\0\0w\0\0\0\0\0\0\0xt\0http://localhost:9029/psq\0~\0#w \0\0\0?@\0\0\0\0\0t\0\rzyjblogs-rbacxsq\0~\0#w \0\0\0?@\0\0\0\0\0q\0~\0\Zxsr\0Oorg.springframework.security.authentication.UsernamePasswordAuthenticationToken\0\0\0\0\0\0\0L\0 credentialsq\0~\0L\0 principalq\0~\0xq\0~\0sr\0java.util.Collections$EmptyListz¸´<§ž\Þ\0\0xpsr\0Horg.springframework.security.web.authentication.WebAuthenticationDetails\0\0\0\0\0\0\0L\0\rremoteAddressq\0~\0L\0 sessionIdq\0~\0xpt\0 127.0.0.1t\0 8702DE5790D13DA3689E435D6CA9DAC6psr\01cn.zyjblogs.oauth.server.user.po.OauthUserDetailsš¼\ÂI\Ù\êY“\0Z\0accountNonExpiredZ\0accountNonLockedZ\0credentialsNonExpiredZ\0enabledL\0 authoritiesq\0~\0L\0deletedt\0Ljava/lang/Integer;L\0emailq\0~\0L\0idq\0~\0L\0 inviteUserIdq\0~\0L\0nameq\0~\0L\0passwordq\0~\0L\0phoneq\0~\04L\0statusq\0~\04L\0usernameq\0~\0xppsr\0java.lang.Integerâ ¤\÷‡8\0I\0valuexr\0java.lang.Number†¬• ”\à‹\0\0xp\0\0\0\0pt\01pt\0admint\0<$2a$10$4DlfvZrq7zgKzkbKyg.GHO6yHdGnozcaf3B5JSAC0fNB4k1GhMk6ypq\0~\08t\0admin'); +INSERT INTO `oauth_code` (`create_time`, `code`, `authentication`) VALUES ('2022-08-18 01:01:55','AeocBw',_binary '¬\í\0sr\0Aorg.springframework.security.oauth2.provider.OAuth2Authentication½@ bR\0L\0\rstoredRequestt\0£qi½\0L\0clientIdq\0~\0L\0requestParametersq\0~\0L\0scopeq\0~\0xpt\0\rzyjblogs-rbacsr\0%java.util.Collections$UnmodifiableMap\ñ¥¨þt\õB\0L\0mq\0~\0xpsr\0java.util.HashMap\ÚÁ\Ã`\Ñ\0F\0\nloadFactorI\0 thresholdxp?@\0\0\0\0\0w\0\0\0\0\0\0t\0\rresponse_typet\0codet\0 client_idq\0~\0t\0 redirect_urlt\0https://www.baidu.comt\0scopet\0allxsr\0%java.util.Collections$UnmodifiableSet€’Ñ›€U\0\0xq\0~\0 sr\0java.util.LinkedHashSet\Øl\×Z•\Ý*\0\0xr\0java.util.HashSetºD…•–¸·4\0\0xpw \0\0\0?@\0\0\0\0\0q\0~\0xsq\0~\0#w \0\0\0?@\0\0\0\0\0\0xsq\0~\0?@\0\0\0\0\0\0w\0\0\0\0\0\0\0xt\0http://localhost:9029/psq\0~\0#w \0\0\0?@\0\0\0\0\0t\0\rzyjblogs-rbacxsq\0~\0#w \0\0\0?@\0\0\0\0\0q\0~\0\Zxsr\0Oorg.springframework.security.authentication.UsernamePasswordAuthenticationToken\0\0\0\0\0\0\0L\0 credentialsq\0~\0L\0 principalq\0~\0xq\0~\0sr\0java.util.Collections$EmptyListz¸´<§ž\Þ\0\0xpsr\0Horg.springframework.security.web.authentication.WebAuthenticationDetails\0\0\0\0\0\0\0L\0\rremoteAddressq\0~\0L\0 sessionIdq\0~\0xpt\0 127.0.0.1t\0 8702DE5790D13DA3689E435D6CA9DAC6psr\01cn.zyjblogs.oauth.server.user.po.OauthUserDetailsš¼\ÂI\Ù\êY“\0Z\0accountNonExpiredZ\0accountNonLockedZ\0credentialsNonExpiredZ\0enabledL\0 authoritiesq\0~\0L\0deletedt\0Ljava/lang/Integer;L\0emailq\0~\0L\0idq\0~\0L\0 inviteUserIdq\0~\0L\0nameq\0~\0L\0passwordq\0~\0L\0phoneq\0~\04L\0statusq\0~\04L\0usernameq\0~\0xppsr\0java.lang.Integerâ ¤\÷‡8\0I\0valuexr\0java.lang.Number†¬• ”\à‹\0\0xp\0\0\0\0pt\01pt\0admint\0<$2a$10$4DlfvZrq7zgKzkbKyg.GHO6yHdGnozcaf3B5JSAC0fNB4k1GhMk6ypq\0~\08t\0admin'),('2022-09-20 14:01:28','ukIZFS',_binary '¬\í\0sr\0Aorg.springframework.security.oauth2.provider.OAuth2Authentication½@ bR\0L\0\rstoredRequestt\0£qi½\0L\0clientIdq\0~\0L\0requestParametersq\0~\0L\0scopeq\0~\0xpt\0\rzyjblogs-rbacsr\0%java.util.Collections$UnmodifiableMap\ñ¥¨þt\õB\0L\0mq\0~\0xpsr\0java.util.HashMap\ÚÁ\Ã`\Ñ\0F\0\nloadFactorI\0 thresholdxp?@\0\0\0\0\0w\0\0\0\0\0\0t\0\rresponse_typet\0codet\0\rclient_secrett\0secrett\0 client_idq\0~\0t\0 redirect_urlt\0https://www.baidu.comt\0scopet\0allxsr\0%java.util.Collections$UnmodifiableSet€’Ñ›€U\0\0xq\0~\0 sr\0java.util.LinkedHashSet\Øl\×Z•\Ý*\0\0xr\0java.util.HashSetºD…•–¸·4\0\0xpw \0\0\0?@\0\0\0\0\0q\0~\0!xsq\0~\0%w \0\0\0?@\0\0\0\0\0\0xsq\0~\0?@\0\0\0\0\0\0w\0\0\0\0\0\0\0xt\0http://localhost:9029/psq\0~\0%w \0\0\0?@\0\0\0\0\0t\0zyjblogs-oautht\0\rzyjblogs-rbacxsq\0~\0%w \0\0\0?@\0\0\0\0\0q\0~\0\Zxsr\0Oorg.springframework.security.authentication.UsernamePasswordAuthenticationToken\0\0\0\0\0\0\0L\0 credentialsq\0~\0L\0 principalq\0~\0xq\0~\0sq\0~\0sq\0~\0 \0\0\0\0w\0\0\0\0xq\0~\01sr\0Horg.springframework.security.web.authentication.WebAuthenticationDetails\0\0\0\0\0\0\0L\0\rremoteAddressq\0~\0L\0 sessionIdq\0~\0xpt\0 127.0.0.1t\0 6B46F217663FE8A97841CE456FC6F71Cpsr\01cn.zyjblogs.oauth.server.user.po.OauthUserDetails\'¥‹€3•Á\0Z\0accountNonExpiredZ\0accountNonLockedZ\0credentialsNonExpiredZ\0enabledL\0 authoritiesq\0~\0L\0deletedt\0Ljava/lang/Integer;L\0emailq\0~\0L\0idq\0~\0L\0 inviteUserIdq\0~\0L\0nameq\0~\0L\0passwordq\0~\0L\0phoneq\0~\0L\0statusq\0~\07L\0tenantIdq\0~\0L\0usernameq\0~\0xppsr\0java.lang.Integerâ ¤\÷‡8\0I\0valuexr\0java.lang.Number†¬• ”\à‹\0\0xp\0\0\0\0pt\01pt\0admint\0<$2a$10$4DlfvZrq7zgKzkbKyg.GHO6yHdGnozcaf3B5JSAC0fNB4k1GhMk6ypq\0~\0;t\0\0t\0admin'),('2022-09-20 14:01:40','qbpSY7',_binary '¬\í\0sr\0Aorg.springframework.security.oauth2.provider.OAuth2Authentication½@ bR\0L\0\rstoredRequestt\0£qi½\0L\0clientIdq\0~\0L\0requestParametersq\0~\0L\0scopeq\0~\0xpt\0\rzyjblogs-rbacsr\0%java.util.Collections$UnmodifiableMap\ñ¥¨þt\õB\0L\0mq\0~\0xpsr\0java.util.HashMap\ÚÁ\Ã`\Ñ\0F\0\nloadFactorI\0 thresholdxp?@\0\0\0\0\0w\0\0\0\0\0\0t\0\rresponse_typet\0codet\0\rclient_secrett\0secrett\0 client_idq\0~\0t\0 redirect_urlt\0https://www.baidu.comt\0scopet\0allxsr\0%java.util.Collections$UnmodifiableSet€’Ñ›€U\0\0xq\0~\0 sr\0java.util.LinkedHashSet\Øl\×Z•\Ý*\0\0xr\0java.util.HashSetºD…•–¸·4\0\0xpw \0\0\0?@\0\0\0\0\0q\0~\0!xsq\0~\0%w \0\0\0?@\0\0\0\0\0\0xsq\0~\0?@\0\0\0\0\0\0w\0\0\0\0\0\0\0xt\0http://localhost:9029/psq\0~\0%w \0\0\0?@\0\0\0\0\0t\0zyjblogs-oautht\0\rzyjblogs-rbacxsq\0~\0%w \0\0\0?@\0\0\0\0\0q\0~\0\Zxsr\0Oorg.springframework.security.authentication.UsernamePasswordAuthenticationToken\0\0\0\0\0\0\0L\0 credentialsq\0~\0L\0 principalq\0~\0xq\0~\0sq\0~\0sq\0~\0 \0\0\0\0w\0\0\0\0xq\0~\01sr\0Horg.springframework.security.web.authentication.WebAuthenticationDetails\0\0\0\0\0\0\0L\0\rremoteAddressq\0~\0L\0 sessionIdq\0~\0xpt\0 127.0.0.1t\0 6B46F217663FE8A97841CE456FC6F71Cpsr\01cn.zyjblogs.oauth.server.user.po.OauthUserDetails\'¥‹€3•Á\0Z\0accountNonExpiredZ\0accountNonLockedZ\0credentialsNonExpiredZ\0enabledL\0 authoritiesq\0~\0L\0deletedt\0Ljava/lang/Integer;L\0emailq\0~\0L\0idq\0~\0L\0 inviteUserIdq\0~\0L\0nameq\0~\0L\0passwordq\0~\0L\0phoneq\0~\0L\0statusq\0~\07L\0tenantIdq\0~\0L\0usernameq\0~\0xppsr\0java.lang.Integerâ ¤\÷‡8\0I\0valuexr\0java.lang.Number†¬• ”\à‹\0\0xp\0\0\0\0pt\01pt\0admint\0<$2a$10$4DlfvZrq7zgKzkbKyg.GHO6yHdGnozcaf3B5JSAC0fNB4k1GhMk6ypq\0~\0;t\0\0t\0admin'),('2022-09-20 14:02:21','1XeJUa',_binary '¬\í\0sr\0Aorg.springframework.security.oauth2.provider.OAuth2Authentication½@ bR\0L\0\rstoredRequestt\0£qi½\0L\0clientIdq\0~\0L\0requestParametersq\0~\0L\0scopeq\0~\0xpt\0zyjblogs-oauthsr\0%java.util.Collections$UnmodifiableMap\ñ¥¨þt\õB\0L\0mq\0~\0xpsr\0java.util.HashMap\ÚÁ\Ã`\Ñ\0F\0\nloadFactorI\0 thresholdxp?@\0\0\0\0\0w\0\0\0\0\0\0t\0\rresponse_typet\0codet\0\rclient_secrett\0secrett\0 client_idq\0~\0t\0 redirect_urlt\0https://www.baidu.comt\0scopet\0allxsr\0%java.util.Collections$UnmodifiableSet€’Ñ›€U\0\0xq\0~\0 sr\0java.util.LinkedHashSet\Øl\×Z•\Ý*\0\0xr\0java.util.HashSetºD…•–¸·4\0\0xpw \0\0\0?@\0\0\0\0\0q\0~\0!xsq\0~\0%w \0\0\0?@\0\0\0\0\0\0xsq\0~\0?@\0\0\0\0\0\0w\0\0\0\0\0\0\0xt\0http://localhost:9019/psq\0~\0%w \0\0\0?@\0\0\0\0\0t\0zyjblogs-oautht\0\rzyjblogs-rbacxsq\0~\0%w \0\0\0?@\0\0\0\0\0q\0~\0\Zxsr\0Oorg.springframework.security.authentication.UsernamePasswordAuthenticationToken\0\0\0\0\0\0\0L\0 credentialsq\0~\0L\0 principalq\0~\0xq\0~\0sq\0~\0sq\0~\0 \0\0\0\0w\0\0\0\0xq\0~\01sr\0Horg.springframework.security.web.authentication.WebAuthenticationDetails\0\0\0\0\0\0\0L\0\rremoteAddressq\0~\0L\0 sessionIdq\0~\0xpt\0 127.0.0.1t\0 6B46F217663FE8A97841CE456FC6F71Cpsr\01cn.zyjblogs.oauth.server.user.po.OauthUserDetails\'¥‹€3•Á\0Z\0accountNonExpiredZ\0accountNonLockedZ\0credentialsNonExpiredZ\0enabledL\0 authoritiesq\0~\0L\0deletedt\0Ljava/lang/Integer;L\0emailq\0~\0L\0idq\0~\0L\0 inviteUserIdq\0~\0L\0nameq\0~\0L\0passwordq\0~\0L\0phoneq\0~\0L\0statusq\0~\07L\0tenantIdq\0~\0L\0usernameq\0~\0xppsr\0java.lang.Integerâ ¤\÷‡8\0I\0valuexr\0java.lang.Number†¬• ”\à‹\0\0xp\0\0\0\0pt\01pt\0admint\0<$2a$10$4DlfvZrq7zgKzkbKyg.GHO6yHdGnozcaf3B5JSAC0fNB4k1GhMk6ypq\0~\0;t\0\0t\0admin'); /*!40000 ALTER TABLE `oauth_code` ENABLE KEYS */; UNLOCK TABLES; @@ -157,4 +157,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-09-19 19:12:23 +-- Dump completed on 2022-09-21 13:16:39 diff --git a/db/postgres/zyjblogs_rbac.sql b/db/postgres/zyjblogs_rbac.sql new file mode 100644 index 0000000..60270c3 --- /dev/null +++ b/db/postgres/zyjblogs_rbac.sql @@ -0,0 +1,65 @@ + +CREATE TABLE oauth_client_details ( + client_id varchar(255) NOT NULL, + resource_ids varchar(255) DEFAULT NULL, + client_secret varchar(255) DEFAULT NULL, + scope varchar(255) DEFAULT NULL, + authorized_grant_types varchar(255) DEFAULT NULL, + web_server_redirect_uri varchar(255) DEFAULT NULL, + authorities varchar(255) DEFAULT NULL, + access_token_validity int DEFAULT NULL, + refresh_token_validity int DEFAULT NULL, + additional_information text , + create_time timestamp WITH TIME ZONE NOT NULL DEFAULT NOW(), + archived smallint DEFAULT 0, + trusted smallint DEFAULT 0, + autoapprove varchar(255) DEFAULT 'false', + PRIMARY KEY (client_id) +); +INSERT INTO oauth_client_details (client_id, resource_ids, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, create_time, archived, trusted, autoapprove) VALUES ('zyjblogs-oauth','zyjblogs-oauth,zyjblogs-rbac','$2a$10$Wk2w4OX5DpFgG3rBuhPnnulCSOIuU3TZhpWjaOq39LZnL.p0LJila','all','authorization_code,password,client_credentials,implicit,refresh_token','http://localhost:9019/',NULL,NULL,NULL,NULL,'2022-08-18 06:14:32',0,0,'false'),('zyjblogs-rbac','zyjblogs-rbac,zyjblogs-oauth','$2a$10$Wk2w4OX5DpFgG3rBuhPnnulCSOIuU3TZhpWjaOq39LZnL.p0LJila','all','authorization_code,password,client_credentials,implicit,refresh_token','http://localhost:9029/',NULL,NULL,NULL,NULL,'2022-08-18 00:34:24',0,0,'false'); + +CREATE TABLE oauth_code ( + create_time timestamp WITH TIME ZONE NOT NULL DEFAULT NOW(), + code varchar(255) DEFAULT NULL, + authentication bytea +) ; +create index code_index on oauth_code(code); + +CREATE TABLE role ( + id varchar(64) NOT NULL, + name varchar(64) DEFAULT NULL , + status int DEFAULT NULL , + deleted smallint DEFAULT 0, + description varchar(600) , + create_user_id varchar(64) , + create_time timestamp WITH TIME ZONE NOT NULL DEFAULT NOW(), + edit_user_id varchar(64) , + edit_time timestamp WITH TIME ZONE NOT NULL DEFAULT NOW(), + tenant_id varchar(100) NOT NULL DEFAULT '', + PRIMARY KEY (id) +); + +CREATE TABLE "user" ( + id varchar(64) NOT NULL , + username varchar(64) NOT NULL , + name varchar(64) DEFAULT NULL , + age int DEFAULT NULL , + avatar varchar(255) DEFAULT NULL , + password varchar(255) DEFAULT NULL, + phone char(11) DEFAULT NULL , + email varchar(64) DEFAULT NULL , + invite_user_id varchar(64) DEFAULT NULL , + status int DEFAULT NULL , + follow_num int DEFAULT NULL , + fans_num int DEFAULT NULL , + deleted smallint DEFAULT 0, + description varchar(600) DEFAULT NULL, + create_user_id varchar(64) , + create_time timestamp WITH TIME ZONE NOT NULL DEFAULT NOW(), + edit_user_id varchar(64) , + edit_time timestamp WITH TIME ZONE NOT NULL DEFAULT NOW(), + tenant_id varchar(100) NOT NULL DEFAULT '', + PRIMARY KEY (id) +); +create index username_index on "user"(username); +INSERT INTO "user" (id, username, name, age, avatar, password, phone, email, invite_user_id, status, follow_num, fans_num, deleted, description, create_user_id, create_time, edit_user_id, edit_time, tenant_id) VALUES ('1','admin','admin',1,NULL,'$2a$10$4DlfvZrq7zgKzkbKyg.GHO6yHdGnozcaf3B5JSAC0fNB4k1GhMk6y',NULL,NULL,NULL,0,NULL,NULL,0,NULL,NULL,now(),NULL,now(),''); diff --git a/pom.xml b/pom.xml index 8adf519..abf496a 100644 --- a/pom.xml +++ b/pom.xml @@ -106,6 +106,11 @@ jackson-annotations ${jackson.version} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + com.fasterxml.jackson.core jackson-databind diff --git a/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/GatewayApplication.java b/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/GatewayApplication.java similarity index 96% rename from server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/GatewayApplication.java rename to server/zyjblogs-gateway/src/main/java/cn/zyjblogs/GatewayApplication.java index ee4645f..b03ab87 100644 --- a/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/GatewayApplication.java +++ b/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/GatewayApplication.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.gateway; +package cn.zyjblogs; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/AuthFilter.java b/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/filter/AuthFilter.java similarity index 99% rename from server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/AuthFilter.java rename to server/zyjblogs-gateway/src/main/java/cn/zyjblogs/filter/AuthFilter.java index 50eeb8a..02c7786 100644 --- a/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/AuthFilter.java +++ b/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/filter/AuthFilter.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.gateway.filter; +package cn.zyjblogs.filter; import cn.zyjblogs.starter.common.entity.constant.HttpHeaderConstant; import cn.zyjblogs.starter.common.entity.response.ResponseObject; diff --git a/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/WhiteListProperties.java b/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/filter/WhiteListProperties.java similarity index 88% rename from server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/WhiteListProperties.java rename to server/zyjblogs-gateway/src/main/java/cn/zyjblogs/filter/WhiteListProperties.java index 6e2b86b..c33a06e 100644 --- a/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/WhiteListProperties.java +++ b/server/zyjblogs-gateway/src/main/java/cn/zyjblogs/filter/WhiteListProperties.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.gateway.filter; +package cn.zyjblogs.filter; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/OauthApplication.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/OauthApplication.java similarity index 82% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/OauthApplication.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/OauthApplication.java index 933ce0e..354ba96 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/OauthApplication.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/OauthApplication.java @@ -1,7 +1,5 @@ -package cn.zyjblogs.oauth; +package cn.zyjblogs; -import org.mybatis.spring.annotation.MapperScan; -import org.mybatis.spring.annotation.MapperScans; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/handler/ResourceAccessDeniedHandler.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/handler/ResourceAccessDeniedHandler.java similarity index 96% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/handler/ResourceAccessDeniedHandler.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/handler/ResourceAccessDeniedHandler.java index b5addea..1477351 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/handler/ResourceAccessDeniedHandler.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/handler/ResourceAccessDeniedHandler.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.config.handler; +package cn.zyjblogs.config.handler; import cn.zyjblogs.starter.common.entity.response.HttpCode; import cn.zyjblogs.starter.common.entity.response.ResponseResult; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/handler/ResourceAuthenticationEntryPoint.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/handler/ResourceAuthenticationEntryPoint.java similarity index 96% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/handler/ResourceAuthenticationEntryPoint.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/handler/ResourceAuthenticationEntryPoint.java index 39e012e..f55bbc7 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/handler/ResourceAuthenticationEntryPoint.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/handler/ResourceAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.config.handler; +package cn.zyjblogs.config.handler; import cn.zyjblogs.starter.common.entity.response.HttpCode; import cn.zyjblogs.starter.common.entity.response.ResponseResult; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/rsa/OauthAutoConfiguration.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/rsa/OauthAutoConfiguration.java similarity index 88% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/rsa/OauthAutoConfiguration.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/rsa/OauthAutoConfiguration.java index 8cccd0e..b3a02e4 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/rsa/OauthAutoConfiguration.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/rsa/OauthAutoConfiguration.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.config.rsa; +package cn.zyjblogs.config.rsa; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/rsa/RsaKeyProperties.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/rsa/RsaKeyProperties.java similarity index 92% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/rsa/RsaKeyProperties.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/rsa/RsaKeyProperties.java index 69deb50..1f7939a 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/rsa/RsaKeyProperties.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/rsa/RsaKeyProperties.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.config.rsa; +package cn.zyjblogs.config.rsa; import lombok.Getter; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/AuthorizationServerConfiguration.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/AuthorizationServerConfiguration.java similarity index 91% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/AuthorizationServerConfiguration.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/AuthorizationServerConfiguration.java index 8ba328c..bb68be5 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/AuthorizationServerConfiguration.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/AuthorizationServerConfiguration.java @@ -1,18 +1,16 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.provider.ClientDetailsService; -import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService; import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices; import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices; import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; @@ -37,11 +35,10 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu private final TokenStore tokenStore; private final AuthenticationManager authenticationManager; private final JwtAccessTokenConverter accessTokenConverter; - private final PasswordEncoder passwordEncoder; private final DataSource dataSource; private final JwtTokenEnhancer jwtTokenEnhancer; private final OauthResponseExceptionTranslator oAuthResponseExceptionTranslator; - + private final ClientDetailsService oauthClientDetailsService; /** * ä»¤ç‰Œç«¯ç‚¹çš„å®‰å…¨çº¦æŸ * @@ -123,9 +120,9 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu @Bean public ClientDetailsService clientDetails(DataSource dataSource) { - JdbcClientDetailsService jdbcClientDetailsService = new JdbcClientDetailsService(dataSource); - jdbcClientDetailsService.setPasswordEncoder(passwordEncoder); - return jdbcClientDetailsService; +// JdbcClientDetailsService jdbcClientDetailsService = new JdbcClientDetailsService(dataSource); +// jdbcClientDetailsService.setPasswordEncoder(passwordEncoder); + return oauthClientDetailsService; } @Bean diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/JwtTokenConfig.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/JwtTokenConfig.java similarity index 95% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/JwtTokenConfig.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/JwtTokenConfig.java index d188f27..866c76c 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/JwtTokenConfig.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/JwtTokenConfig.java @@ -1,6 +1,6 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; -import cn.zyjblogs.oauth.config.rsa.RsaKeyProperties; +import cn.zyjblogs.config.rsa.RsaKeyProperties; import lombok.RequiredArgsConstructor; import org.apache.commons.io.IOUtils; import org.springframework.context.annotation.Bean; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/JwtTokenEnhancer.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/JwtTokenEnhancer.java similarity index 94% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/JwtTokenEnhancer.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/JwtTokenEnhancer.java index f8367c8..5a37799 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/JwtTokenEnhancer.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/JwtTokenEnhancer.java @@ -1,6 +1,6 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; -import cn.zyjblogs.oauth.server.user.po.OauthUserDetails; +import cn.zyjblogs.server.user.po.OauthUserDetails; import cn.zyjblogs.starter.common.entity.constant.ContextKeyConstant; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2AccessToken; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthAccessTokenConverter.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthAccessTokenConverter.java similarity index 97% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthAccessTokenConverter.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthAccessTokenConverter.java index 71c50e9..68ddadc 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthAccessTokenConverter.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthAccessTokenConverter.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; import cn.zyjblogs.starter.common.entity.constant.ContextKeyConstant; import cn.zyjblogs.starter.common.entity.context.BaseContext; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthAuthenticationProvider.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthAuthenticationProvider.java similarity index 82% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthAuthenticationProvider.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthAuthenticationProvider.java index 608cb35..b392b70 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthAuthenticationProvider.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthAuthenticationProvider.java @@ -1,21 +1,17 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; -import cn.zyjblogs.oauth.server.user.po.OauthUserDetails; -import lombok.RequiredArgsConstructor; +import cn.zyjblogs.server.user.po.OauthUserDetails; +import cn.zyjblogs.starter.common.entity.response.HttpCode; +import cn.zyjblogs.starter.common.exception.AuthRuntimeException; import lombok.extern.log4j.Log4j2; import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.authentication.DisabledException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; @@ -50,7 +46,7 @@ public class OauthAuthenticationProvider extends DaoAuthenticationProvider { UserDetails user = userDetailsService.loadUserByUsername(username); if (user == null){ this.logger.debug("用户ä¸å­˜åœ¨"); - throw new RuntimeException("用户ä¸å­˜åœ¨"); + throw new AuthRuntimeException(HttpCode.UNAUTHORIZED,"用户ä¸å­˜åœ¨"); } OauthUserDetails userDetails = (OauthUserDetails) user; //比较å‰ç«¯ä¼ å…¥çš„密ç æ˜Žæ–‡å’Œæ•°æ®åº“中加密的密ç æ˜¯å¦ç›¸ç­‰ @@ -60,9 +56,7 @@ public class OauthAuthenticationProvider extends DaoAuthenticationProvider { } //获å–用户æƒé™ä¿¡æ¯ Collection authorities = userDetails.getAuthorities(); - authorities.forEach(x -> { - log.info("{}", x); - }); + authorities.forEach(x -> log.info("{}", x)); return new UsernamePasswordAuthenticationToken(userDetails, password, authorities); } diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthResponseExceptionTranslator.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthResponseExceptionTranslator.java similarity index 97% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthResponseExceptionTranslator.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthResponseExceptionTranslator.java index d9cf681..510f9fc 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthResponseExceptionTranslator.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthResponseExceptionTranslator.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthUserAuthenticationConverter.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthUserAuthenticationConverter.java similarity index 90% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthUserAuthenticationConverter.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthUserAuthenticationConverter.java index f47e3f1..58a1cd0 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/OauthUserAuthenticationConverter.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/OauthUserAuthenticationConverter.java @@ -1,15 +1,12 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; +import cn.zyjblogs.server.user.po.OauthUserDetails; import cn.zyjblogs.starter.common.entity.constant.ContextKeyConstant; -import cn.zyjblogs.oauth.server.user.po.OauthUserDetails; -import cn.zyjblogs.starter.common.entity.context.BaseContext; -import cn.zyjblogs.starter.common.entity.dto.ContextDto; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/PasswordEncoderConfig.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/PasswordEncoderConfig.java similarity index 93% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/PasswordEncoderConfig.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/PasswordEncoderConfig.java index 75f53f1..f56f6ed 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/PasswordEncoderConfig.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/PasswordEncoderConfig.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/ResourceServerConfig.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/ResourceServerConfig.java similarity index 92% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/ResourceServerConfig.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/ResourceServerConfig.java index 532cc37..c69ef46 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/ResourceServerConfig.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/ResourceServerConfig.java @@ -1,7 +1,7 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; -import cn.zyjblogs.oauth.config.handler.ResourceAccessDeniedHandler; -import cn.zyjblogs.oauth.config.handler.ResourceAuthenticationEntryPoint; +import cn.zyjblogs.config.handler.ResourceAccessDeniedHandler; +import cn.zyjblogs.config.handler.ResourceAuthenticationEntryPoint; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/WebSecurityConfiguration.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/WebSecurityConfiguration.java similarity index 95% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/WebSecurityConfiguration.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/WebSecurityConfiguration.java index 292a8b4..5763d7b 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/config/security/WebSecurityConfiguration.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/WebSecurityConfiguration.java @@ -1,6 +1,6 @@ -package cn.zyjblogs.oauth.config.security; +package cn.zyjblogs.config.security; -import cn.zyjblogs.oauth.server.user.service.impl.OauthUserDetailsServiceImpl; +import cn.zyjblogs.server.user.service.impl.OauthUserDetailsServiceImpl; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/OauthClientDetail.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/OauthClientDetail.java deleted file mode 100644 index 208519f..0000000 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/OauthClientDetail.java +++ /dev/null @@ -1,78 +0,0 @@ -package cn.zyjblogs.oauth.server.user.po; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.oauth2.provider.ClientDetails; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * @author zhuyijun - */ -public class OauthClientDetail implements ClientDetails { - @Override - public String getClientId() { - return null; - } - - @Override - public Set getResourceIds() { - return null; - } - - @Override - public boolean isSecretRequired() { - return false; - } - - @Override - public String getClientSecret() { - return null; - } - - @Override - public boolean isScoped() { - return false; - } - - @Override - public Set getScope() { - return null; - } - - @Override - public Set getAuthorizedGrantTypes() { - return null; - } - - @Override - public Set getRegisteredRedirectUri() { - return null; - } - - @Override - public Collection getAuthorities() { - return null; - } - - @Override - public Integer getAccessTokenValiditySeconds() { - return null; - } - - @Override - public Integer getRefreshTokenValiditySeconds() { - return null; - } - - @Override - public boolean isAutoApprove(String s) { - return false; - } - - @Override - public Map getAdditionalInformation() { - return null; - } -} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/LoginService.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/LoginService.java deleted file mode 100644 index 4b75a9c..0000000 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/LoginService.java +++ /dev/null @@ -1,56 +0,0 @@ -package cn.zyjblogs.oauth.server.user.service; - -import cn.zyjblogs.oauth.server.user.dto.AuthorizationCodeDto; -import cn.zyjblogs.oauth.server.user.dto.OAuth2AccessTokenDto; -import cn.zyjblogs.oauth.server.user.dto.UserLoginDto; -import cn.zyjblogs.oauth.server.user.vo.OAuth2AccessTokenVo; - -/** - * 登录 - * - * @author zhuyijun - */ -public interface LoginService { - /** - * ç™»å½•æŽ¥å£ - * - * @param userLoginDto - * @return cn.zyjblogs.oauth.server.user.vo.OAuth2AccessTokenVo - * @author zhuyijun - * @date 2022/9/17 下åˆ5:11 - */ - OAuth2AccessTokenVo login(UserLoginDto userLoginDto); - - /** - * 退出 - * - * @param - * @return void - * @author zhuyijun - * @date 2022/9/17 下åˆ5:53 - */ - void logout(); - - /** - * 刷新token - * - * @param oAuth2AccessTokenDto - * @return - */ - OAuth2AccessTokenVo refreshToken(OAuth2AccessTokenDto oAuth2AccessTokenDto); - - /** - * 检测tokenä¿¡æ¯ - * - * @param oAuth2AccessTokenDto - * @return - */ - OAuth2AccessTokenVo checkToken(OAuth2AccessTokenDto oAuth2AccessTokenDto); - - /** - * 获å–授æƒç  - * - * @param authorizationCodeDto - */ - void getAuthorizationCode(AuthorizationCodeDto authorizationCodeDto); -} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/constant/ClientConstant.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/constant/ClientConstant.java new file mode 100644 index 0000000..53f269a --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/constant/ClientConstant.java @@ -0,0 +1,8 @@ +package cn.zyjblogs.server.client.constant; + +/** + * @author zhuyijun + */ +public class ClientConstant { + public static final String REDIS_KEY = "oauth:clients"; +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/mapper/OauthClientDetailsMapper.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/mapper/OauthClientDetailsMapper.java new file mode 100644 index 0000000..1d37206 --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/mapper/OauthClientDetailsMapper.java @@ -0,0 +1,12 @@ +package cn.zyjblogs.server.client.mapper; + +import cn.zyjblogs.server.client.po.OauthClientDetail; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author zhuyijun + */ +@Mapper +public interface OauthClientDetailsMapper extends BaseMapper { +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/po/OauthClientDetail.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/po/OauthClientDetail.java new file mode 100644 index 0000000..a5ee7b4 --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/po/OauthClientDetail.java @@ -0,0 +1,275 @@ +package cn.zyjblogs.server.client.po; + +import cn.zyjblogs.starter.common.utils.bean.BeanUtils; +import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson2.JSON; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.codehaus.jackson.annotate.JsonIgnore; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.annotate.JsonProperty; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.oauth2.provider.ClientDetails; +import org.springframework.util.StringUtils; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author zhuyijun + */ +@org.codehaus.jackson.map.annotate.JsonSerialize( + include = org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_DEFAULT +) +@JsonIgnoreProperties( + ignoreUnknown = true +) +@JsonInclude(JsonInclude.Include.NON_DEFAULT) +@com.fasterxml.jackson.annotation.JsonIgnoreProperties( + ignoreUnknown = true +) +@TableName("oauth_client_details") +public class OauthClientDetail implements ClientDetails , Serializable { + + @TableId("client_id") + private String clientId; + + @TableField("client_secret") + private String clientSecret; + + @TableField("resource_ids") + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + private String resourceIds; + + @TableField("scope") + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + private String scope; + + @TableField("authorized_grant_types") + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + private String authorizedGrantTypes; + + @TableField("web_server_redirect_uri") + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + private String webServerRedirectUri; + + @TableField("authorities") + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + private String authorities; + + @TableField("access_token_validity") + private String accessTokenValidity; + + @TableField("refresh_token_validity") + private String refreshTokenValidity; + + @TableField("additional_information") + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + private String additionalInformation; + + @TableField("create_time") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JSONField(format = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + @TableField("archived") + @JsonProperty("archived") + @com.fasterxml.jackson.annotation.JsonProperty("archived") + private Integer archived; + + @TableField("trusted") + @JsonProperty("trusted") + @com.fasterxml.jackson.annotation.JsonProperty("trusted") + private Integer trusted; + + @TableField("autoapprove") + private String autoapprove; + + @TableField(exist = false) + @JsonProperty("access_token_validity") + @com.fasterxml.jackson.annotation.JsonProperty("access_token_validity") + private Integer accessTokenValiditySeconds; + @TableField(exist = false) + @JsonProperty("access_token_validity") + @com.fasterxml.jackson.annotation.JsonProperty("refresh_token_validity") + private Integer refreshTokenValiditySeconds; + + public OauthClientDetail() { + } + + public OauthClientDetail(ClientDetails prototype){ + this(); + this.setAccessTokenValiditySeconds(prototype.getAccessTokenValiditySeconds()); + this.setRefreshTokenValiditySeconds(prototype.getRefreshTokenValiditySeconds()); + Collection authorities = prototype.getAuthorities(); + this.setAuthorities(JSON.toJSONString(authorities)); + this.setAuthorizedGrantTypes(String.join(",",prototype.getAuthorizedGrantTypes())); + this.setClientId(prototype.getClientId()); + this.setClientSecret(prototype.getClientSecret()); + this.setWebServerRedirectUri(String.join(",",prototype.getRegisteredRedirectUri())); + this.setScope(String.join(",",prototype.getScope())); + this.setResourceIds(String.join(",",prototype.getResourceIds())); + } + + @Override + public String getClientId() { + return clientId; + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public Set getResourceIds() { + return Set.of(resourceIds.split(",")); + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + + public void setResourceIds(String resourceIds) { + this.resourceIds = resourceIds; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public void setAuthorizedGrantTypes(String authorizedGrantTypes) { + this.authorizedGrantTypes = authorizedGrantTypes; + } + + public void setWebServerRedirectUri(String webServerRedirectUri) { + this.webServerRedirectUri = webServerRedirectUri; + } + + public void setAuthorities(String authorities) { + this.authorities = authorities; + } + + public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) { + this.accessTokenValiditySeconds = accessTokenValiditySeconds; + } + + public void setRefreshTokenValiditySeconds(Integer refreshTokenValiditySeconds) { + this.refreshTokenValiditySeconds = refreshTokenValiditySeconds; + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public boolean isSecretRequired() { + return this.clientSecret != null; + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public String getClientSecret() { + return clientSecret; + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public boolean isScoped() { + return this.scope != null && !this.scope.isEmpty(); + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public Set getScope() { + return Set.of(scope.split(",")); + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public Set getAuthorizedGrantTypes() { + if (authorizedGrantTypes == null){ + return new HashSet<>(0); + } + return Set.of(authorizedGrantTypes.split(",")); + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public Set getRegisteredRedirectUri() { + if (webServerRedirectUri == null){ + return new HashSet<>(0); + } + return Set.of(webServerRedirectUri.split(",")); + } + + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public Collection getAuthorities() { + if (StringUtils.isEmpty(authorities)){ + return Collections.emptyList(); + } + return JSON.parseArray(authorities, GrantedAuthority.class); + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public Integer getAccessTokenValiditySeconds() { + return accessTokenValiditySeconds; + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public Integer getRefreshTokenValiditySeconds() { + return refreshTokenValiditySeconds; + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public boolean isAutoApprove(String s) { + return Boolean.getBoolean(autoapprove); + } + + @Override + @JsonIgnore + @com.fasterxml.jackson.annotation.JsonIgnore + public Map getAdditionalInformation() { + if (additionalInformation == null){ + return new HashMap<>(0); + } + return BeanUtils.beanToMap(additionalInformation); + } +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/service/impl/OauthClientDetailsServiceImpl.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/service/impl/OauthClientDetailsServiceImpl.java new file mode 100644 index 0000000..c49d9c8 --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/service/impl/OauthClientDetailsServiceImpl.java @@ -0,0 +1,79 @@ +package cn.zyjblogs.server.client.service.impl; + +import cn.zyjblogs.server.client.mapper.OauthClientDetailsMapper; +import cn.zyjblogs.server.client.po.OauthClientDetail; +import cn.zyjblogs.starter.common.utils.bean.BeanUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.oauth2.provider.ClientAlreadyExistsException; +import org.springframework.security.oauth2.provider.ClientDetails; +import org.springframework.security.oauth2.provider.ClientDetailsService; +import org.springframework.security.oauth2.provider.ClientRegistrationException; +import org.springframework.security.oauth2.provider.ClientRegistrationService; +import org.springframework.security.oauth2.provider.NoSuchClientException; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author zhuyijun + */ +@Service("oauthClientDetailsService") +@RequiredArgsConstructor +public class OauthClientDetailsServiceImpl implements ClientDetailsService, ClientRegistrationService { + private final OauthClientDetailsMapper oauthClientDetailsMapper; + private final PasswordEncoder passwordEncoder; + + @Override + public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.eq(OauthClientDetail::getClientId,clientId); + return oauthClientDetailsMapper.selectOne(wrapper); + } + + @Override + public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException { + OauthClientDetail oauthClientDetail = new OauthClientDetail(clientDetails); + if (oauthClientDetail.getClientSecret() != null){ + oauthClientDetail.setClientSecret(passwordEncoder.encode(oauthClientDetail.getClientSecret())); + } + oauthClientDetailsMapper.insert(oauthClientDetail); + } + + @Override + public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException { + LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(); + updateWrapper.eq(OauthClientDetail::getClientId,clientDetails.getClientId()); + OauthClientDetail oauthClientDetail = new OauthClientDetail(clientDetails); + oauthClientDetailsMapper.update(oauthClientDetail,updateWrapper); + } + + @Override + public void updateClientSecret(String clientId, String clientSecret) throws NoSuchClientException { + LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(); + updateWrapper.eq(OauthClientDetail::getClientId,clientId).set(OauthClientDetail::getClientSecret,passwordEncoder.encode(clientSecret)); + oauthClientDetailsMapper.update(null,updateWrapper); + } + + @Override + public void removeClientDetails(String clientId) throws NoSuchClientException { + LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(); + updateWrapper.eq(OauthClientDetail::getClientId,clientId); + oauthClientDetailsMapper.delete(updateWrapper); + } + + @Override + public List listClientDetails() { + List oauthClientDetails = oauthClientDetailsMapper.selectList(Wrappers.emptyWrapper()); + if (CollectionUtils.isEmpty(oauthClientDetails)){ + return new ArrayList<>(); + } + return BeanUtils.map(oauthClientDetails,ClientDetails.class); + } +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/demo/DemoController.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/demo/DemoController.java similarity index 92% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/demo/DemoController.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/demo/DemoController.java index e6ad4db..49abd19 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/demo/DemoController.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/demo/DemoController.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.server.demo; +package cn.zyjblogs.server.demo; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/constant/CommonConstant.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/CommonConstant.java similarity index 76% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/constant/CommonConstant.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/CommonConstant.java index 72f884c..b6087c5 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/constant/CommonConstant.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/CommonConstant.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.server.user.constant; +package cn.zyjblogs.server.user.constant; /** * diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/LoginEnum.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/LoginEnum.java new file mode 100644 index 0000000..f961367 --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/LoginEnum.java @@ -0,0 +1,37 @@ +package cn.zyjblogs.server.user.constant; + + +import lombok.Getter; + +/** + * @author zhuyijun + */ +public enum LoginEnum { + /** + * è´¦å·å·é‚®ç®±æ–¹å¼ + */ + NORMAL("1","普通登录方å¼"), + /** + * 验è¯ç æ–¹å¼ + */ + VERIFY_CODE("2","手机验è¯ç æ–¹å¼"), + /** + * 第三方登录 + */ + OTHER("3","第三方登录"); + private String code; + private String name; + + public String getCode() { + return code; + } + + public String getName() { + return name; + } + + LoginEnum(String code, String name) { + this.code = code; + this.name = name; + } +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/constant/UserEnum.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/UserEnum.java similarity index 85% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/constant/UserEnum.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/UserEnum.java index 1403a2c..d557586 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/constant/UserEnum.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/constant/UserEnum.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.server.user.constant; +package cn.zyjblogs.server.user.constant; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/controller/LoginController.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/controller/AutoController.java similarity index 52% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/controller/LoginController.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/controller/AutoController.java index f1523bb..7278b61 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/controller/LoginController.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/controller/AutoController.java @@ -1,10 +1,9 @@ -package cn.zyjblogs.oauth.server.user.controller; +package cn.zyjblogs.server.user.controller; -import cn.zyjblogs.oauth.server.user.dto.AuthorizationCodeDto; -import cn.zyjblogs.oauth.server.user.dto.OAuth2AccessTokenDto; -import cn.zyjblogs.oauth.server.user.dto.UserLoginDto; -import cn.zyjblogs.oauth.server.user.service.LoginService; -import cn.zyjblogs.oauth.server.user.vo.OAuth2AccessTokenVo; +import cn.zyjblogs.server.user.dto.AuthorizationCodeDto; +import cn.zyjblogs.server.user.dto.OAuth2AccessTokenDto; +import cn.zyjblogs.server.user.service.AuthService; +import cn.zyjblogs.server.user.vo.OAuth2AccessTokenVo; import cn.zyjblogs.starter.common.entity.response.ResponseObject; import cn.zyjblogs.starter.common.entity.response.ResponseResult; import io.swagger.annotations.ApiOperation; @@ -20,38 +19,26 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController @RequiredArgsConstructor -@RequestMapping("/user") -public class LoginController { - private final LoginService loginService; - - @ApiOperation(value = "用户登录", notes = "用户登录") - @PostMapping("/login") - public ResponseObject login(@RequestBody @Validated UserLoginDto userLoginDto) { - return ResponseResult.success(loginService.login(userLoginDto)); - } - - @ApiOperation(value = "用户注销", notes = "用户注销") - @PostMapping("/logout") - public void logout() { - loginService.logout(); - } +@RequestMapping("/auth") +public class AutoController { + private final AuthService authService; @ApiOperation(value = "刷新token", notes = "刷新token") @PostMapping("/refresh/token") public ResponseObject refreshToken(@RequestBody @Validated OAuth2AccessTokenDto oAuth2AccessTokenDto) { - return ResponseResult.success(loginService.refreshToken(oAuth2AccessTokenDto)); + return ResponseResult.success(authService.refreshToken(oAuth2AccessTokenDto)); } @ApiOperation(value = "检测token", notes = "刷新token") @PostMapping("/check/token") public ResponseObject checkToken(@RequestBody @Validated OAuth2AccessTokenDto oAuth2AccessTokenDto) { - return ResponseResult.success(loginService.checkToken(oAuth2AccessTokenDto)); + return ResponseResult.success(authService.checkToken(oAuth2AccessTokenDto)); } @ApiOperation(value = "获å–授æƒç ", notes = "刷新token") @PostMapping("/authorize") public void getAuthorizationCode(@RequestBody @Validated AuthorizationCodeDto authorizationCodeDto) { - loginService.getAuthorizationCode(authorizationCodeDto); + authService.getAuthorizationCode(authorizationCodeDto); } } diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/controller/LoginController.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/controller/LoginController.java new file mode 100644 index 0000000..cc3968b --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/controller/LoginController.java @@ -0,0 +1,36 @@ +package cn.zyjblogs.server.user.controller; + +import cn.zyjblogs.server.user.dto.UserLoginDto; +import cn.zyjblogs.server.user.service.LoginService; +import cn.zyjblogs.server.user.vo.OAuth2AccessTokenVo; +import cn.zyjblogs.starter.common.entity.response.ResponseObject; +import cn.zyjblogs.starter.common.entity.response.ResponseResult; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author zhuyijun + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/user") +public class LoginController { + private final LoginService loginService; + + @ApiOperation(value = "用户登录", notes = "用户登录") + @PostMapping("/login") + public ResponseObject login(@RequestBody @Validated UserLoginDto userLoginDto) { + return ResponseResult.success(loginService.login(userLoginDto)); + } + + @ApiOperation(value = "用户注销", notes = "用户注销") + @PostMapping("/logout") + public void logout() { + loginService.logout(); + } +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/AuthorizationCodeDto.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/AuthorizationCodeDto.java similarity index 93% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/AuthorizationCodeDto.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/AuthorizationCodeDto.java index 1966056..8cf147a 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/AuthorizationCodeDto.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/AuthorizationCodeDto.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.server.user.dto; +package cn.zyjblogs.server.user.dto; import io.swagger.annotations.ApiModelProperty; import lombok.Data; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/OAuth2AccessTokenDto.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/OAuth2AccessTokenDto.java similarity index 91% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/OAuth2AccessTokenDto.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/OAuth2AccessTokenDto.java index 91a5fae..6492088 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/OAuth2AccessTokenDto.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/OAuth2AccessTokenDto.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.server.user.dto; +package cn.zyjblogs.server.user.dto; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/UserLoginDto.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/UserLoginDto.java similarity index 73% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/UserLoginDto.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/UserLoginDto.java index ba9a8b5..ea6f7ce 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/dto/UserLoginDto.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/dto/UserLoginDto.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.server.user.dto; +package cn.zyjblogs.server.user.dto; import lombok.AllArgsConstructor; import lombok.Builder; @@ -18,13 +18,13 @@ public class UserLoginDto implements Serializable { /** * è´¦å· (æ‰‹æœºå· é‚®ç®± 用户å) */ - private String username; + private String userIdentification; /** * å¯†ç  */ - private String password; + private String pwdOrVerifyCode; /** * 登录类型 */ - private Integer type; + private String loginType; } diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/mapper/UserMapper.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/mapper/UserMapper.java similarity index 67% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/mapper/UserMapper.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/mapper/UserMapper.java index 74afa78..74d8e11 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/mapper/UserMapper.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/mapper/UserMapper.java @@ -1,6 +1,6 @@ -package cn.zyjblogs.oauth.server.user.mapper; +package cn.zyjblogs.server.user.mapper; -import cn.zyjblogs.oauth.server.user.po.UserPo; +import cn.zyjblogs.server.user.po.UserPo; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/OauthUserDetails.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/OauthUserDetails.java similarity index 95% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/OauthUserDetails.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/OauthUserDetails.java index 3816355..3c47a69 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/OauthUserDetails.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/OauthUserDetails.java @@ -1,8 +1,8 @@ -package cn.zyjblogs.oauth.server.user.po; +package cn.zyjblogs.server.user.po; -import cn.zyjblogs.oauth.server.user.constant.CommonConstant; -import cn.zyjblogs.oauth.server.user.constant.UserEnum; +import cn.zyjblogs.server.user.constant.CommonConstant; +import cn.zyjblogs.server.user.constant.UserEnum; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.NoArgsConstructor; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/Role.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/Role.java similarity index 92% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/Role.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/Role.java index b830e66..ffeaca6 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/Role.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/Role.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.oauth.server.user.po; +package cn.zyjblogs.server.user.po; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/UserPo.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/UserPo.java similarity index 77% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/UserPo.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/UserPo.java index d13c94a..357bacd 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/po/UserPo.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/po/UserPo.java @@ -1,16 +1,20 @@ -package cn.zyjblogs.oauth.server.user.po; +package cn.zyjblogs.server.user.po; import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +import java.sql.Timestamp; import java.time.LocalDateTime; /** @@ -20,7 +24,7 @@ import java.time.LocalDateTime; @AllArgsConstructor @NoArgsConstructor @Builder -@TableName("user") +@TableName("users") public class UserPo implements Serializable { @TableId(value = "id", type = IdType.ASSIGN_UUID) @@ -68,7 +72,8 @@ public class UserPo implements Serializable { @TableField("create_user_id") private String createUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("create_time") private LocalDateTime createTime; @@ -76,7 +81,8 @@ public class UserPo implements Serializable { private String editUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("edit_time") private LocalDateTime editTime; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/AuthService.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/AuthService.java new file mode 100644 index 0000000..e2849f3 --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/AuthService.java @@ -0,0 +1,33 @@ +package cn.zyjblogs.server.user.service; + +import cn.zyjblogs.server.user.dto.AuthorizationCodeDto; +import cn.zyjblogs.server.user.dto.OAuth2AccessTokenDto; +import cn.zyjblogs.server.user.vo.OAuth2AccessTokenVo; + +/** + * @author zhuyijun + */ +public interface AuthService { + /** + * 刷新token + * + * @param oAuth2AccessTokenDto + * @return + */ + OAuth2AccessTokenVo refreshToken(OAuth2AccessTokenDto oAuth2AccessTokenDto); + + /** + * 检测tokenä¿¡æ¯ + * + * @param oAuth2AccessTokenDto + * @return + */ + OAuth2AccessTokenVo checkToken(OAuth2AccessTokenDto oAuth2AccessTokenDto); + + /** + * 获å–授æƒç  + * + * @param authorizationCodeDto + */ + void getAuthorizationCode(AuthorizationCodeDto authorizationCodeDto); +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/LoginService.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/LoginService.java new file mode 100644 index 0000000..b95e076 --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/LoginService.java @@ -0,0 +1,31 @@ +package cn.zyjblogs.server.user.service; + +import cn.zyjblogs.server.user.dto.UserLoginDto; +import cn.zyjblogs.server.user.vo.OAuth2AccessTokenVo; + +/** + * 登录 + * + * @author zhuyijun + */ +public interface LoginService { + /** + * ç™»å½•æŽ¥å£ + * + * @param userLoginDto + * @return cn.zyjblogs.oauth.server.user.vo.OAuth2AccessTokenVo + * @author zhuyijun + * @date 2022/9/17 下åˆ5:11 + */ + OAuth2AccessTokenVo login(UserLoginDto userLoginDto); + + /** + * 退出 + * + * @param + * @return void + * @author zhuyijun + * @date 2022/9/17 下åˆ5:53 + */ + void logout(); +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/UserService.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/UserService.java similarity index 56% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/UserService.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/UserService.java index 0d502ce..b4e0ebb 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/UserService.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/UserService.java @@ -1,6 +1,6 @@ -package cn.zyjblogs.oauth.server.user.service; +package cn.zyjblogs.server.user.service; -import cn.zyjblogs.oauth.server.user.po.UserPo; +import cn.zyjblogs.server.user.po.UserPo; import com.baomidou.mybatisplus.extension.service.IService; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/LoginServiceImpl.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/AuthServiceImpl.java similarity index 51% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/LoginServiceImpl.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/AuthServiceImpl.java index e8dba89..38cd46d 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/LoginServiceImpl.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/AuthServiceImpl.java @@ -1,18 +1,12 @@ -package cn.zyjblogs.oauth.server.user.service.impl; +package cn.zyjblogs.server.user.service.impl; -import cn.zyjblogs.oauth.server.user.dto.AuthorizationCodeDto; -import cn.zyjblogs.oauth.server.user.dto.OAuth2AccessTokenDto; -import cn.zyjblogs.oauth.server.user.dto.UserLoginDto; -import cn.zyjblogs.oauth.server.user.service.LoginService; -import cn.zyjblogs.oauth.server.user.vo.OAuth2AccessTokenVo; -import cn.zyjblogs.starter.common.entity.constant.HttpHeaderConstant; -import cn.zyjblogs.starter.common.entity.context.BaseContext; -import cn.zyjblogs.starter.common.entity.dto.ContextDto; +import cn.zyjblogs.server.user.dto.AuthorizationCodeDto; +import cn.zyjblogs.server.user.dto.OAuth2AccessTokenDto; +import cn.zyjblogs.server.user.service.AuthService; +import cn.zyjblogs.server.user.vo.OAuth2AccessTokenVo; import cn.zyjblogs.starter.common.entity.response.HttpCode; import cn.zyjblogs.starter.common.exception.AuthRuntimeException; -import cn.zyjblogs.starter.common.utils.bean.BeanUtils; import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration; import org.springframework.security.oauth2.provider.ClientDetails; @@ -23,7 +17,6 @@ import org.springframework.security.oauth2.provider.TokenRequest; import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; import java.util.HashMap; import java.util.Map; @@ -32,61 +25,35 @@ import java.util.Map; * @author zhuyijun */ @Service -public class LoginServiceImpl implements LoginService { +public class AuthServiceImpl implements AuthService { private final TokenGranter tokenGranter; private final ClientDetailsService clientDetails; private final OAuth2RequestFactory oAuth2RequestFactory; - private final TokenStore tokenStore; - public LoginServiceImpl(AuthorizationServerEndpointsConfiguration authorizationServerEndpointsConfiguration, - ClientDetailsService clientDetails, - TokenStore tokenStore) { + public AuthServiceImpl(AuthorizationServerEndpointsConfiguration authorizationServerEndpointsConfiguration, + ClientDetailsService clientDetails, + TokenStore tokenStore) { this.tokenGranter = authorizationServerEndpointsConfiguration.getEndpointsConfigurer().getTokenGranter(); this.clientDetails = clientDetails; this.oAuth2RequestFactory = new DefaultOAuth2RequestFactory(clientDetails); - this.tokenStore = tokenStore; } - @Value("${spring.application.name}") + @Value("${security.oauth2.client.client-id}") private String clientId; - @Override - public OAuth2AccessTokenVo login(UserLoginDto userLoginDto) { - Map parameters = BeanUtils.map(userLoginDto, Map.class); - parameters.put("grant_type", "password"); - ClientDetails authenticatedClient = clientDetails.loadClientByClientId(clientId); - TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient); - OAuth2AccessToken token = tokenGranter.grant(tokenRequest.getGrantType(), tokenRequest); - if (token == null) { - throw new AuthRuntimeException(HttpCode.INTERNAL_SERVER_ERROR, "客户端获å–token失败"); - } - return transferToken(token); - } - - @Override - public void logout() { - String token = BaseContext.getToken(); - if (StringUtils.isEmpty(token)) { - return; - } - token = token.replace(HttpHeaderConstant.AUTHORIZATION_TYPE, "").trim(); - OAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(token); - tokenStore.removeAccessToken(oAuth2AccessToken); - } - @Override public OAuth2AccessTokenVo refreshToken(OAuth2AccessTokenDto oAuth2AccessTokenDto) { Map parameters = new HashMap<>(); parameters.put("refresh_token", oAuth2AccessTokenDto.getToken()); parameters.put("grant_type", "refresh_token"); ClientDetails authenticatedClient = clientDetails.loadClientByClientId(clientId); - TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient); + if (authenticatedClient == null){ + throw new AuthRuntimeException(HttpCode.INTERNAL_SERVER_ERROR, "客户端获å–失败"); + } try { + TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient); OAuth2AccessToken token = tokenGranter.grant(tokenRequest.getGrantType(), tokenRequest); - if (token == null) { - throw new AuthRuntimeException(HttpCode.INTERNAL_SERVER_ERROR, "客户端刷新token失败"); - } - return transferToken(token); + return OAuth2AccessTokenVo.TransferToken(token); } catch (Exception e) { throw new AuthRuntimeException(HttpCode.INTERNAL_SERVER_ERROR, e.getMessage()); } @@ -116,25 +83,4 @@ public class LoginServiceImpl implements LoginService { // } } - /** - * 处ç†token - * - * @param token - * @return - */ - private OAuth2AccessTokenVo transferToken(OAuth2AccessToken token) { - OAuth2AccessTokenVo oAuth2AccessTokenVo = new OAuth2AccessTokenVo( - token.getValue(), - token.getTokenType(), - token.getRefreshToken().getValue(), - token.getExpiresIn(), - token.getScope(), - token.getAdditionalInformation()); - BaseContext.set(ContextDto.builder() - .userId(oAuth2AccessTokenVo.getUserId()) - .username(oAuth2AccessTokenVo.getUsername()) - .token(oAuth2AccessTokenVo.getValue()) - .build()); - return oAuth2AccessTokenVo; - } } diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/LoginServiceImpl.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/LoginServiceImpl.java new file mode 100644 index 0000000..9f5db5a --- /dev/null +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/LoginServiceImpl.java @@ -0,0 +1,78 @@ +package cn.zyjblogs.server.user.service.impl; + +import cn.zyjblogs.server.user.dto.UserLoginDto; +import cn.zyjblogs.server.user.service.LoginService; +import cn.zyjblogs.server.user.vo.OAuth2AccessTokenVo; +import cn.zyjblogs.starter.common.entity.constant.HttpHeaderConstant; +import cn.zyjblogs.starter.common.entity.context.BaseContext; +import cn.zyjblogs.starter.common.entity.response.HttpCode; +import cn.zyjblogs.starter.common.exception.AuthRuntimeException; +import cn.zyjblogs.starter.common.utils.bean.BeanUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration; +import org.springframework.security.oauth2.provider.ClientDetails; +import org.springframework.security.oauth2.provider.ClientDetailsService; +import org.springframework.security.oauth2.provider.OAuth2RequestFactory; +import org.springframework.security.oauth2.provider.TokenGranter; +import org.springframework.security.oauth2.provider.TokenRequest; +import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; +import org.springframework.security.oauth2.provider.token.TokenStore; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.Map; + +/** + * @author zhuyijun + */ +@Service +public class LoginServiceImpl implements LoginService { + private final TokenGranter tokenGranter; + private final ClientDetailsService clientDetails; + private final OAuth2RequestFactory oAuth2RequestFactory; + private final TokenStore tokenStore; + + public LoginServiceImpl(AuthorizationServerEndpointsConfiguration authorizationServerEndpointsConfiguration, + ClientDetailsService clientDetails, + TokenStore tokenStore) { + this.tokenGranter = authorizationServerEndpointsConfiguration.getEndpointsConfigurer().getTokenGranter(); + this.clientDetails = clientDetails; + this.oAuth2RequestFactory = new DefaultOAuth2RequestFactory(clientDetails); + this.tokenStore = tokenStore; + } + + @Value("${security.oauth2.client.client-id}") + private String clientId; + + @Override + public OAuth2AccessTokenVo login(UserLoginDto userLoginDto) { + Map parameters = BeanUtils.map(userLoginDto, Map.class); + parameters.put("username",userLoginDto.getUserIdentification()); + parameters.put("password",userLoginDto.getPwdOrVerifyCode()); + parameters.put("grant_type", "password"); + ClientDetails authenticatedClient = clientDetails.loadClientByClientId(clientId); + if (authenticatedClient == null) { + throw new AuthRuntimeException(HttpCode.INTERNAL_SERVER_ERROR, "客户端获å–token失败"); + } + try{ + TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient); + OAuth2AccessToken token = tokenGranter.grant(tokenRequest.getGrantType(), tokenRequest); + return OAuth2AccessTokenVo.TransferToken(token); + }catch (Exception e){ + throw new AuthRuntimeException(HttpCode.INTERNAL_SERVER_ERROR, e.getMessage()); + } + } + + @Override + public void logout() { + String token = BaseContext.getToken(); + if (StringUtils.isEmpty(token)) { + return; + } + token = token.replace(HttpHeaderConstant.AUTHORIZATION_TYPE, "").trim(); + OAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(token); + tokenStore.removeAccessToken(oAuth2AccessToken); + } +} diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/OauthUserDetailsServiceImpl.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/OauthUserDetailsServiceImpl.java similarity index 77% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/OauthUserDetailsServiceImpl.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/OauthUserDetailsServiceImpl.java index a5d032f..5ae1e3d 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/OauthUserDetailsServiceImpl.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/OauthUserDetailsServiceImpl.java @@ -1,20 +1,17 @@ -package cn.zyjblogs.oauth.server.user.service.impl; +package cn.zyjblogs.server.user.service.impl; -import cn.zyjblogs.oauth.server.user.po.OauthUserDetails; -import cn.zyjblogs.oauth.server.user.po.UserPo; -import cn.zyjblogs.oauth.server.user.service.UserService; +import cn.zyjblogs.server.user.po.OauthUserDetails; +import cn.zyjblogs.server.user.po.UserPo; +import cn.zyjblogs.server.user.service.UserService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; -import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; -import java.util.List; - /** * @author zhuyijun */ @@ -25,7 +22,7 @@ public class OauthUserDetailsServiceImpl implements UserDetailsService { @Override public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); - queryWrapper.eq(UserPo::getUsername,s); + queryWrapper.eq(UserPo::getUsername,s).or().eq(UserPo::getEmail,s).or().eq(UserPo::getPhone,s); UserPo userPo = userService.getBaseMapper().selectOne(queryWrapper); if (userPo == null){ return null; diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/UserServiceImpl.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/UserServiceImpl.java similarity index 56% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/UserServiceImpl.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/UserServiceImpl.java index 200b761..ed6a23c 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/service/impl/UserServiceImpl.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/service/impl/UserServiceImpl.java @@ -1,13 +1,16 @@ -package cn.zyjblogs.oauth.server.user.service.impl; +package cn.zyjblogs.server.user.service.impl; -import cn.zyjblogs.oauth.server.user.mapper.UserMapper; -import cn.zyjblogs.oauth.server.user.po.UserPo; -import cn.zyjblogs.oauth.server.user.service.UserService; +import cn.zyjblogs.server.user.mapper.UserMapper; +import cn.zyjblogs.server.user.po.UserPo; +import cn.zyjblogs.server.user.service.UserService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +/** + * @author zhuyijun + */ @Service @RequiredArgsConstructor public class UserServiceImpl extends ServiceImpl implements UserService { diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/vo/OAuth2AccessTokenVo.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/vo/OAuth2AccessTokenVo.java similarity index 68% rename from server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/vo/OAuth2AccessTokenVo.java rename to server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/vo/OAuth2AccessTokenVo.java index 2017be9..b661596 100644 --- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/oauth/server/user/vo/OAuth2AccessTokenVo.java +++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/user/vo/OAuth2AccessTokenVo.java @@ -1,8 +1,11 @@ -package cn.zyjblogs.oauth.server.user.vo; +package cn.zyjblogs.server.user.vo; import cn.zyjblogs.starter.common.entity.constant.ContextKeyConstant; +import cn.zyjblogs.starter.common.entity.context.BaseContext; +import cn.zyjblogs.starter.common.entity.dto.ContextDto; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.springframework.security.oauth2.common.OAuth2AccessToken; import java.io.Serializable; import java.util.Collection; @@ -51,5 +54,20 @@ public class OAuth2AccessTokenVo implements Serializable { this.jti = (String) addition.get("jti"); } + public static OAuth2AccessTokenVo TransferToken(OAuth2AccessToken token) { + OAuth2AccessTokenVo oAuth2AccessTokenVo = new OAuth2AccessTokenVo( + token.getValue(), + token.getTokenType(), + token.getRefreshToken().getValue(), + token.getExpiresIn(), + token.getScope(), + token.getAdditionalInformation()); + BaseContext.set(ContextDto.builder() + .userId(oAuth2AccessTokenVo.getUserId()) + .username(oAuth2AccessTokenVo.getUsername()) + .token(oAuth2AccessTokenVo.getValue()) + .build()); + return oAuth2AccessTokenVo; + } } diff --git a/server/zyjblogs-oauth/src/main/resources/bootstrap.yml b/server/zyjblogs-oauth/src/main/resources/bootstrap.yml index 9df34b2..063e93c 100644 --- a/server/zyjblogs-oauth/src/main/resources/bootstrap.yml +++ b/server/zyjblogs-oauth/src/main/resources/bootstrap.yml @@ -29,4 +29,10 @@ spring: group: public logging: - config: classpath:logback-spring.xml \ No newline at end of file + config: classpath:logback-spring.xml + +security: + oauth2: + client: + client-id: ${spring.application.name} + client-secret: secret \ No newline at end of file diff --git a/server/zyjblogs-oauth/src/main/resources/mapper/user/UserMapper.xml b/server/zyjblogs-oauth/src/main/resources/mapper/user/UserMapper.xml new file mode 100644 index 0000000..cb79ec8 --- /dev/null +++ b/server/zyjblogs-oauth/src/main/resources/mapper/user/UserMapper.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/RbacApplication.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/RbacApplication.java similarity index 95% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/RbacApplication.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/RbacApplication.java index 7137767..ea6d5e0 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/RbacApplication.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/RbacApplication.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.rbac; +package cn.zyjblogs; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/controller/RoleController.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/controller/RoleController.java similarity index 89% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/controller/RoleController.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/controller/RoleController.java index 532d711..183129d 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/controller/RoleController.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/controller/RoleController.java @@ -1,9 +1,9 @@ -package cn.zyjblogs.rbac.server.role.controller; +package cn.zyjblogs.server.role.controller; -import cn.zyjblogs.rbac.server.role.dto.RolePageDto; -import cn.zyjblogs.rbac.server.role.po.RolePo; -import cn.zyjblogs.rbac.server.role.service.RoleService; -import cn.zyjblogs.rbac.server.role.vo.RoleVo; +import cn.zyjblogs.server.role.dto.RolePageDto; +import cn.zyjblogs.server.role.po.RolePo; +import cn.zyjblogs.server.role.service.RoleService; +import cn.zyjblogs.server.role.vo.RoleVo; import cn.zyjblogs.starter.common.entity.response.ResponseObject; import cn.zyjblogs.starter.common.entity.response.ResponseResult; import cn.zyjblogs.starter.common.utils.bean.BeanUtils; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/dto/RolePageDto.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/dto/RolePageDto.java similarity index 97% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/dto/RolePageDto.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/dto/RolePageDto.java index adbbcaf..e4b47ec 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/dto/RolePageDto.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/dto/RolePageDto.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.rbac.server.role.dto; +package cn.zyjblogs.server.role.dto; import cn.zyjblogs.starter.common.entity.dto.PageDto; import com.alibaba.fastjson.annotation.JSONField; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/mapper/RoleMapper.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/mapper/RoleMapper.java similarity index 78% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/mapper/RoleMapper.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/mapper/RoleMapper.java index 5442fc9..65123fa 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/mapper/RoleMapper.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/mapper/RoleMapper.java @@ -1,8 +1,8 @@ -package cn.zyjblogs.rbac.server.role.mapper; +package cn.zyjblogs.server.role.mapper; -import cn.zyjblogs.rbac.server.role.dto.RolePageDto; -import cn.zyjblogs.rbac.server.role.po.RolePo; -import cn.zyjblogs.rbac.server.role.vo.RoleVo; +import cn.zyjblogs.server.role.dto.RolePageDto; +import cn.zyjblogs.server.role.po.RolePo; +import cn.zyjblogs.server.role.vo.RoleVo; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import org.apache.ibatis.annotations.Mapper; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/po/RolePo.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/po/RolePo.java similarity index 71% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/po/RolePo.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/po/RolePo.java index 22d222a..a27ff7f 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/po/RolePo.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/po/RolePo.java @@ -1,9 +1,12 @@ -package cn.zyjblogs.rbac.server.role.po; +package cn.zyjblogs.server.role.po; import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -36,14 +39,16 @@ public class RolePo implements Serializable { @TableField("create_user_id") private String createUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("create_time") private LocalDateTime createTime; @TableField("edit_user_id") private String editUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("edit_time") private LocalDateTime editTime; @TableField("tenant_id") diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/service/RoleService.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/service/RoleService.java similarity index 74% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/service/RoleService.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/service/RoleService.java index 9edd984..4344004 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/service/RoleService.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/service/RoleService.java @@ -1,8 +1,8 @@ -package cn.zyjblogs.rbac.server.role.service; +package cn.zyjblogs.server.role.service; -import cn.zyjblogs.rbac.server.role.dto.RolePageDto; -import cn.zyjblogs.rbac.server.role.po.RolePo; -import cn.zyjblogs.rbac.server.role.vo.RoleVo; +import cn.zyjblogs.server.role.dto.RolePageDto; +import cn.zyjblogs.server.role.po.RolePo; +import cn.zyjblogs.server.role.vo.RoleVo; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/service/impl/RoleServiceImpl.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/service/impl/RoleServiceImpl.java similarity index 84% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/service/impl/RoleServiceImpl.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/service/impl/RoleServiceImpl.java index af2851b..14636bc 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/service/impl/RoleServiceImpl.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/service/impl/RoleServiceImpl.java @@ -1,10 +1,10 @@ -package cn.zyjblogs.rbac.server.role.service.impl; +package cn.zyjblogs.server.role.service.impl; -import cn.zyjblogs.rbac.server.role.dto.RolePageDto; -import cn.zyjblogs.rbac.server.role.mapper.RoleMapper; -import cn.zyjblogs.rbac.server.role.po.RolePo; -import cn.zyjblogs.rbac.server.role.service.RoleService; -import cn.zyjblogs.rbac.server.role.vo.RoleVo; +import cn.zyjblogs.server.role.dto.RolePageDto; +import cn.zyjblogs.server.role.mapper.RoleMapper; +import cn.zyjblogs.server.role.po.RolePo; +import cn.zyjblogs.server.role.service.RoleService; +import cn.zyjblogs.server.role.vo.RoleVo; import cn.zyjblogs.starter.common.entity.context.BaseContext; import cn.zyjblogs.starter.common.utils.bean.BeanUtils; import com.baomidou.mybatisplus.core.metadata.IPage; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/vo/RoleVo.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/vo/RoleVo.java similarity index 71% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/vo/RoleVo.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/vo/RoleVo.java index 77f30e8..20a6db3 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/role/vo/RoleVo.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/role/vo/RoleVo.java @@ -1,9 +1,12 @@ -package cn.zyjblogs.rbac.server.role.vo; +package cn.zyjblogs.server.role.vo; import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -36,14 +39,16 @@ public class RoleVo implements Serializable { @TableField("create_user_id") private String createUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("create_time") private LocalDateTime createTime; @TableField("edit_user_id") private String editUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("edit_time") private LocalDateTime editTime; @TableField("tenant_id") diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/controller/UserController.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/controller/UserController.java similarity index 89% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/controller/UserController.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/controller/UserController.java index 0c8c0a5..30fdfbf 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/controller/UserController.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/controller/UserController.java @@ -1,9 +1,9 @@ -package cn.zyjblogs.rbac.server.user.controller; +package cn.zyjblogs.server.user.controller; -import cn.zyjblogs.rbac.server.user.dto.UserPageDto; -import cn.zyjblogs.rbac.server.user.po.UserPo; -import cn.zyjblogs.rbac.server.user.service.UserService; -import cn.zyjblogs.rbac.server.user.vo.UserVo; +import cn.zyjblogs.server.user.dto.UserPageDto; +import cn.zyjblogs.server.user.po.UserPo; +import cn.zyjblogs.server.user.service.UserService; +import cn.zyjblogs.server.user.vo.UserVo; import cn.zyjblogs.starter.common.entity.response.ResponseObject; import cn.zyjblogs.starter.common.entity.response.ResponseResult; import com.baomidou.mybatisplus.core.metadata.IPage; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/dto/UserPageDto.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/dto/UserPageDto.java similarity index 94% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/dto/UserPageDto.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/dto/UserPageDto.java index 46c1c3b..29388f8 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/dto/UserPageDto.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/dto/UserPageDto.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.rbac.server.user.dto; +package cn.zyjblogs.server.user.dto; import cn.zyjblogs.starter.common.entity.dto.PageDto; import lombok.Builder; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/mapper/UserMapper.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/mapper/UserMapper.java similarity index 81% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/mapper/UserMapper.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/mapper/UserMapper.java index 8ec2537..0b7910f 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/mapper/UserMapper.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/mapper/UserMapper.java @@ -1,8 +1,8 @@ -package cn.zyjblogs.rbac.server.user.mapper; +package cn.zyjblogs.server.user.mapper; -import cn.zyjblogs.rbac.server.user.dto.UserPageDto; -import cn.zyjblogs.rbac.server.user.po.UserPo; -import cn.zyjblogs.rbac.server.user.vo.UserVo; +import cn.zyjblogs.server.user.dto.UserPageDto; +import cn.zyjblogs.server.user.po.UserPo; +import cn.zyjblogs.server.user.vo.UserVo; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import org.apache.ibatis.annotations.Mapper; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/po/UserPo.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/po/UserPo.java similarity index 77% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/po/UserPo.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/po/UserPo.java index 5c9e168..357bacd 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/po/UserPo.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/po/UserPo.java @@ -1,16 +1,20 @@ -package cn.zyjblogs.rbac.server.user.po; +package cn.zyjblogs.server.user.po; import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +import java.sql.Timestamp; import java.time.LocalDateTime; /** @@ -20,7 +24,7 @@ import java.time.LocalDateTime; @AllArgsConstructor @NoArgsConstructor @Builder -@TableName("user") +@TableName("users") public class UserPo implements Serializable { @TableId(value = "id", type = IdType.ASSIGN_UUID) @@ -68,7 +72,8 @@ public class UserPo implements Serializable { @TableField("create_user_id") private String createUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("create_time") private LocalDateTime createTime; @@ -76,7 +81,8 @@ public class UserPo implements Serializable { private String editUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("edit_time") private LocalDateTime editTime; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/service/UserService.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/service/UserService.java similarity index 78% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/service/UserService.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/service/UserService.java index dadf2c5..046d942 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/service/UserService.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/service/UserService.java @@ -1,8 +1,8 @@ -package cn.zyjblogs.rbac.server.user.service; +package cn.zyjblogs.server.user.service; -import cn.zyjblogs.rbac.server.user.dto.UserPageDto; -import cn.zyjblogs.rbac.server.user.po.UserPo; -import cn.zyjblogs.rbac.server.user.vo.UserVo; +import cn.zyjblogs.server.user.dto.UserPageDto; +import cn.zyjblogs.server.user.po.UserPo; +import cn.zyjblogs.server.user.vo.UserVo; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/service/impl/UserServiceImpl.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/service/impl/UserServiceImpl.java similarity index 84% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/service/impl/UserServiceImpl.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/service/impl/UserServiceImpl.java index 24435d1..c453407 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/service/impl/UserServiceImpl.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/service/impl/UserServiceImpl.java @@ -1,11 +1,11 @@ -package cn.zyjblogs.rbac.server.user.service.impl; +package cn.zyjblogs.server.user.service.impl; -import cn.zyjblogs.rbac.server.user.dto.UserPageDto; -import cn.zyjblogs.rbac.server.user.mapper.UserMapper; -import cn.zyjblogs.rbac.server.user.po.UserPo; -import cn.zyjblogs.rbac.server.user.service.UserService; -import cn.zyjblogs.rbac.server.user.vo.UserVo; +import cn.zyjblogs.server.user.dto.UserPageDto; +import cn.zyjblogs.server.user.mapper.UserMapper; +import cn.zyjblogs.server.user.po.UserPo; +import cn.zyjblogs.server.user.service.UserService; +import cn.zyjblogs.server.user.vo.UserVo; import cn.zyjblogs.starter.common.entity.context.BaseContext; import cn.zyjblogs.starter.common.utils.bean.BeanUtils; import com.baomidou.mybatisplus.core.metadata.IPage; diff --git a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/vo/UserVo.java b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/vo/UserVo.java similarity index 65% rename from server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/vo/UserVo.java rename to server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/vo/UserVo.java index 1076f0a..aa5f476 100644 --- a/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/server/user/vo/UserVo.java +++ b/server/zyjblogs-rbac/src/main/java/cn/zyjblogs/server/user/vo/UserVo.java @@ -1,12 +1,16 @@ -package cn.zyjblogs.rbac.server.user.vo; +package cn.zyjblogs.server.user.vo; import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +import java.sql.Timestamp; import java.time.LocalDateTime; /** @@ -46,13 +50,15 @@ public class UserVo implements Serializable { private String createUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime createTime; private String editUserId; - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime editTime; private String tenantId; diff --git a/server/zyjblogs-rbac/src/main/resources/bootstrap.yml b/server/zyjblogs-rbac/src/main/resources/bootstrap.yml index abca73b..4c00875 100644 --- a/server/zyjblogs-rbac/src/main/resources/bootstrap.yml +++ b/server/zyjblogs-rbac/src/main/resources/bootstrap.yml @@ -27,6 +27,12 @@ spring: logging: config: classpath:logback-spring.xml + +security: + oauth2: + client: + client-id: ${spring.application.name} + client-secret: secret # é…置了公钥和ç§é’¥çš„ä½ç½® rsa: key: diff --git a/server/zyjblogs-rbac/src/main/resources/mapper/role/RoleMapper.xml b/server/zyjblogs-rbac/src/main/resources/mapper/role/RoleMapper.xml index 53d47b5..3defc63 100644 --- a/server/zyjblogs-rbac/src/main/resources/mapper/role/RoleMapper.xml +++ b/server/zyjblogs-rbac/src/main/resources/mapper/role/RoleMapper.xml @@ -1,7 +1,7 @@ - - select * from role where deleted = 0 diff --git a/server/zyjblogs-rbac/src/main/resources/mapper/user/UserMapper.xml b/server/zyjblogs-rbac/src/main/resources/mapper/user/UserMapper.xml index 7760476..0a51fdf 100644 --- a/server/zyjblogs-rbac/src/main/resources/mapper/user/UserMapper.xml +++ b/server/zyjblogs-rbac/src/main/resources/mapper/user/UserMapper.xml @@ -1,17 +1,40 @@ - - select * - from user + from users where deleted = 0 and username like CONCAT('%', #{username}, '%') and tenant_id = #{tenantId} - + select * from users + where deleted = 0 + + and username concat('%',#{userPageDto.username},'%') + + + and name concat('%',#{name},'%') + + + and phone concat('%',#{phone},'%') + + + and email concat('%',#{email},'%') + + + and status = #{userPageDto.status} + + + and tenant_id = #{tenantId} + + order by create_time desc + + - \ No newline at end of file diff --git a/stater/zyjblogs-mybatisplus-spring-boot-starter/pom.xml b/stater/zyjblogs-mybatisplus-spring-boot-starter/pom.xml index 8bb24b8..f63e452 100644 --- a/stater/zyjblogs-mybatisplus-spring-boot-starter/pom.xml +++ b/stater/zyjblogs-mybatisplus-spring-boot-starter/pom.xml @@ -38,6 +38,10 @@ mysql mysql-connector-java + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + org.postgresql postgresql diff --git a/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/MyBatisPlusConfig.java b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/autoconfigure/MyBatisPlusConfig.java similarity index 97% rename from stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/MyBatisPlusConfig.java rename to stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/autoconfigure/MyBatisPlusConfig.java index c479e7c..9e6ac9a 100644 --- a/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/MyBatisPlusConfig.java +++ b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/autoconfigure/MyBatisPlusConfig.java @@ -1,4 +1,4 @@ -package cn.zyjblogs.starter.mybatisplus.config; +package cn.zyjblogs.starter.mybatisplus.autoconfigure; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; diff --git a/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/resources/META-INF/spring.factories b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/resources/META-INF/spring.factories index 458aef0..be86ee4 100644 --- a/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,2 +1,2 @@ org.springframework.boot.cn.zyjblogs.starter.feign.autoconfigure.EnableAutoConfiguration=\ - cn.zyjblogs.starter.mybatisplus.config.MyBatisPlusConfig + cn.zyjblogs.starter.mybatisplus.autoconfigure.MyBatisPlusConfig diff --git a/stater/zyjblogs-redis-spring-boot-starter/pom.xml b/stater/zyjblogs-redis-spring-boot-starter/pom.xml index ca8d039..f27a6ce 100644 --- a/stater/zyjblogs-redis-spring-boot-starter/pom.xml +++ b/stater/zyjblogs-redis-spring-boot-starter/pom.xml @@ -36,6 +36,10 @@ com.fasterxml.jackson.core jackson-databind + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + org.projectlombok lombok diff --git a/stater/zyjblogs-redis-spring-boot-starter/src/main/java/cn/zyjblogs/starter/redis/config/GenericJackson2JsonRedisSerializerEx.java b/stater/zyjblogs-redis-spring-boot-starter/src/main/java/cn/zyjblogs/starter/redis/config/GenericJackson2JsonRedisSerializerEx.java new file mode 100644 index 0000000..becd910 --- /dev/null +++ b/stater/zyjblogs-redis-spring-boot-starter/src/main/java/cn/zyjblogs/starter/redis/config/GenericJackson2JsonRedisSerializerEx.java @@ -0,0 +1,65 @@ +package cn.zyjblogs.starter.redis.config; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.springframework.cache.support.NullValue; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.SerializationException; + +import java.io.IOException; + +/** + * @author zhuyijun + */ +public class GenericJackson2JsonRedisSerializerEx implements RedisSerializer { + + protected GenericJackson2JsonRedisSerializer serializer = null; + + public GenericJackson2JsonRedisSerializerEx() { + ObjectMapper om = new ObjectMapper(); + om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + om.registerModule(new JavaTimeModule()); + this.serializer = new GenericJackson2JsonRedisSerializer(om); + } + + public GenericJackson2JsonRedisSerializerEx(ObjectMapper om) { + this.serializer = new GenericJackson2JsonRedisSerializer(om); + } + + @Override + public byte[] serialize(Object o) throws SerializationException { + return serializer.serialize(o); + } + + @Override + public Object deserialize(byte[] bytes) throws SerializationException { + return serializer.deserialize(bytes); + } + + + protected class NullValueSerializer extends StdSerializer { + private static final long serialVersionUID = 1999052150548658807L; + private final String classIdentifier="@class"; + + NullValueSerializer() { + super(NullValue.class); + } + + @Override + public void serialize(NullValue value, JsonGenerator jgen, SerializerProvider provider) throws IOException { + jgen.writeStartObject(); + jgen.writeStringField(this.classIdentifier, NullValue.class.getName()); + jgen.writeEndObject(); + } + } +} \ No newline at end of file diff --git a/stater/zyjblogs-redis-spring-boot-starter/src/main/java/cn/zyjblogs/starter/redis/config/RedisConfig.java b/stater/zyjblogs-redis-spring-boot-starter/src/main/java/cn/zyjblogs/starter/redis/config/RedisConfig.java index 9342417..b409c81 100644 --- a/stater/zyjblogs-redis-spring-boot-starter/src/main/java/cn/zyjblogs/starter/redis/config/RedisConfig.java +++ b/stater/zyjblogs-redis-spring-boot-starter/src/main/java/cn/zyjblogs/starter/redis/config/RedisConfig.java @@ -2,8 +2,11 @@ package cn.zyjblogs.starter.redis.config; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; @@ -35,11 +38,14 @@ public class RedisConfig { RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory); - //解决查询缓存转æ¢å¼‚常的问题 - ObjectMapper om = new ObjectMapper(); - om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); - om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance,ObjectMapper.DefaultTyping.NON_FINAL); - GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(om); +// //解决查询缓存转æ¢å¼‚常的问题 +// ObjectMapper om = new ObjectMapper(); +// om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); +// //注册java时间处ç†æ¨¡å— +// om.registerModule(new JavaTimeModule()); +// GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(om); + + GenericJackson2JsonRedisSerializerEx genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializerEx(); //åºåˆ—å·key value redisTemplate.setKeySerializer(new StringRedisSerializer()); diff --git a/stater/zyjblogs-web-spring-boot-starter/pom.xml b/stater/zyjblogs-web-spring-boot-starter/pom.xml index c68b72a..0b4c4bb 100644 --- a/stater/zyjblogs-web-spring-boot-starter/pom.xml +++ b/stater/zyjblogs-web-spring-boot-starter/pom.xml @@ -41,6 +41,10 @@ org.springframework.cloud spring-cloud-starter-openfeign + + org.springframework + spring-jdbc + diff --git a/stater/zyjblogs-web-spring-boot-starter/src/main/java/cn/zyjblogs/starter/web/autoconfig/GlobalExceptionHandlerAutoConfiguration.java b/stater/zyjblogs-web-spring-boot-starter/src/main/java/cn/zyjblogs/starter/web/autoconfig/GlobalExceptionHandlerAutoConfiguration.java new file mode 100644 index 0000000..6af5091 --- /dev/null +++ b/stater/zyjblogs-web-spring-boot-starter/src/main/java/cn/zyjblogs/starter/web/autoconfig/GlobalExceptionHandlerAutoConfiguration.java @@ -0,0 +1,21 @@ +package cn.zyjblogs.starter.web.autoconfig; + +import cn.zyjblogs.starter.web.hander.GlobalExceptionHandler; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author zhuyijun + */ +@Configuration +public class GlobalExceptionHandlerAutoConfiguration { + @Bean + @ConditionalOnMissingBean( + name = {"globalExceptionHandler"} + ) + public GlobalExceptionHandler globalExceptionHandler(){ + return new GlobalExceptionHandler(); + } +} diff --git a/stater/zyjblogs-web-spring-boot-starter/src/main/java/cn/zyjblogs/starter/web/hander/GlobalExceptionHandler.java b/stater/zyjblogs-web-spring-boot-starter/src/main/java/cn/zyjblogs/starter/web/hander/GlobalExceptionHandler.java index e6c4e76..d91f1d4 100644 --- a/stater/zyjblogs-web-spring-boot-starter/src/main/java/cn/zyjblogs/starter/web/hander/GlobalExceptionHandler.java +++ b/stater/zyjblogs-web-spring-boot-starter/src/main/java/cn/zyjblogs/starter/web/hander/GlobalExceptionHandler.java @@ -14,10 +14,14 @@ import java.util.List; import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; + +import cn.zyjblogs.starter.common.exception.AuthRuntimeException; +import ma.glasnost.orika.MappingException; import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.validation.BindException; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; @@ -30,45 +34,40 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.servlet.NoHandlerFoundException; +/** + * @author zhuyijun + */ @RestControllerAdvice public class GlobalExceptionHandler { private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); - private static final String TYPE_MISMATCH = "typeMismatch"; @ExceptionHandler({NoHandlerFoundException.class}) @ResponseStatus(org.springframework.http.HttpStatus.NOT_FOUND) public ResponseObject handleNoHandlerFoundException(NoHandlerFoundException exception) { log.error("NoHandlerFound", exception); String i18nCode = "web_starter_not_found"; - return ResponseResult.error(HttpCode.NOT_FOUND, i18nCode, i18nCode); + return ResponseResult.error(HttpCode.NOT_FOUND, i18nCode); } @ExceptionHandler({HttpRequestMethodNotSupportedException.class}) public ResponseObject handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) { log.error("HttpRequestMethodNotSupported", exception); String i18nCode = "web_starter_method_not_allowed"; - return ResponseResult.error(HttpCode.METHOD_NOT_ALLOWED, i18nCode, i18nCode); + return ResponseResult.error(HttpCode.METHOD_NOT_ALLOWED, i18nCode); } @ExceptionHandler({HttpMediaTypeNotSupportedException.class}) public ResponseObject handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException exception) { log.error("HttpMediaTypeNotSupported", exception); String i18nCode = "web_starter_unsupported_media_type"; - return ResponseResult.error(HttpCode.UNSUPPORTED_MEDIA_TYPE, i18nCode, i18nCode); - } - - @ExceptionHandler({Exception.class}) - public ResponseObject handleException(Exception exception) { - log.error("", exception); - String i18nCode = "web_starter_internal_server_error"; - return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, i18nCode, i18nCode); + return ResponseResult.error(HttpCode.UNSUPPORTED_MEDIA_TYPE, i18nCode); } @ExceptionHandler({MethodArgumentTypeMismatchException.class}) public ResponseObject handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException exception) { String i18nCode = "web_starter_property_format_error"; - return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode); + return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode); } @ExceptionHandler({ConstraintViolationException.class}) @@ -78,10 +77,10 @@ public class GlobalExceptionHandler { if (CollectionUtils.isEmpty(constraintViolations)) { log.warn("全局异常æ•èŽ·åˆ°äº†ConstraintViolationException,但是没有å‘现错误", exception); i18nCode = "web_starter_bad_request"; - return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode); + return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode); } else { i18nCode = constraintViolations.stream().findFirst().get().getMessage(); - return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode); + return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode); } } @@ -93,14 +92,26 @@ public class GlobalExceptionHandler { @ExceptionHandler({AbstractFrameworkException.class}) public ResponseObject handleFrameworkException(AbstractFrameworkException exception) { - log.error("系统异常:", exception); + log.error("全局异常æ•èŽ· 系统异常:{}", exception.getMessage()); return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, exception.getMessage()); } + @ExceptionHandler({AuthRuntimeException.class}) + public ResponseObject handleBusinessException(AuthRuntimeException exception) { + log.error("全局异常æ•èŽ· 系统异常:", exception); + return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, exception.getMessage()); + } + @ExceptionHandler({AbstractBusinessException.class}) public ResponseObject handleBusinessException(AbstractBusinessException exception) { - log.error("系统异常:", exception); + log.error("全局异常æ•èŽ· 系统异常:", exception); return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, exception.getMessage()); } + @ExceptionHandler({BadSqlGrammarException.class}) + public ResponseObject handleSqlException(Exception exception) { + log.error("全局异常æ•èŽ· SQL执行异常:{}", exception.getMessage()); + return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, "SQL执行异常",exception.getMessage()); + } + @ExceptionHandler({BindException.class}) public ResponseObject handleBindException(BindException exception) { BindingResult bindingResult = exception.getBindingResult(); @@ -109,18 +120,30 @@ public class GlobalExceptionHandler { @ExceptionHandler({HttpMessageNotReadableException.class}) public ResponseObject handleHttpMessageNotReadableException(HttpMessageNotReadableException exception) { - log.error("å‚æ•°æ ¼å¼ä¸æ­£ç¡®", exception); + log.error("全局异常æ•èŽ· å‚æ•°æ ¼å¼ä¸æ­£ç¡®", exception); return ResponseResult.error(HttpCode.BAD_REQUEST, exception.getMessage()); } private ResponseObject getByBindingResult(BindingResult bindingResult) { List fieldErrors = bindingResult.getFieldErrors(); if (fieldErrors.isEmpty()) { - log.error("æ•èŽ·åˆ°äº†å‚数校验错误,{}", bindingResult); + log.error("全局异常æ•èŽ· æ•èŽ·åˆ°äº†å‚数校验错误,{}", bindingResult); return ResponseResult.error(HttpCode.BAD_REQUEST, bindingResult.toString()); } else { FieldError fieldError = fieldErrors.get(0); return ResponseResult.error(HttpCode.BAD_REQUEST, fieldError.getDefaultMessage()); } } + + @ExceptionHandler({MappingException.class}) + public ResponseObject handleMappingException(Exception exception) { + log.error("全局异常æ•èŽ·ï¼šå¯¹è±¡è½¬åŒ–{}", exception.getMessage()); + return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, exception.getMessage()); + } + + @ExceptionHandler({Exception.class}) + public ResponseObject handleException(Exception exception) { + log.error("全局异常æ•èŽ·ï¼š{}", exception.getMessage()); + return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, exception.getMessage()); + } } diff --git a/stater/zyjblogs-web-spring-boot-starter/src/main/resources/META-INF/spring.factories b/stater/zyjblogs-web-spring-boot-starter/src/main/resources/META-INF/spring.factories index 74640fc..ed3a26f 100644 --- a/stater/zyjblogs-web-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/stater/zyjblogs-web-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ ## Auto Configure -#org.springframework.boot.cn.zyjblogs.starter.feign.autoconfigure.EnableAutoConfiguration=\ -# cn.zyjblogs.starter.web.config.Knife4jAutoConfigurationConfig +org.springframework.boot.cn.zyjblogs.starter.feign.autoconfigure.EnableAutoConfiguration=\ + cn.zyjblogs.starter.web.autoconfig.GlobalExceptionHandlerAutoConfiguration