From 75fd8a02c058f6a51e3c5ea36d997c157c070793 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期三, 24 十一月 2021 16:02:32 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- pamapi/src/main/java/com/pollex/pam/security/provider/OtpAuthenticationProvider.java | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/security/provider/OtpAuthenticationProvider.java b/pamapi/src/main/java/com/pollex/pam/security/provider/OtpAuthenticationProvider.java index 6fadbba..43138ce 100644 --- a/pamapi/src/main/java/com/pollex/pam/security/provider/OtpAuthenticationProvider.java +++ b/pamapi/src/main/java/com/pollex/pam/security/provider/OtpAuthenticationProvider.java @@ -2,9 +2,13 @@ import com.pollex.pam.config.ApplicationProperties; import com.pollex.pam.domain.Customer; +import com.pollex.pam.domain.OtpTmp; import com.pollex.pam.enums.CustomerDetailEnum; +import com.pollex.pam.enums.OtpLoginTypeEnum; +import com.pollex.pam.enums.OtpTmpStatusEnum; import com.pollex.pam.repository.CustomerRepository; import com.pollex.pam.security.token.OtpAuthenticationToken; +import com.pollex.pam.service.OtpTmpService; import com.pollex.pam.service.OtpWebService; import com.pollex.pam.service.dto.OtpResponseDTO; import com.pollex.pam.web.rest.vm.OtpAccount; @@ -38,6 +42,9 @@ @Autowired CustomerRepository customerRepository; + + @Autowired + OtpTmpService otpTmpService; public Authentication authenticate(OtpAuthenticationToken otpAuthenticationToken) throws AuthenticationException { OtpAccount otpAccount = otpAuthenticationToken.getPrincipal(); @@ -46,13 +53,15 @@ String otpCode = otpAuthenticationToken.getCredentials(); if(applicationProperty.isMockLogin()){ - return getCustomerToken(account, otpCode); + setVerrifiedOtpTmp(account, indexKey); + return getCustomerToken(account, otpCode, indexKey); } try { OtpResponseDTO otpResponseDTO = otpWebService.verifyOTP(indexKey, otpCode); if(otpResponseDTO.isSuccess()) { - return getCustomerToken(account, otpCode); + setVerrifiedOtpTmp(account, indexKey); + return getCustomerToken(account, otpCode, indexKey); } } catch (Exception e) { log.error("Exception: ", e); @@ -62,9 +71,18 @@ throw new AuthenticationCredentialsNotFoundException(""); } - private UsernamePasswordAuthenticationToken getCustomerToken(String account, String otpCode) { - // todo �摮�DB��撅祆迤撣貊鞊∴����畾essage����垢��脰�酉��� - Customer customer = customerRepository.findOneByEmailEqualsOrPhoneEquals(account, account).orElseThrow(() -> new UsernameNotFoundException("this customer is not in db, account = " + account)); + private void setVerrifiedOtpTmp(String account, String indexKey) { + OtpTmp otpTmp = otpTmpService.findByAccountAndIndexKey(account, indexKey); + otpTmp.setStatus(OtpTmpStatusEnum.VERRIFIED); + otpTmpService.save(otpTmp); + } + + private UsernamePasswordAuthenticationToken getCustomerToken(String account + , String otpCode, String indexKey) { + + + // todo �摮�DB��撅祆迤撣貊鞊∴����畾essage����垢��脰�酉��� + Customer customer = customerRepository.findOneByEmailEqualsOrPhoneEquals(account, account).orElseThrow(() -> new UsernameNotFoundException("this customer is not in register, account = " + account)); List<GrantedAuthority> grantedAuths = Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")); UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(account, otpCode, grantedAuths); @@ -73,6 +91,7 @@ details.put(CustomerDetailEnum.ID.getValue(), customer.getId().toString()); details.put(CustomerDetailEnum.NAME.getValue(), customer.getName()); details.put(CustomerDetailEnum.ACCOUNT.getValue(), account); +// details.put(CustomerDetailEnum.CONTACT_TYPE.getValue(), customer.getContactType()); authenticationToken.setDetails(details); return authenticationToken; -- Gitblit v1.8.0