|
|
@@ -1,6 +1,8 @@ |
|
|
|
package com.ningdatech.pmapi.user.security.auth.credential; |
|
|
|
|
|
|
|
import com.ningdatech.basic.model.GenericResult; |
|
|
|
import com.ningdatech.pmapi.user.constant.LoginTypeEnum; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant; |
|
|
|
import com.ningdatech.zwdd.client.ZwddAuthClient; |
|
|
|
import org.springframework.security.authentication.AuthenticationProvider; |
|
|
|
import org.springframework.security.authentication.BadCredentialsException; |
|
|
@@ -30,19 +32,25 @@ public class CredentialAuthProvider implements AuthenticationProvider { |
|
|
|
throw new RuntimeException("CustomAuthProvider 只支持 CustomAuthToken"); |
|
|
|
} |
|
|
|
CredentialAuthToken authenticationToken = (CredentialAuthToken) authentication; |
|
|
|
String credentials = (String) authenticationToken.getCredentials(); |
|
|
|
String principal = (String) authenticationToken.getPrincipal(); |
|
|
|
|
|
|
|
UserDetails user = null; |
|
|
|
LoginTypeEnum loginTypeEnum = authenticationToken.getLoginTypeEnum(); |
|
|
|
switch (loginTypeEnum) { |
|
|
|
case DING_QR_LOGIN: { |
|
|
|
// TODO 补充浙政钉扫码逻辑 |
|
|
|
user = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal()); |
|
|
|
String code = (String) authenticationToken.getCredentials(); |
|
|
|
GenericResult<String> accountResult = zwddAuthClient.getAccountId(code); |
|
|
|
if (accountResult.isSuccess()) { |
|
|
|
throw new BadCredentialsException("login fail! 浙政钉校验失败"); |
|
|
|
} |
|
|
|
String accountId = accountResult.getData(); |
|
|
|
|
|
|
|
user = userDetailsService.loadUserByUsername(accountId + UserDeatilsServiceConstant.USER_DETAILS_SERVICE_SEPARATOR + loginTypeEnum.name()); |
|
|
|
} |
|
|
|
break; |
|
|
|
case PHONE_VERIFICATION_CODE_LOGIN: { |
|
|
|
// TODO |
|
|
|
user = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal()); |
|
|
|
// TODO 校验短信验证码 |
|
|
|
user = userDetailsService.loadUserByUsername(principal + UserDeatilsServiceConstant.USER_DETAILS_SERVICE_SEPARATOR + loginTypeEnum.name()); |
|
|
|
} |
|
|
|
break; |
|
|
|
case USERNAME_PASSWORD_LOGIN: { |
|
|
@@ -55,8 +63,6 @@ public class CredentialAuthProvider implements AuthenticationProvider { |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 将用户定义的user放入token中,这样可以在session中查询到所有自定义的用户信息 |
|
|
|
return new CredentialAuthToken(user, user.getPassword(), user.getAuthorities()); |
|
|
|
} |
|
|
@@ -72,6 +78,7 @@ public class CredentialAuthProvider implements AuthenticationProvider { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean supports(Class<?> authentication) { |
|
|
|
return CredentialAuthToken.class.isAssignableFrom(authentication); |
|
|
|