| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import cn.hutool.http.Method; |
| | | import com.aizuda.snailjob.common.core.constant.SystemConstants; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhyd.oauth.model.AuthResponse; |
| | |
| | | import org.dromara.common.social.config.properties.SocialProperties; |
| | | import org.dromara.common.social.utils.SocialUtils; |
| | | import org.dromara.common.tenant.helper.TenantHelper; |
| | | import org.dromara.system.domain.SysUser; |
| | | import org.dromara.system.domain.bo.SysSocialBo; |
| | | import org.dromara.system.domain.vo.SysClientVo; |
| | | import org.dromara.system.domain.vo.SysSocialVo; |
| | | import org.dromara.system.domain.vo.SysUserVo; |
| | |
| | | .formStr(MapUtil.of("access_token", authUserData.getToken().getAccessToken())) |
| | | .executeAsync(); |
| | | } |
| | | if ("KEYCLOAK".equals(authUserData.getSource())) { |
| | | // 新增KEYCLOAK用户自动创建逻辑 |
| | | String authId = authUserData.getSource() + authUserData.getUuid(); |
| | | List<SysSocialVo> list = sysSocialService.selectByAuthId(authId); |
| | | if (CollUtil.isEmpty(list)) { |
| | | // 自动创建新用户 |
| | | SysUser newUser = new SysUser(); |
| | | newUser.setUserName(authUserData.getUsername()); |
| | | newUser.setEmail(authUserData.getEmail()); |
| | | newUser.setNickName(authUserData.getNickname()); |
| | | newUser.setPassword("Initial123@"); // 初始密码需符合安全策略 |
| | | newUser.setStatus("0"); |
| | | |
| | | userMapper.insert(newUser); // 假设存在插入方法 |
| | | |
| | | // 创建社交绑定记录 |
| | | SysSocialBo newSocial = new SysSocialBo(); |
| | | newSocial.setUserId(newUser.getUserId()); |
| | | newSocial.setUserName(newUser.getUserName()); |
| | | newSocial.setAuthId(authId); |
| | | newSocial.setSource(authUserData.getSource()); |
| | | newSocial.setTenantId(newUser.getTenantId()); |
| | | newSocial.setOpenId(authUserData.getUuid()); |
| | | newSocial.setAccessToken(authUserData.getToken().getAccessToken()); |
| | | newSocial.setRefreshToken(authUserData.getToken().getRefreshToken()); |
| | | newSocial.setIdToken(authUserData.getToken().getIdToken()); |
| | | sysSocialService.insertByBo(newSocial); // 需确保服务有新增方法 |
| | | |
| | | // 重新查询确保数据可用 |
| | | list = sysSocialService.selectByAuthId(authId); |
| | | } else { |
| | | // 更新社交绑定记录 |
| | | SysSocialBo socialBo = new SysSocialBo(); |
| | | socialBo.setId(list.get(0).getId()); |
| | | socialBo.setAccessToken(authUserData.getToken().getAccessToken()); |
| | | socialBo.setRefreshToken(authUserData.getToken().getRefreshToken()); |
| | | socialBo.setIdToken(authUserData.getToken().getIdToken()); |
| | | sysSocialService.updateByBo(socialBo); |
| | | |
| | | } |
| | | } |
| | | |
| | | List<SysSocialVo> list = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid()); |
| | | if (CollUtil.isEmpty(list)) { |