|
@@ -10,6 +10,7 @@ import com.ym.mec.common.entity.HttpResponseResult;
|
|
import com.ym.mec.common.exception.BizException;
|
|
import com.ym.mec.common.exception.BizException;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
|
|
+import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
|
|
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
|
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
|
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
|
|
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -33,7 +34,8 @@ public class CbsQrCodeScanServiceImpl implements CbsQrCodeScanService {
|
|
@Override
|
|
@Override
|
|
public CbsQrCodeScanWrapper.UserInfo userInfo(CbsQrCodeScanWrapper.QrCodeScanUserInfoReq req) {
|
|
public CbsQrCodeScanWrapper.UserInfo userInfo(CbsQrCodeScanWrapper.QrCodeScanUserInfoReq req) {
|
|
CbsQrCodeScanWrapper.UserInfo userInfo = new CbsQrCodeScanWrapper.UserInfo();
|
|
CbsQrCodeScanWrapper.UserInfo userInfo = new CbsQrCodeScanWrapper.UserInfo();
|
|
- userInfo.setUsername(customTokenServices.loadAuthentication(req.getToken()).getName());
|
|
|
|
|
|
+ userInfo.setUsername(customTokenServices.loadAuthentication(req.getToken()).getName().split(":")[1]);
|
|
|
|
+ userInfo.setClientTypes("TEACHER");
|
|
return userInfo;
|
|
return userInfo;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -42,9 +44,9 @@ public class CbsQrCodeScanServiceImpl implements CbsQrCodeScanService {
|
|
OAuth2AccessToken oAuth2AccessToken = redisTokenStore.readAccessToken(req.getPassword());
|
|
OAuth2AccessToken oAuth2AccessToken = redisTokenStore.readAccessToken(req.getPassword());
|
|
if (oAuth2AccessToken != null) {
|
|
if (oAuth2AccessToken != null) {
|
|
OAuth2Authentication authentication = redisTokenStore.readAuthentication(req.getPassword());
|
|
OAuth2Authentication authentication = redisTokenStore.readAuthentication(req.getPassword());
|
|
- Map<String,String> hashMap = objectMapper.convertValue(authentication.getUserAuthentication().getPrincipal(), HashMap.class);
|
|
|
|
- String userId = hashMap.get("userId");
|
|
|
|
- SysUser sysUser = sysUserFeignService.queryUserById(Integer.parseInt(userId));
|
|
|
|
|
|
+ Map<String,Object> hashMap = objectMapper.convertValue(authentication.getUserAuthentication().getPrincipal(), HashMap.class);
|
|
|
|
+ Object userId = hashMap.get("userId");
|
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserById(Integer.parseInt(userId.toString()));
|
|
if (sysUser == null) {
|
|
if (sysUser == null) {
|
|
throw new BizException(HttpStatus.UNAUTHORIZED.value(), "用户不存在");
|
|
throw new BizException(HttpStatus.UNAUTHORIZED.value(), "用户不存在");
|
|
}
|
|
}
|
|
@@ -56,6 +58,6 @@ public class CbsQrCodeScanServiceImpl implements CbsQrCodeScanService {
|
|
qrCodeScanToken.setTokenData(result.getData().get("access_token"));
|
|
qrCodeScanToken.setTokenData(result.getData().get("access_token"));
|
|
return qrCodeScanToken;
|
|
return qrCodeScanToken;
|
|
}
|
|
}
|
|
- return null;
|
|
|
|
|
|
+ throw new InvalidTokenException("Invalid access token: " + req.getPassword());
|
|
}
|
|
}
|
|
}
|
|
}
|