use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.
the class BaseJwtRealm method doGetAuthenticationInfo.
/**
* 获取认证信息
* @param token
* @return
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
BaseJwtAuthToken jwtToken = (BaseJwtAuthToken) token;
String authAccount = (String) jwtToken.getPrincipal();
if (V.isEmpty(authAccount)) {
throw new AuthenticationException("无效的用户标识");
} else {
// 获取认证方式
AuthService authService = AuthServiceFactory.getAuthService(jwtToken.getAuthType());
if (authService == null) {
jwtToken.clearAuthtoken();
throw new AuthenticationException("认证类型: " + jwtToken.getAuthType() + " 的AccountAuthService未实现!");
}
IamAccount account = authService.getAccount(jwtToken);
// 登录失败则抛出相关异常
if (account == null) {
jwtToken.clearAuthtoken();
throw new AuthenticationException("用户账号或密码错误!");
}
// 获取当前user对象并缓存
BaseLoginUser loginUser = null;
BaseService userService = ContextHelper.getBaseServiceByEntity(jwtToken.getUserTypeClass());
if (userService != null) {
loginUser = (BaseLoginUser) userService.getEntity(account.getUserId());
} else {
throw new AuthenticationException("用户 " + jwtToken.getUserTypeClass().getName() + " 相关的Service未定义!");
}
if (loginUser == null) {
throw new AuthenticationException("用户不存在");
}
loginUser.setAuthToken(jwtToken.getAuthtoken());
IamExtensible iamExtensible = getIamUserRoleService().getIamExtensible();
if (iamExtensible != null) {
LabelValue extentionObj = iamExtensible.getUserExtentionObj(jwtToken.getUserTypeClass().getSimpleName(), account.getUserId(), jwtToken.getExtObj());
if (extentionObj != null) {
loginUser.setExtentionObj(extentionObj);
}
}
// 清空当前用户缓存
this.clearCachedAuthorizationInfo(IamSecurityUtils.getSubject().getPrincipals());
return new SimpleAuthenticationInfo(loginUser, jwtToken.getCredentials(), this.getName());
}
}
use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.
the class IamAccountServiceImpl method getAuthAccount.
@Override
public String getAuthAccount(String userType, Long userId) {
LambdaQueryWrapper<IamAccount> queryWrapper = new QueryWrapper<IamAccount>().lambda().select(IamAccount::getAuthAccount).eq(IamAccount::getUserType, userType).eq(IamAccount::getUserId, userId);
IamAccount account = getSingleEntity(queryWrapper);
return account != null ? account.getAuthAccount() : null;
}
use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.
the class WxMaMemberAuthServiceImpl method getAndSaveWxMember.
@Override
public IamMemberVO getAndSaveWxMember(WxMemberDTO wxInfoDTO) {
// 校验用户是否存在,如果已经存在,那么直接返回数据
IamMember iamMember = iamMemberService.getSingleEntity(Wrappers.<IamMember>lambdaQuery().eq(IamMember::getOpenid, wxInfoDTO.getOpenid()).eq(IamMember::getStatus, Cons.DICTCODE_ACCOUNT_STATUS.A.name()));
if (V.notEmpty(iamMember)) {
return Binder.convertAndBindRelations(iamMember, IamMemberVO.class);
}
// 创建微信用户基本信息
IamMember wxMember = maInfo2IamMemberEntity(wxInfoDTO).setUserId(0L).setOrgId(0L).setUserType(IamMember.class.getSimpleName());
boolean success = iamMemberService.createEntity(wxMember);
if (!success) {
throw new BusinessException(Status.FAIL_OPERATION, "创建用户信息失败!");
}
// 创建当前用户的账户
IamAccount iamAccount = createIamAccountEntity(wxMember, wxMember.getId(), IamMember.class);
success = iamAccountService.createEntity(iamAccount);
if (!success) {
throw new BusinessException(Status.FAIL_OPERATION, "创建系统账户失败!");
}
return Binder.convertAndBindRelations(wxMember, IamMemberVO.class);
}
use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.
the class WxMaUserAuthServiceImpl method bindWxMa.
@Override
public IamMember bindWxMa(WxMemberDTO wxInfoDTO) throws Exception {
IamUser iamUser = IamSecurityUtils.getCurrentUser();
if (V.isEmpty(iamUser)) {
throw new BusinessException(Status.FAIL_OPERATION, "请登陆后绑定");
}
// 获取用户信息
IamMember iamMember = iamMemberService.getSingleEntity(Wrappers.<IamMember>lambdaQuery().eq(IamMember::getUserType, IamUser.class.getSimpleName()).eq(IamMember::getUserId, iamUser.getId()));
if (V.notEmpty(iamMember)) {
throw new BusinessException(Status.FAIL_OPERATION, "用户已经绑定");
}
iamMember = maInfo2IamMemberEntity(wxInfoDTO).setUserId(iamUser.getId()).setOrgId(iamUser.getOrgId()).setUserType(IamUser.class.getSimpleName());
boolean success = iamMemberService.createEntity(iamMember);
if (!success) {
throw new BusinessException(Status.FAIL_OPERATION, "绑定用户信息失败!");
}
// 创建当前用户的账户
IamAccount iamAccount = createIamAccountEntity(iamMember, iamMember.getUserId(), IamUser.class);
success = iamAccountService.createEntity(iamAccount);
if (!success) {
throw new BusinessException(Status.FAIL_OPERATION, "创建系统账户失败!");
}
return iamMember;
}
use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.
the class WxMpUserAuthServiceImpl method bindWxMp.
@Override
public IamMember bindWxMp(String code, String state) throws Exception {
// 校验STATE
if (V.notEmpty(STATE) && !STATE.equals(state)) {
throw new BusinessException(Status.FAIL_INVALID_PARAM, "非法来源");
}
if (V.isEmpty(code)) {
log.error("请求参数有误: code = null");
throw new BusinessException(Status.FAIL_INVALID_PARAM, "请求参数有误: code is null");
}
IamUser iamUser = IamSecurityUtils.getCurrentUser();
if (V.isEmpty(iamUser)) {
throw new BusinessException(Status.FAIL_OPERATION, "请登陆后绑定");
}
WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
// 获取用户信息
IamMember iamMember = iamMemberService.getSingleEntity(Wrappers.<IamMember>lambdaQuery().eq(IamMember::getUserType, IamUser.class.getSimpleName()).eq(IamMember::getUserId, iamUser.getId()));
if (V.notEmpty(iamMember)) {
throw new BusinessException(Status.FAIL_OPERATION, "请勿重新绑定");
}
// 创建绑定
WxOAuth2UserInfo userInfo = wxMpService.getOAuth2Service().getUserInfo(accessToken, null);
iamMember = mpInfo2IamMemberEntity(userInfo).setUserId(iamUser.getId()).setOrgId(iamUser.getOrgId()).setUserType(IamUser.class.getSimpleName());
iamMemberService.createEntity(iamMember);
// 基于openId 创建iam_account账号
IamAccount iamAccount = createIamAccountEntity(iamMember, iamMember.getUserId(), IamUser.class);
iamAccountService.createEntity(iamAccount);
return iamMember;
}
Aggregations