Merge pull request #872 from dataease/pr@dev@fix_sso_info_validate

fix: 修复sso用户信息缺失验证
This commit is contained in:
fit2cloud-chenyw 2021-09-24 18:19:42 +08:00 committed by GitHub
commit 7f8de5ce57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -77,6 +77,7 @@ public class AuthServer implements AuthApi {
ldapAddRequest.setEnabled(1L);
ldapAddRequest.setDeptId(1L);
ldapAddRequest.setRoleIds(new ArrayList<Long>(){{add(2L);}});
sysUserService.validateExistUser(ldapUserEntity.getUserName(), ldapUserEntity.getEmail());
sysUserService.saveLdapUsers(ldapAddRequest);
}

View File

@ -54,6 +54,7 @@ public class SSOServer {
SSOUserInfo ssoUserInfo = oidcXpackService.requestUserInfo(config, ssoToken.getAccessToken());
SysUserEntity sysUserEntity = authUserService.getUserBySub(ssoUserInfo.getSub());
if(null == sysUserEntity){
sysUserService.validateExistUser(ssoUserInfo.getUsername(), ssoUserInfo.getEmail());
sysUserService.saveOIDCUser(ssoUserInfo);
sysUserEntity = authUserService.getUserBySub(ssoUserInfo.getSub());
}

View File

@ -299,6 +299,33 @@ public class SysUserService {
return null;
}
public void validateExistUser(String userName, String email) {
SysUserExample example = new SysUserExample();
if (StringUtils.isNotBlank(userName)) {
example.createCriteria().andUsernameEqualTo(userName);
List<SysUser> users = sysUserMapper.selectByExample(example);
if(CollectionUtils.isNotEmpty(users)) {
throw new RuntimeException("用户ID【"+userName+"】已存在,请联系管理员");
}
}
/* if (StringUtils.isNotBlank(nickName)) {
example.createCriteria().andNickNameEqualTo(nickName);
List<SysUser> users = sysUserMapper.selectByExample(example);
if(CollectionUtils.isNotEmpty(users)) {
throw new RuntimeException("用户姓名【"+nickName+"】已存在,请联系管理员");
}
} */
if (StringUtils.isNotBlank(email)) {
example.createCriteria().andEmailEqualTo(email);
List<SysUser> users = sysUserMapper.selectByExample(example);
if(CollectionUtils.isNotEmpty(users)) {
throw new RuntimeException("用户邮箱【"+email+"】已存在,请联系管理员");
}
}
}
public List<SysUser> users(List<Long> userIds) {
return userIds.stream().map(sysUserMapper::selectByPrimaryKey).collect(Collectors.toList());