提交 54fc675e 编写于 作者: zhouweidong's avatar zhouweidong

转接sysUser

上级 73bdf4b6
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.uaa.service.impl.SysUserServiceImpl;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
@Service
@Primary
public class SysUserExService extends SysUserServiceImpl {
@Override
protected Class currentModelClass() {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
}
}
......@@ -8,7 +8,10 @@ import cn.ibizlab.core.uaa.extensions.domain.PermissionType;
import cn.ibizlab.core.uaa.extensions.helper.DingTalkHelper;
import cn.ibizlab.core.uaa.filter.SysRolePermissionSearchContext;
import cn.ibizlab.core.uaa.filter.SysUserSearchContext;
import cn.ibizlab.core.uaa.service.*;
import cn.ibizlab.core.uaa.service.ISysPSSystemService;
import cn.ibizlab.core.uaa.service.ISysRolePermissionService;
import cn.ibizlab.core.uaa.service.ISysUserRoleService;
import cn.ibizlab.core.uaa.service.ISysUserService;
import cn.ibizlab.util.domain.Token;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.security.AuthTokenUtil;
......@@ -27,8 +30,6 @@ import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;
......@@ -36,6 +37,7 @@ import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.Base64Utils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
......@@ -44,7 +46,6 @@ import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.sql.Wrapper;
import java.util.*;
@Service
......@@ -409,7 +410,7 @@ public class UAACoreService {
@Autowired
private ISysUserService userService;;
private ISysUserService userService;
@Cacheable( value="ibzuaa-model",key = "'catalog:SysOperator'")
public JSONObject getOptions(String catalog) {
......
package cn.ibizlab.core.uaa.extensions.service;
import cn.ibizlab.core.uaa.domain.SysOpenAccess;
import cn.ibizlab.core.uaa.domain.SysUser;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.service.ISysOpenAccessService;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.core.uaa.service.ISysUserService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.errors.InternalServerErrorException;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.AuthenticationUserService;
import cn.ibizlab.util.service.IBZUSERService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dingtalk.api.DefaultDingTalkClient;
......@@ -33,7 +33,7 @@ import org.springframework.util.StringUtils;
public class UserDingtalkRegisterService {
@Autowired
private IBZUSERService ibzuserService;
private ISysUserService sysUserService;
@Autowired
private AuthenticationUserService authenticationUserService;
......@@ -88,7 +88,7 @@ public class UserDingtalkRegisterService {
String userId = response.getUserid();
//先按userid或者username查
IBZUSER user = ibzuserService.getOne(Wrappers.<IBZUSER>lambdaQuery().eq(IBZUSER::getUserid,userId).or().eq(IBZUSER::getUsername,userId),false);
SysUser user = sysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUserid,userId).or().eq(SysUser::getUsername,userId),false);
if(user==null)
{
......@@ -96,7 +96,7 @@ public class UserDingtalkRegisterService {
SysUserAuth userAuth = sysUserAuthService.getOne(Wrappers.<SysUserAuth>lambdaQuery().eq(SysUserAuth::getIdentityType,"dingtalk").eq(SysUserAuth::getIdentifier, userId),false);
// 该钉钉用户注册过账号,登录系统
if (userAuth!=null) {
user = ibzuserService.getById(userAuth.getUserid());
user = sysUserService.getById(userAuth.getUserid());
if(user==null)
throw new BadRequestAlertException("未找到"+userId+"对应系统用户","UserDingtalkRegisterService","");
......@@ -138,12 +138,12 @@ public class UserDingtalkRegisterService {
.and(wrapper -> wrapper.eq(SysUserAuth::getIdentifier, response.getUserInfo().getOpenid()).or().eq(SysUserAuth::getIdentifier, response.getUserInfo().getUnionid())
),false);
IBZUSER user = null;
SysUser user = null;
// 该钉钉用户注册过账号,登录系统
if (userAuth!=null) {
user = ibzuserService.getById(userAuth.getUserid());
user = sysUserService.getById(userAuth.getUserid());
if (user == null)
user = ibzuserService.getOne(Wrappers.<IBZUSER>lambdaQuery().eq(IBZUSER::getUserid,response.getUserInfo().getOpenid()).or().eq(IBZUSER::getUsername,response.getUserInfo().getOpenid()),false);
user = sysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUserid,response.getUserInfo().getOpenid()).or().eq(SysUser::getUsername,response.getUserInfo().getOpenid()),false);
if(user!=null)
{
......
package cn.ibizlab.core.uaa.extensions.service;
import cn.ibizlab.core.uaa.domain.SysOpenAccess;
import cn.ibizlab.core.uaa.domain.SysUser;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.service.ISysOpenAccessService;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.core.uaa.service.ISysUserService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.errors.InternalServerErrorException;
import cn.ibizlab.util.helper.HttpUtils;
import cn.ibizlab.util.service.IBZUSERService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
......@@ -16,8 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.UnsupportedEncodingException;
/**
* 实体[IBZUSER] QQ用户注册接口实现
*/
......@@ -26,11 +24,11 @@ import java.io.UnsupportedEncodingException;
public class UserQQRegisterService {
@Autowired
private IBZUSERService ibzuserService;
private ISysUserService sysUserService;
@Autowired
private ISysUserAuthService sysUserAuthService;
@Autowired
private ISysOpenAccessService sysOpenAccessService;
......@@ -111,12 +109,12 @@ public class UserQQRegisterService {
returnObj.put("openid",openid);
SysUserAuth userAuth = sysUserAuthService.getOne(Wrappers.<SysUserAuth>lambdaQuery().eq(SysUserAuth::getIdentityType,"qq").eq(SysUserAuth::getIdentifier, openid),false);
IBZUSER user = null;
SysUser user = null;
// 该qq用户注册过账号,登录系统
if (userAuth!=null) {
user = ibzuserService.getById(userAuth.getUserid());
user = sysUserService.getById(userAuth.getUserid());
if (user == null)
user = ibzuserService.getOne(Wrappers.<IBZUSER>lambdaQuery().eq(IBZUSER::getUserid,openid).or().eq(IBZUSER::getUsername,openid),false);
user = sysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUserid,openid).or().eq(SysUser::getUsername,openid),false);
if(user!=null)
{
......
package cn.ibizlab.core.uaa.extensions.service;
import cn.ibizlab.core.uaa.domain.SysUser;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.core.uaa.service.ISysUserService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.CachedBeanCopier;
import cn.ibizlab.util.service.IBZUSERService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -15,12 +13,6 @@ import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import java.sql.Wrapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* 实体[IBZUSER] 用户注册接口实现
*/
......@@ -29,7 +21,7 @@ import java.util.UUID;
public class UserRegisterService {
@Autowired
private IBZUSERService ibzuserService;
private ISysUserService sysUserService;
@Autowired
private ISysUserAuthService sysUserAuthService;
......@@ -38,12 +30,12 @@ public class UserRegisterService {
private int pwencrymode;
public IBZUSER toRegister(IBZUSER account)
public SysUser toRegister(SysUser account)
{
return toRegister(account,null);
}
public IBZUSER toRegister(IBZUSER account, SysUserAuth sysUserAuth) {
public SysUser toRegister(SysUser account, SysUserAuth sysUserAuth) {
String domains = account.getDomains();
String loginname = account.getLoginname();
......@@ -68,8 +60,8 @@ public class UserRegisterService {
String username = loginname+(StringUtils.isEmpty(domains)?"":("|"+domains));
IBZUSER existedUser = ibzuserService.getOne(Wrappers.<IBZUSER>lambdaQuery().eq(IBZUSER::getLoginname,loginname)
.eq((!StringUtils.isEmpty(domains)),IBZUSER::getDomains,domains),false);
SysUser existedUser = sysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getLoginname,loginname)
.eq((!StringUtils.isEmpty(domains)),SysUser::getDomains,domains),false);
if(existedUser!=null)
......@@ -100,7 +92,7 @@ public class UserRegisterService {
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", username, password).getBytes());
account.setPassword(password);
account.setUserid(username);
ibzuserService.save(account);
sysUserService.save(account);
}
if(sysUserAuth!=null)
......
package cn.ibizlab.core.uaa.extensions.service;
import cn.ibizlab.core.uaa.domain.SysOpenAccess;
import cn.ibizlab.core.uaa.domain.SysUser;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.service.ISysOpenAccessService;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.core.uaa.service.ISysUserService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.errors.InternalServerErrorException;
import cn.ibizlab.util.helper.HttpUtils;
import cn.ibizlab.util.service.IBZUSERService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiSnsGetuserinfoBycodeRequest;
import com.dingtalk.api.response.OapiSnsGetuserinfoBycodeResponse;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
/**
* 实体[IBZUSER] 微信用户注册接口实现
*/
......@@ -31,11 +24,11 @@ import java.sql.Timestamp;
public class UserWechatRegisterService {
@Autowired
private IBZUSERService ibzuserService;
private ISysUserService sysUserService;
@Autowired
private ISysUserAuthService sysUserAuthService;
@Autowired
private ISysOpenAccessService sysOpenAccessService;
......@@ -90,12 +83,12 @@ public class UserWechatRegisterService {
.and(wrapper -> wrapper.eq(SysUserAuth::getIdentifier, openid).or().eq(SysUserAuth::getIdentifier, unionid)
),false);
IBZUSER user = null;
SysUser user = null;
// 该wechat用户注册过账号,登录系统
if (userAuth!=null) {
user = ibzuserService.getById(userAuth.getUserid());
user = sysUserService.getById(userAuth.getUserid());
if (user == null)
user = ibzuserService.getOne(Wrappers.<IBZUSER>lambdaQuery().eq(IBZUSER::getUserid,openid).or().eq(IBZUSER::getUsername,openid),false);
user = sysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUserid,openid).or().eq(SysUser::getUsername,openid),false);
if(user!=null)
{
......
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SysOpenAccess;
import cn.ibizlab.core.uaa.domain.SysUser;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.extensions.service.UserDingtalkRegisterService;
import cn.ibizlab.core.uaa.extensions.service.UserRegisterService;
......@@ -33,8 +34,6 @@ public class UserDingtalkRegisterResource {
@Autowired
private UserRegisterService userRegisterService;
@Autowired
private IBZUSERService ibzuserService;
@Autowired
private ISysUserAuthService sysUserAuthService;
@Autowired
private AuthTokenUtil jwtTokenUtil;
......@@ -127,24 +126,24 @@ public class UserDingtalkRegisterResource {
throw new BadRequestAlertException("钉钉信息openid为空", "UserDingtalkRegisterResource", "");
// 钉钉用户注册
IBZUSER ibzuser = new IBZUSER();
ibzuser.setPassword(password);
ibzuser.setLoginname(loginname);
ibzuser.setPersonname(StringUtils.isEmpty(personname)?nickname:personname);
ibzuser.setNickname(nickname);
ibzuser.setPhone(phone);
ibzuser.setEmail(email);
ibzuser.setDomains(domains);
SysUser sysUser = new SysUser();
sysUser.setPassword(password);
sysUser.setLoginname(loginname);
sysUser.setPersonname(StringUtils.isEmpty(personname)?nickname:personname);
sysUser.setNickname(nickname);
sysUser.setPhone(phone);
sysUser.setEmail(email);
sysUser.setDomains(domains);
SysUserAuth userAuth = new SysUserAuth();
userAuth.setIdentifier(openid);
userAuth.setIdentityType("dingtalk");
userRegisterService.toRegister(ibzuser,userAuth);
userRegisterService.toRegister(sysUser,userAuth);
// 生成登录token信息
userDetailsService.resetByUsername(ibzuser.getLoginname()+(StringUtils.isEmpty(ibzuser.getDomains())?"":("|"+ibzuser.getDomains())));
AuthenticationUser user = userDetailsService.loadUserByUsername(ibzuser.getLoginname()+(StringUtils.isEmpty(ibzuser.getDomains())?"":("|"+ibzuser.getDomains())));
userDetailsService.resetByUsername(sysUser.getLoginname()+(StringUtils.isEmpty(sysUser.getDomains())?"":("|"+sysUser.getDomains())));
AuthenticationUser user = userDetailsService.loadUserByUsername(sysUser.getLoginname()+(StringUtils.isEmpty(sysUser.getDomains())?"":("|"+sysUser.getDomains())));
final String token = jwtTokenUtil.generateToken(user);
AuthenticationUser user2 = new AuthenticationUser();
CachedBeanCopier.copy(user, user2);
......
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SysOpenAccess;
import cn.ibizlab.core.uaa.domain.SysUser;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.extensions.service.UserQQRegisterService;
import cn.ibizlab.core.uaa.extensions.service.UserRegisterService;
......@@ -126,24 +127,24 @@ public class UserQQRegisterResource {
throw new BadRequestAlertException("QQ信息openid为空", "UserQQRegisterResource", "");
// qq用户注册
IBZUSER ibzuser = new IBZUSER();
ibzuser.setPassword(password);
ibzuser.setLoginname(loginname);
ibzuser.setPersonname(StringUtils.isEmpty(personname)?nickname:personname);
ibzuser.setNickname(nickname);
ibzuser.setPhone(phone);
ibzuser.setEmail(email);
ibzuser.setDomains(domains);
SysUser sysUser = new SysUser();
sysUser.setPassword(password);
sysUser.setLoginname(loginname);
sysUser.setPersonname(StringUtils.isEmpty(personname)?nickname:personname);
sysUser.setNickname(nickname);
sysUser.setPhone(phone);
sysUser.setEmail(email);
sysUser.setDomains(domains);
SysUserAuth userAuth = new SysUserAuth();
userAuth.setIdentifier(openid);
userAuth.setIdentityType("qq");
userRegisterService.toRegister(ibzuser,userAuth);
userRegisterService.toRegister(sysUser,userAuth);
// 生成登录token信息
userDetailsService.resetByUsername(ibzuser.getLoginname()+(StringUtils.isEmpty(ibzuser.getDomains())?"":("|"+ibzuser.getDomains())));
AuthenticationUser user = userDetailsService.loadUserByUsername(ibzuser.getLoginname()+(StringUtils.isEmpty(ibzuser.getDomains())?"":("|"+ibzuser.getDomains())));
userDetailsService.resetByUsername(sysUser.getLoginname()+(StringUtils.isEmpty(sysUser.getDomains())?"":("|"+sysUser.getDomains())));
AuthenticationUser user = userDetailsService.loadUserByUsername(sysUser.getLoginname()+(StringUtils.isEmpty(sysUser.getDomains())?"":("|"+sysUser.getDomains())));
final String token = jwtTokenUtil.generateToken(user);
AuthenticationUser user2 = new AuthenticationUser();
CachedBeanCopier.copy(user, user2);
......
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SysUser;
import cn.ibizlab.core.uaa.extensions.service.UserRegisterService;
import cn.ibizlab.util.domain.IBZUSER;
import com.alibaba.fastjson.JSONObject;
......@@ -18,7 +19,7 @@ public class UserRegisterResource {
private UserRegisterService userRegisterService;
@PostMapping(value = "/uaa/register")
public ResponseEntity<JSONObject> register(@RequestBody IBZUSER ibzuser) {
public ResponseEntity<JSONObject> register(@RequestBody SysUser ibzuser) {
JSONObject object = new JSONObject();
// 响应结果
......
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SysOpenAccess;
import cn.ibizlab.core.uaa.domain.SysUser;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.extensions.service.UserRegisterService;
import cn.ibizlab.core.uaa.extensions.service.UserWechatRegisterService;
......@@ -34,8 +35,6 @@ public class UserWechatRegisterResource {
@Autowired
private UserRegisterService userRegisterService;
@Autowired
private IBZUSERService ibzuserService;
@Autowired
private ISysUserAuthService sysUserAuthService;
@Autowired
private AuthTokenUtil jwtTokenUtil;
......@@ -128,24 +127,24 @@ public class UserWechatRegisterResource {
throw new BadRequestAlertException("微信信息openid为空", "UserWechatRegisterResource", "");
// 微信用户注册
IBZUSER ibzuser = new IBZUSER();
ibzuser.setPassword(password);
ibzuser.setLoginname(loginname);
ibzuser.setPersonname(StringUtils.isEmpty(personname)?nickname:personname);
ibzuser.setNickname(nickname);
ibzuser.setPhone(phone);
ibzuser.setEmail(email);
ibzuser.setDomains(domains);
SysUser sysUser = new SysUser();
sysUser.setPassword(password);
sysUser.setLoginname(loginname);
sysUser.setPersonname(StringUtils.isEmpty(personname)?nickname:personname);
sysUser.setNickname(nickname);
sysUser.setPhone(phone);
sysUser.setEmail(email);
sysUser.setDomains(domains);
SysUserAuth userAuth = new SysUserAuth();
userAuth.setIdentifier(openid);
userAuth.setIdentityType("wechat");
userRegisterService.toRegister(ibzuser,userAuth);
userRegisterService.toRegister(sysUser,userAuth);
// 生成登录token信息
userDetailsService.resetByUsername(ibzuser.getLoginname()+(StringUtils.isEmpty(ibzuser.getDomains())?"":("|"+ibzuser.getDomains())));
AuthenticationUser user = userDetailsService.loadUserByUsername(ibzuser.getLoginname()+(StringUtils.isEmpty(ibzuser.getDomains())?"":("|"+ibzuser.getDomains())));
userDetailsService.resetByUsername(sysUser.getLoginname()+(StringUtils.isEmpty(sysUser.getDomains())?"":("|"+sysUser.getDomains())));
AuthenticationUser user = userDetailsService.loadUserByUsername(sysUser.getLoginname()+(StringUtils.isEmpty(sysUser.getDomains())?"":("|"+sysUser.getDomains())));
final String token = jwtTokenUtil.generateToken(user);
AuthenticationUser user2 = new AuthenticationUser();
CachedBeanCopier.copy(user, user2);
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册