|
|
@@ -1,8 +1,11 @@ |
|
|
|
package com.ningdatech.pmapi.user.security.auth.credential; |
|
|
|
|
|
|
|
import com.ningdatech.basic.model.GenericResult; |
|
|
|
import com.ningdatech.pmapi.sms.constant.VerificationCodeType; |
|
|
|
import com.ningdatech.pmapi.sms.helper.VerifyCodeCheckHelper; |
|
|
|
import com.ningdatech.pmapi.user.constant.LoginTypeEnum; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.validate.CommonLoginException; |
|
|
|
import com.ningdatech.zwdd.client.ZwddAuthClient; |
|
|
|
import org.springframework.security.authentication.AuthenticationProvider; |
|
|
|
import org.springframework.security.authentication.BadCredentialsException; |
|
|
@@ -27,6 +30,11 @@ public class CredentialAuthProvider implements AuthenticationProvider { |
|
|
|
|
|
|
|
private ZwddAuthClient zwddAuthClient; |
|
|
|
|
|
|
|
private Boolean phoneVerifyCodeSkip; |
|
|
|
|
|
|
|
private VerifyCodeCheckHelper verifyCodeCheckHelper; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Authentication authenticate(Authentication authentication) throws AuthenticationException { |
|
|
|
if (!(authentication instanceof CredentialAuthToken)) { |
|
|
@@ -37,6 +45,7 @@ public class CredentialAuthProvider implements AuthenticationProvider { |
|
|
|
|
|
|
|
UserDetails user = null; |
|
|
|
LoginTypeEnum loginTypeEnum = authenticationToken.getLoginTypeEnum(); |
|
|
|
String credentials = (String) authenticationToken.getCredentials(); |
|
|
|
switch (loginTypeEnum) { |
|
|
|
case DING_QR_LOGIN: { |
|
|
|
String code = (String) authenticationToken.getCredentials(); |
|
|
@@ -52,7 +61,13 @@ public class CredentialAuthProvider implements AuthenticationProvider { |
|
|
|
} |
|
|
|
break; |
|
|
|
case PHONE_VERIFICATION_CODE_LOGIN: { |
|
|
|
// TODO 校验短信验证码 |
|
|
|
if (!phoneVerifyCodeSkip) { |
|
|
|
// 校验短信验证码 |
|
|
|
boolean verificationResult = verifyCodeCheckHelper.verification(VerificationCodeType.LOGIN, principal, credentials); |
|
|
|
if (!verificationResult) { |
|
|
|
throw new CommonLoginException("验证码错误"); |
|
|
|
} |
|
|
|
} |
|
|
|
user = userDetailsService.loadUserByUsername(principal + UserDeatilsServiceConstant.USER_DETAILS_SERVICE_SEPARATOR + loginTypeEnum.name()); |
|
|
|
} |
|
|
|
break; |
|
|
@@ -95,4 +110,12 @@ public class CredentialAuthProvider implements AuthenticationProvider { |
|
|
|
this.zwddAuthClient = zwddAuthClient; |
|
|
|
} |
|
|
|
|
|
|
|
public void setVerifyCodeCheckHelper(VerifyCodeCheckHelper verifyCodeCheckHelper) { |
|
|
|
this.verifyCodeCheckHelper = verifyCodeCheckHelper; |
|
|
|
} |
|
|
|
|
|
|
|
public void setPhoneVerifyCodeSkip(Boolean phoneVerifyCodeSkip) { |
|
|
|
this.phoneVerifyCodeSkip = phoneVerifyCodeSkip; |
|
|
|
} |
|
|
|
|
|
|
|
} |