|
@@ -1,8 +1,15 @@
|
|
|
package com.yonge.cooleshow.auth.core.provider;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
+import com.microsvc.toolkit.config.jwt.utils.RsaKeyHelper;
|
|
|
+import com.yonge.cooleshow.auth.api.dto.SysUserInfo;
|
|
|
+import com.yonge.cooleshow.auth.api.entity.LoginEntity;
|
|
|
+import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
+import com.yonge.cooleshow.auth.config.token.PhoneAuthenticationToken;
|
|
|
+import com.yonge.cooleshow.auth.service.SysUserDeviceService;
|
|
|
+import com.yonge.cooleshow.auth.service.SysUserService;
|
|
|
+import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
|
+import com.yonge.toolset.base.exception.BizException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
|
@@ -12,16 +19,15 @@ import org.springframework.security.core.AuthenticationException;
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
+import org.springframework.security.jwt.Jwt;
|
|
|
+import org.springframework.security.jwt.JwtHelper;
|
|
|
+import org.springframework.security.jwt.crypto.sign.RsaVerifier;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import com.yonge.cooleshow.auth.api.dto.SysUserInfo;
|
|
|
-import com.yonge.cooleshow.auth.api.entity.LoginEntity;
|
|
|
-import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
-import com.yonge.cooleshow.auth.config.token.PhoneAuthenticationToken;
|
|
|
-import com.yonge.cooleshow.auth.service.SysUserDeviceService;
|
|
|
-import com.yonge.cooleshow.auth.service.SysUserService;
|
|
|
-import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
|
-
|
|
|
+import java.security.interfaces.RSAPublicKey;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Objects;
|
|
|
+@Slf4j
|
|
|
public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider {
|
|
|
|
|
|
private UserDetailsService userDetailsService;
|
|
@@ -49,13 +55,32 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
|
|
|
|
|
|
String smsCode = loginEntity.getSmsCode();
|
|
|
String phone = loginEntity.getPhone();
|
|
|
+ // 二维码登录
|
|
|
String qrCode = loginEntity.getQrCode();
|
|
|
- if (StringUtils.isNotEmpty(qrCode) && StringUtils.isEmpty(smsCode)) {
|
|
|
+ // 授权Token登录
|
|
|
+ String authToken = loginEntity.getAuthToken();
|
|
|
+ if (StringUtils.isNotEmpty(qrCode)) {
|
|
|
// 二维码验证
|
|
|
boolean b = sysUserService.verifyQrCode(phone, qrCode);
|
|
|
if (!b) {
|
|
|
throw new BadCredentialsException("二维码校验失败");
|
|
|
}
|
|
|
+ } else if (StringUtils.isNotEmpty(authToken)) {
|
|
|
+ // 授权authToken登录
|
|
|
+ try {
|
|
|
+ RSAPublicKey rsaPublicKey = RsaKeyHelper.getRSAPublicKey("jmedu", "dayaedu", "jmedu.jks", "dayaedu");
|
|
|
+ Jwt jwt = JwtHelper.decodeAndVerify(authToken, new RsaVerifier(rsaPublicKey));
|
|
|
+
|
|
|
+ //获取jwt原始内容
|
|
|
+ String claims = jwt.getClaims();
|
|
|
+ if (StringUtils.isEmpty(claims)) {
|
|
|
+ throw new BizException("三方授权登录失败");
|
|
|
+ }
|
|
|
+ log.info("retrieveUser claims={}", claims);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("retrieveUser authToken={}", authToken, e);
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
// 验证码验证
|
|
|
boolean b = smsCodeService.verifyValidCode(phone, smsCode, "SMS_VERIFY_CODE_LOGIN");
|