From 468ff87bb511eda5553d72a3880ea4d8659e0ccd Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Tue, 18 Jan 2022 09:36:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=201.=E3=80=90?= =?UTF-8?q?=E5=8C=BA=E5=9D=97=E9=93=BE=E3=80=91=E5=8C=BA=E5=9D=97=E9=93=BE?= =?UTF-8?q?web=E7=95=8C=E9=9D=A2=E7=94=A8=E6=88=B7=E8=BA=AB=E4=BB=BD?= =?UTF-8?q?=E8=AE=A4=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/controller/GovLoginController.java | 22 ++++++++++++++ .../form/BcStaffAuthenticationFormDTO.java | 24 +++++++++++++++ .../com/epmet/service/GovLoginService.java | 8 +++++ .../service/impl/GovLoginServiceImpl.java | 29 ++++++++++++++++++- 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 epmet-auth/src/main/java/com/epmet/dto/form/BcStaffAuthenticationFormDTO.java diff --git a/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java b/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java index 386e162c02..deaa719859 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.HashMap; import java.util.List; /** @@ -121,5 +122,26 @@ public class GovLoginController { List staffOrgs = govLoginService.getMyOrgByPassword(formDTO); return new Result>().ok(staffOrgs); } + + /** + * 区块链web 系统身份认证 + * @param input + * @return + */ + @PostMapping("/blockchain/authentication") + public Result blockChainGetStaffInfoByPwd(@RequestBody BcStaffAuthenticationFormDTO input) { + ValidatorUtils.validateEntity(input); + + String customerId = input.getCustomerId(); + String mobile = input.getMobile(); + String password = input.getPassword(); + + String userId = govLoginService.blockChainStaffAuthenticationByPwd(customerId, mobile, password); + + HashMap m = new HashMap<>(); + m.put("userId", userId); + return new Result().ok(m); + } + } diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/BcStaffAuthenticationFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/BcStaffAuthenticationFormDTO.java new file mode 100644 index 0000000000..202f8073c9 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dto/form/BcStaffAuthenticationFormDTO.java @@ -0,0 +1,24 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @ClassName BcAdminLoginFormDTO + * @Description 区块链管理系统staff身份认证 + * @Author wangxianzhang + * @Date 2022/1/17 10:11 下午 + */ +@Data +public class BcStaffAuthenticationFormDTO { + + @NotBlank(message = "客户ID必填") + private String customerId; + + @NotBlank(message = "手机号必填") + private String mobile; + + @NotBlank(message = "密码必填") + private String password; +} diff --git a/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java b/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java index ea6329ceda..2a493fd54c 100644 --- a/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java @@ -76,4 +76,12 @@ public interface GovLoginService { * @Date 2020/6/30 22:43 **/ List getMyOrgByPassword(StaffOrgsFormDTO formDTO); + + /** + * 区块链系统通过用户密码认证身份 + * @param mobile + * @param password + * @return + */ + String blockChainStaffAuthenticationByPwd(String customerId, String mobile, String password); } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java index 86569434c2..8a36124e4d 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java @@ -5,8 +5,10 @@ import com.epmet.common.token.constant.LoginConstant; import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.security.dto.GovTokenDto; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.security.password.PasswordUtils; @@ -46,7 +48,7 @@ import java.util.stream.Collectors; * @Date 2020/4/20 10:56 */ @Service -public class GovLoginServiceImpl implements GovLoginService { +public class GovLoginServiceImpl implements GovLoginService, ResultDataResolver { private static final Logger logger = LoggerFactory.getLogger(GovLoginServiceImpl.class); private static final String SEND_SMS_CODE_ERROR = "发送短信验证码异常,手机号[%s],code[%s],msg[%s]"; @Autowired @@ -490,5 +492,30 @@ public class GovLoginServiceImpl implements GovLoginService { } return result.getData(); } + + @Override + public String blockChainStaffAuthenticationByPwd(String customerId, String mobile, String password) { + + GovWebOperLoginFormDTO form = new GovWebOperLoginFormDTO(); + form.setCustomerId(customerId); + form.setMobile(mobile); + + GovWebOperLoginResultDTO staff = getResultDataOrThrowsException(epmetUserFeignClient.getStaffIdAndPwd(form), ServiceConstant.EPMET_USER_SERVER, + EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), + String.format("【区块链获取用户信息】根据手机号%s和指定客户ID:%s查找用户信息失败", mobile, customerId), + "查询用户失败"); + + if (staff == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), + String.format("【区块链获取用户信息】根据手机号%s和指定客户ID:%s查找用户信息失败", mobile, customerId)); + } + + if (!PasswordUtils.matches(password, staff.getPassWord())) { + // 密码不匹配 + throw new EpmetException(EpmetErrorCode.ERR10004.getCode(), String.format("【区块链获取用户信息】密码不匹配,手机号:%s", mobile)); + } + + return staff.getUserId(); + } }