From c77d7ca74384847070f7ffb7dbbbc314be71b4f9 Mon Sep 17 00:00:00 2001 From: haoxin963 <525899665@qq.com> Date: Wed, 23 Jun 2021 23:31:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=94=A8=E6=A8=A1=E5=9D=97=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/constant/AuthConstants.java | 4 +- .../main/resources/META-INF/spring.factories | 2 +- .../config/AuthorizationServerConfig.java | 1 + .../com/xtoon/cloud/ops/auth/domain/User.java | 3 +- .../cloud/ops/auth/filter/CaptchaFilter.java | 3 +- .../ops/gateway/filter/AuthGlobalFilter.java | 4 +- .../cloud/sys/dto/AuthenticationDTO.java | 5 ++ .../xtoon-sys/xtoon-sys-server/pom.xml | 23 ++++++ .../cloud/sys/api/RegisterController.java | 4 +- .../assembler/AuthenticationDTOAssembler.java | 1 + .../impl/AuthenticationServiceImpl.java | 8 +- .../mapper/xml/SysPermissionMapper.xml | 8 +- .../persistence/mapper/xml/SysRoleMapper.xml | 4 +- .../mapper/xml/SysTenantMapper.xml | 2 +- .../persistence/mapper/xml/SysUserMapper.xml | 6 +- .../src/main/resources/logback-spring.xml | 73 +++++++++++++++++++ .../sys/domain/model/user/PasswordTest.java | 17 +++++ 17 files changed, 144 insertions(+), 24 deletions(-) create mode 100644 xtoon-service/xtoon-sys/xtoon-sys-server/src/main/resources/logback-spring.xml create mode 100644 xtoon-service/xtoon-sys/xtoon-sys-server/src/test/java/com/xtoon/cloud/sys/domain/model/user/PasswordTest.java diff --git a/xtoon-common/xtoon-common-core/src/main/java/com/xtoon/cloud/common/core/constant/AuthConstants.java b/xtoon-common/xtoon-common-core/src/main/java/com/xtoon/cloud/common/core/constant/AuthConstants.java index bfa22cd..0cb9c1c 100644 --- a/xtoon-common/xtoon-common-core/src/main/java/com/xtoon/cloud/common/core/constant/AuthConstants.java +++ b/xtoon-common/xtoon-common-core/src/main/java/com/xtoon/cloud/common/core/constant/AuthConstants.java @@ -72,11 +72,11 @@ public interface AuthConstants { */ String BCRYPT = "{bcrypt}"; - String USER_ID_KEY = "user_id"; + String USER_ID_KEY = "userId"; String USER_NAME_KEY = "userName"; - String CLIENT_ID_KEY = "client_id"; + String TENANT_ID_KEY = "tenantId"; /** * JWT存储权限前缀 diff --git a/xtoon-common/xtoon-common-web/src/main/resources/META-INF/spring.factories b/xtoon-common/xtoon-common-web/src/main/resources/META-INF/spring.factories index 3ca850d..6843332 100755 --- a/xtoon-common/xtoon-common-web/src/main/resources/META-INF/spring.factories +++ b/xtoon-common/xtoon-common-web/src/main/resources/META-INF/spring.factories @@ -1,2 +1,2 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.xtoon.cloud.common.web.util.BaseExceptionHandler + com.xtoon.cloud.common.web.util.BaseExceptionHandler \ No newline at end of file diff --git a/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/config/AuthorizationServerConfig.java b/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/config/AuthorizationServerConfig.java index e15903c..e9fccc7 100644 --- a/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/config/AuthorizationServerConfig.java +++ b/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/config/AuthorizationServerConfig.java @@ -113,6 +113,7 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap User user = (User) authentication.getUserAuthentication().getPrincipal(); map.put(AuthConstants.USER_ID_KEY, user.getId()); map.put(AuthConstants.USER_NAME_KEY, user.getUsername()); + map.put(AuthConstants.TENANT_ID_KEY, user.getTenantId()); ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(map); return accessToken; }; diff --git a/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/domain/User.java b/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/domain/User.java index 64b3cd2..25e5bdb 100644 --- a/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/domain/User.java +++ b/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/domain/User.java @@ -28,7 +28,7 @@ public class User implements UserDetails { private Boolean enabled; - private String clientId; + private String tenantId; private Collection authorities; @@ -37,6 +37,7 @@ public class User implements UserDetails { this.setUsername(authenticationDTO.getUserName()); this.setPassword(AuthConstants.BCRYPT + authenticationDTO.getPassword()); this.setEnabled(StatusEnum.ENABLE.getValue().equals(authenticationDTO.getStatus())); + this.setTenantId(authenticationDTO.getTenantId()); this.authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils.join(authenticationDTO.getPermissionCodes(), ",")); } diff --git a/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/filter/CaptchaFilter.java b/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/filter/CaptchaFilter.java index 2b5d6a5..4987d30 100644 --- a/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/filter/CaptchaFilter.java +++ b/xtoon-ops/xtoon-auth-server/src/main/java/com/xtoon/cloud/ops/auth/filter/CaptchaFilter.java @@ -44,8 +44,9 @@ public class CaptchaFilter extends OncePerRequestFilter { httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getOutputStream().write(JSONObject.toJSONString(Result.error("验证码不正确")).getBytes()); + } else { + filterChain.doFilter(httpServletRequest, httpServletResponse); } - filterChain.doFilter(httpServletRequest, httpServletResponse); } else { filterChain.doFilter(httpServletRequest, httpServletResponse); } diff --git a/xtoon-ops/xtoon-gateway-server/src/main/java/com/xtoon/cloud/ops/gateway/filter/AuthGlobalFilter.java b/xtoon-ops/xtoon-gateway-server/src/main/java/com/xtoon/cloud/ops/gateway/filter/AuthGlobalFilter.java index dfc2f0a..d246578 100644 --- a/xtoon-ops/xtoon-gateway-server/src/main/java/com/xtoon/cloud/ops/gateway/filter/AuthGlobalFilter.java +++ b/xtoon-ops/xtoon-gateway-server/src/main/java/com/xtoon/cloud/ops/gateway/filter/AuthGlobalFilter.java @@ -58,10 +58,10 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered { } // 存在token且不是黑名单,request写入JWT的载体信息 - String tenantId = request.getHeaders().getFirst(CommonConstant.TENANT_ID); +// String tenantId = request.getHeaders().getFirst(CommonConstant.TENANT_ID); request = exchange.getRequest().mutate() .header(AuthConstants.JWT_PAYLOAD_KEY, payload) - .header(CommonConstant.TENANT_ID, tenantId) +// .header(CommonConstant.TENANT_ID, tenantId) .build(); exchange = exchange.mutate().request(request).build(); return chain.filter(exchange); diff --git a/xtoon-service/xtoon-sys/xtoon-sys-interface/src/main/java/com/xtoon/cloud/sys/dto/AuthenticationDTO.java b/xtoon-service/xtoon-sys/xtoon-sys-interface/src/main/java/com/xtoon/cloud/sys/dto/AuthenticationDTO.java index 5622e7f..e7718f7 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-interface/src/main/java/com/xtoon/cloud/sys/dto/AuthenticationDTO.java +++ b/xtoon-service/xtoon-sys/xtoon-sys-interface/src/main/java/com/xtoon/cloud/sys/dto/AuthenticationDTO.java @@ -34,6 +34,11 @@ public class AuthenticationDTO implements Serializable { */ private String status; + /** + * 租户ID + */ + private String tenantId; + /** * 权限编码 */ diff --git a/xtoon-service/xtoon-sys/xtoon-sys-server/pom.xml b/xtoon-service/xtoon-sys/xtoon-sys-server/pom.xml index faccb17..e41f499 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-server/pom.xml +++ b/xtoon-service/xtoon-sys/xtoon-sys-server/pom.xml @@ -84,5 +84,28 @@ dubbo 2.7.8 + + org.junit.jupiter + junit-jupiter-api + RELEASE + test + + + + + + src/main/resources + true + + + src/main/java + + **/*.xml + **/*.json + **/*.ftl + + + + \ No newline at end of file diff --git a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/api/RegisterController.java b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/api/RegisterController.java index dcb751b..d561010 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/api/RegisterController.java +++ b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/api/RegisterController.java @@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; 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; /** @@ -21,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController; **/ @Api(tags = "注册") @RestController +@RequestMapping("/register") public class RegisterController { @Autowired @@ -31,7 +33,7 @@ public class RegisterController { */ @ApiOperation("注册租户") @SysLog("注册租户") - @PostMapping("/registerTenant") + @PostMapping("/tenant") public Result registerTenantAndUser(@RequestBody RegisterTenantCommand registerTenantCommand) { ValidatorUtils.validateEntity(registerTenantCommand, AddGroup.class); registerApplicationService.registerTenant(registerTenantCommand); diff --git a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/application/assembler/AuthenticationDTOAssembler.java b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/application/assembler/AuthenticationDTOAssembler.java index 0924901..bb07228 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/application/assembler/AuthenticationDTOAssembler.java +++ b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/application/assembler/AuthenticationDTOAssembler.java @@ -16,6 +16,7 @@ public class AuthenticationDTOAssembler { authenticationDTO.setUserId(user.getUserId().getId()); authenticationDTO.setUserName(user.getUserName().getName()); authenticationDTO.setPassword(user.getAccount().getPassword().getPassword()); + authenticationDTO.setTenantId(user.getTenantId().getId()); authenticationDTO.setStatus(user.getStatus().getValue()); return authenticationDTO; } diff --git a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/application/impl/AuthenticationServiceImpl.java b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/application/impl/AuthenticationServiceImpl.java index bf8c8fb..dc77b79 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/application/impl/AuthenticationServiceImpl.java +++ b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/application/impl/AuthenticationServiceImpl.java @@ -1,9 +1,7 @@ package com.xtoon.cloud.sys.application.impl; -import com.google.code.kaptcha.Producer; import com.xtoon.cloud.sys.application.PermissionQueryService; import com.xtoon.cloud.sys.application.assembler.AuthenticationDTOAssembler; -import com.xtoon.cloud.sys.domain.model.captcha.Captcha; import com.xtoon.cloud.sys.domain.model.captcha.CaptchaCode; import com.xtoon.cloud.sys.domain.model.captcha.CaptchaRepository; import com.xtoon.cloud.sys.domain.model.captcha.Uuid; @@ -14,11 +12,9 @@ import com.xtoon.cloud.sys.domain.service.CaptchaValidateService; import com.xtoon.cloud.sys.dto.AuthenticationDTO; import com.xtoon.cloud.sys.service.AuthenticationService; import org.apache.commons.lang.StringUtils; +import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.awt.image.BufferedImage; import java.util.List; /** @@ -27,7 +23,7 @@ import java.util.List; * @author haoxin * @date 2021-05-10 **/ -@Service +@DubboService public class AuthenticationServiceImpl implements AuthenticationService { @Autowired diff --git a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysPermissionMapper.xml b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysPermissionMapper.xml index 0872c96..a03b600 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysPermissionMapper.xml +++ b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysPermissionMapper.xml @@ -2,7 +2,7 @@ - select p.* from sys_permission p and p.del_flag = '0' @@ -13,20 +13,20 @@ order by p.order_num asc - select p.* from sys_role_permission rp LEFT JOIN sys_permission p on rp.permission_id = p.id where rp.role_id = #{roleId} and p.del_flag = '0' and p.status = '0' - select p.* from sys_role_permission rp LEFT JOIN sys_permission p on rp.permission_id = p.id LEFT JOIN sys_role r on r.id = rp.role_id where r.role_code = #{roleId} and p.del_flag = '0' and p.status = '0' - SELECT p.* FROM sys_role_permission rp LEFT JOIN sys_permission p ON rp.permission_id = p.id LEFT JOIN sys_user_role ur ON rp.role_id = ur.role_id diff --git a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysRoleMapper.xml b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysRoleMapper.xml index bb15131..a75e030 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysRoleMapper.xml +++ b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysRoleMapper.xml @@ -2,7 +2,7 @@ - select r.* from sys_role r and r.del_flag = '0' @@ -13,7 +13,7 @@ ORDER BY r.id desc - select r.* from sys_role r INNER JOIN sys_user_role ur on ur.role_id = r.id where ur.user_id = #{userId} and r.del_flag = '0' and r.status = '0' diff --git a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysTenantMapper.xml b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysTenantMapper.xml index 180d290..f6609bd 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysTenantMapper.xml +++ b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysTenantMapper.xml @@ -2,7 +2,7 @@ - SELECT t.* FROM diff --git a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysUserMapper.xml b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysUserMapper.xml index d3e395c..748562d 100644 --- a/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysUserMapper.xml +++ b/xtoon-service/xtoon-sys/xtoon-sys-server/src/main/java/com/xtoon/cloud/sys/infrastructure/persistence/mapper/xml/SysUserMapper.xml @@ -3,7 +3,7 @@