mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-12 13:39:01 +08:00
fix(login): 增加登录参数空值校验
- 在OscChinaLoginHandler中增加identify空值校验 - 在WeChatCPLoginHandler中增加userid空值校验 - 在CasLoginHandler中增加username空值校验 - 在MiniAppLoginHandler中增加openId空值校验 - 在SmsLoginHandler中增加identify空值校验 - 在GiteeLoginHandler中增加identify空值校验 - 在WeChatLoginHandler中增加openId空值校验 - 在DingTalkLoginHandler中增加openId空值校验
This commit is contained in:
1 parent
6117c47d7c
commit
74110199e2
8 files changed
+196
-147
No files matched your search
+36
-28
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
@@ -41,47 +42,54 @@ import org.springframework.stereotype.Component;
|
||||
@AllArgsConstructor
|
||||
public class CasLoginHandler extends AbstractLoginHandler {
|
||||
|
||||
private final SysSocialDetailsMapper sysSocialDetailsMapper;
|
||||
private final SysSocialDetailsMapper sysSocialDetailsMapper;
|
||||
|
||||
private final SysUserService sysUserService;
|
||||
private final SysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* cas 回到的ticket
|
||||
* <p>
|
||||
* 通过ticket 调用CAS获取唯一标识
|
||||
* @param ticket
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public String identify(String ticket) {
|
||||
SysSocialDetails condition = new SysSocialDetails();
|
||||
condition.setType(LoginTypeEnum.CAS.getType());
|
||||
SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
|
||||
// remark 字段填写 CAS 服务器的URL
|
||||
Cas30ProxyTicketValidator cas30ProxyTicketValidator = new Cas30ProxyTicketValidator(socialDetails.getRemark());
|
||||
Assertion validate = cas30ProxyTicketValidator.validate(ticket, socialDetails.getRedirectUrl());
|
||||
return validate.getPrincipal().getName();
|
||||
}
|
||||
/**
|
||||
* cas 回到的ticket
|
||||
* <p>
|
||||
* 通过ticket 调用CAS获取唯一标识
|
||||
*
|
||||
* @param ticket
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public String identify(String ticket) {
|
||||
SysSocialDetails condition = new SysSocialDetails();
|
||||
condition.setType(LoginTypeEnum.CAS.getType());
|
||||
SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
|
||||
// remark 字段填写 CAS 服务器的URL
|
||||
Cas30ProxyTicketValidator cas30ProxyTicketValidator = new Cas30ProxyTicketValidator(socialDetails.getRemark());
|
||||
Assertion validate = cas30ProxyTicketValidator.validate(ticket, socialDetails.getRedirectUrl());
|
||||
return validate.getPrincipal().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 根据用户名获取用户信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户信息对象,如果用户不存在则返回null
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String username) {
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String username) {
|
||||
if (StrUtil.isBlank(username)) {
|
||||
log.warn("CAS用户名为空,无法获取用户信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setUsername(username);
|
||||
|
||||
R<UserInfo> userInfoR = sysUserService.getUserInfo(userDTO);
|
||||
|
||||
if (userInfoR.getData() == null) {
|
||||
log.info("CAS 不存在用户:{}", username);
|
||||
return null;
|
||||
}
|
||||
log.info("CAS 不存在用户:{}", username);
|
||||
return null;
|
||||
}
|
||||
|
||||
return userInfoR.getData();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@@ -91,6 +92,11 @@ public class DingTalkLoginHandler extends AbstractLoginHandler {
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String openId) {
|
||||
if (StrUtil.isBlank(openId)) {
|
||||
log.warn("钉钉openId为空,无法获取用户信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setWxDingUserid(openId);
|
||||
|
||||
|
||||
+5
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
@@ -87,6 +88,10 @@ public class GiteeLoginHandler extends AbstractLoginHandler {
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String identify) {
|
||||
if (StrUtil.isBlank(identify)) {
|
||||
log.warn("Gitee标识为空,无法获取用户信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setGiteeLogin(identify);
|
||||
|
||||
+62
-57
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@@ -46,72 +47,76 @@ import org.springframework.stereotype.Component;
|
||||
@AllArgsConstructor
|
||||
public class MiniAppLoginHandler extends AbstractLoginHandler {
|
||||
|
||||
private final SysUserService sysUserService;
|
||||
private final SysUserService sysUserService;
|
||||
|
||||
private final SysSocialDetailsMapper sysSocialDetailsMapper;
|
||||
private final SysSocialDetailsMapper sysSocialDetailsMapper;
|
||||
|
||||
/**
|
||||
* 小程序登录传入code
|
||||
* <p>
|
||||
* 通过code 调用qq 获取唯一标识
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String identify(String code) {
|
||||
SysSocialDetails condition = new SysSocialDetails();
|
||||
condition.setType(LoginTypeEnum.MINI_APP.getType());
|
||||
SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
|
||||
/**
|
||||
* 小程序登录传入code
|
||||
* <p>
|
||||
* 通过code 调用qq 获取唯一标识
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String identify(String code) {
|
||||
SysSocialDetails condition = new SysSocialDetails();
|
||||
condition.setType(LoginTypeEnum.MINI_APP.getType());
|
||||
SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
|
||||
|
||||
String url = String.format(SecurityConstants.MINI_APP_AUTHORIZATION_CODE_URL, socialDetails.getAppId(),
|
||||
socialDetails.getAppSecret(), code);
|
||||
String result = HttpUtil.get(url);
|
||||
log.debug("微信小程序响应报文:{}", result);
|
||||
JSONObject resultJsonObj = JSONUtil.parseObj(result);
|
||||
String url = String.format(SecurityConstants.MINI_APP_AUTHORIZATION_CODE_URL, socialDetails.getAppId(),
|
||||
socialDetails.getAppSecret(), code);
|
||||
String result = HttpUtil.get(url);
|
||||
log.debug("微信小程序响应报文:{}", result);
|
||||
JSONObject resultJsonObj = JSONUtil.parseObj(result);
|
||||
|
||||
if (resultJsonObj.containsKey("errcode")) {
|
||||
log.error("微信小程序登录失败:{}", result);
|
||||
throw new CheckedException("微信小程序登录失败");
|
||||
}
|
||||
if (resultJsonObj.containsKey("errcode")) {
|
||||
log.error("微信小程序登录失败:{}", result);
|
||||
throw new CheckedException("微信小程序登录失败");
|
||||
}
|
||||
|
||||
Object obj = resultJsonObj.get("openid");
|
||||
return obj.toString();
|
||||
}
|
||||
return resultJsonObj.getStr("openid");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据openId获取用户信息
|
||||
*
|
||||
* @param openId 用户openId
|
||||
* @return 用户信息对象,未找到时返回null
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String openId) {
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setMiniOpenid(openId);
|
||||
/**
|
||||
* 根据openId获取用户信息
|
||||
*
|
||||
* @param openId 用户openId
|
||||
* @return 用户信息对象,未找到时返回null
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String openId) {
|
||||
if (StrUtil.isBlank(openId)) {
|
||||
log.warn("小程序openId为空,无法获取用户信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
R<UserInfo> userInfoR = sysUserService.getUserInfo(userDTO);
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setMiniOpenid(openId);
|
||||
|
||||
if (userInfoR.getData() == null) {
|
||||
log.info("小程序不存在用户:{}", openId);
|
||||
return null;
|
||||
}
|
||||
R<UserInfo> userInfoR = sysUserService.getUserInfo(userDTO);
|
||||
|
||||
return userInfoR.getData();
|
||||
}
|
||||
if (userInfoR.getData() == null) {
|
||||
log.info("小程序不存在用户:{}", openId);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
*
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
user.setMiniOpenid(identify);
|
||||
sysUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
return userInfoR.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
*
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
user.setMiniOpenid(identify);
|
||||
sysUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+7
-2
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@@ -86,8 +87,7 @@ public class OscChinaLoginHandler extends AbstractLoginHandler {
|
||||
|
||||
JSONObject userInfo = JSONUtil.parseObj(resp);
|
||||
// 开源中国唯一标识
|
||||
String id = userInfo.getStr("id");
|
||||
return id;
|
||||
return userInfo.getStr("id");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,6 +98,11 @@ public class OscChinaLoginHandler extends AbstractLoginHandler {
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String identify) {
|
||||
if (StrUtil.isBlank(identify)) {
|
||||
log.warn("开源中国标识为空,无法获取用户信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setOscId(identify);
|
||||
|
||||
|
||||
+17
-11
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
@@ -48,23 +49,28 @@ public class SmsLoginHandler extends AbstractLoginHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过手机号获取用户信息
|
||||
* @param identify 手机号标识
|
||||
* @return 用户信息,未找到时返回null
|
||||
* 通过手机号获取用户信息
|
||||
* @param identify 手机号标识
|
||||
* @return 用户信息,未找到时返回null
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String identify) {
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setPhone(identify);
|
||||
|
||||
R<UserInfo> userInfoR = sysUserService.getUserInfo(userDTO);
|
||||
|
||||
if (userInfoR.getData() == null) {
|
||||
log.info("手机号 不存在用户:{}", identify);
|
||||
if (StrUtil.isBlank(identify)) {
|
||||
log.warn("手机号为空,无法获取用户信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
return userInfoR.getData();
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setPhone(identify);
|
||||
|
||||
R<UserInfo> userInfoR = sysUserService.getUserInfo(userDTO);
|
||||
|
||||
if (userInfoR.getData() == null) {
|
||||
log.info("手机号 不存在用户:{}", identify);
|
||||
return null;
|
||||
}
|
||||
|
||||
return userInfoR.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -82,6 +83,11 @@ public class WeChatCPLoginHandler extends AbstractLoginHandler {
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String openId) {
|
||||
if (StrUtil.isBlank(openId)) {
|
||||
log.warn("企业微信userid为空,无法获取用户信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setWxCpUserid(openId);
|
||||
|
||||
|
||||
+57
-49
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -42,63 +43,70 @@ import org.springframework.stereotype.Component;
|
||||
@AllArgsConstructor
|
||||
public class WeChatLoginHandler extends AbstractLoginHandler {
|
||||
|
||||
private final SysUserService sysUserService;
|
||||
private final SysUserService sysUserService;
|
||||
|
||||
private final SysSocialDetailsMapper sysSocialDetailsMapper;
|
||||
private final SysSocialDetailsMapper sysSocialDetailsMapper;
|
||||
|
||||
/**
|
||||
* 微信登录传入code
|
||||
* <p>
|
||||
* 通过code 调用qq 获取唯一标识
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String identify(String code) {
|
||||
SysSocialDetails condition = new SysSocialDetails();
|
||||
condition.setType(LoginTypeEnum.WECHAT.getType());
|
||||
SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
|
||||
/**
|
||||
* 微信登录传入code
|
||||
* <p>
|
||||
* 通过code 调用qq 获取唯一标识
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String identify(String code) {
|
||||
SysSocialDetails condition = new SysSocialDetails();
|
||||
condition.setType(LoginTypeEnum.WECHAT.getType());
|
||||
SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
|
||||
|
||||
String url = String.format(SecurityConstants.WX_AUTHORIZATION_CODE_URL, socialDetails.getAppId(),
|
||||
socialDetails.getAppSecret(), code);
|
||||
String result = HttpUtil.get(url);
|
||||
log.debug("微信响应报文:{}", result);
|
||||
String url = String.format(SecurityConstants.WX_AUTHORIZATION_CODE_URL, socialDetails.getAppId(),
|
||||
socialDetails.getAppSecret(), code);
|
||||
String result = HttpUtil.get(url);
|
||||
log.debug("微信响应报文:{}", result);
|
||||
|
||||
Object obj = JSONUtil.parseObj(result).get("openid");
|
||||
return obj.toString();
|
||||
}
|
||||
return JSONUtil.parseObj(result).getStr("openid");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据微信openId获取用户信息
|
||||
* @param openId 微信openId
|
||||
* @return 用户信息,未找到时返回null
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String openId) {
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setWxOpenid(openId);
|
||||
/**
|
||||
* 根据微信openId获取用户信息
|
||||
*
|
||||
* @param openId 微信openId
|
||||
* @return 用户信息,未找到时返回null
|
||||
*/
|
||||
@Override
|
||||
public UserInfo info(String openId) {
|
||||
if (StrUtil.isBlank(openId)) {
|
||||
log.warn("微信openId为空,无法获取用户信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
R<UserInfo> userInfoR = sysUserService.getUserInfo(userDTO);
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setWxOpenid(openId);
|
||||
|
||||
if (userInfoR.getData() == null) {
|
||||
log.info("微信 不存在用户:{}", openId);
|
||||
return null;
|
||||
}
|
||||
R<UserInfo> userInfoR = sysUserService.getUserInfo(userDTO);
|
||||
|
||||
return userInfoR.getData();
|
||||
}
|
||||
if (userInfoR.getData() == null) {
|
||||
log.info("微信 不存在用户:{}", openId);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
user.setWxOpenid(identify);
|
||||
sysUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
return userInfoR.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
*
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
user.setWxOpenid(identify);
|
||||
sysUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user