Search in sources :

Example 6 with IamAccount

use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.

the class WxAuthServiceImpl method getAccount.

@Override
public IamAccount getAccount(BaseJwtAuthToken jwtToken) throws AuthenticationException {
    // 查询最新的记录
    LambdaQueryWrapper<IamAccount> queryWrapper = new LambdaQueryWrapper<IamAccount>().select(IamAccount::getAuthAccount, IamAccount::getUserType, IamAccount::getUserId, IamAccount::getStatus).eq(IamAccount::getUserType, jwtToken.getUserType()).eq(IamAccount::getAuthType, jwtToken.getAuthType()).eq(IamAccount::getAuthAccount, jwtToken.getAuthAccount()).orderByDesc(IamAccount::getId);
    IamAccount latestAccount = accountService.getSingleEntity(queryWrapper);
    if (latestAccount == null) {
        return null;
    }
    if (Cons.DICTCODE_ACCOUNT_STATUS.I.name().equals(latestAccount.getStatus())) {
        throw new AuthenticationException("用户账号已禁用! account=" + jwtToken.getAuthAccount());
    }
    if (Cons.DICTCODE_ACCOUNT_STATUS.L.name().equals(latestAccount.getStatus())) {
        throw new AuthenticationException("用户账号已锁定! account=" + jwtToken.getAuthAccount());
    }
    return latestAccount;
}
Also used : IamAccount(com.diboot.iam.entity.IamAccount) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 7 with IamAccount

use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.

the class PwdAuthServiceImpl method getAccount.

@Override
public IamAccount getAccount(BaseJwtAuthToken jwtToken) throws AuthenticationException {
    // 查询最新的记录
    LambdaQueryWrapper<IamAccount> queryWrapper = new LambdaQueryWrapper<IamAccount>().select(IamAccount::getAuthAccount, IamAccount::getAuthSecret, IamAccount::getSecretSalt, IamAccount::getUserType, IamAccount::getUserId, IamAccount::getStatus).eq(IamAccount::getUserType, jwtToken.getUserType()).eq(IamAccount::getAuthType, jwtToken.getAuthType()).eq(IamAccount::getAuthAccount, jwtToken.getAuthAccount()).eq(IamAccount::getTenantId, jwtToken.getTenantId()).orderByDesc(IamAccount::getId);
    IamAccount latestAccount = accountService.getSingleEntity(queryWrapper);
    if (latestAccount == null) {
        return null;
    }
    if (Cons.DICTCODE_ACCOUNT_STATUS.I.name().equals(latestAccount.getStatus())) {
        throw new AuthenticationException("用户账号已禁用! account=" + jwtToken.getAuthAccount());
    }
    if (Cons.DICTCODE_ACCOUNT_STATUS.L.name().equals(latestAccount.getStatus())) {
        throw new AuthenticationException("用户账号已锁定! account=" + jwtToken.getAuthAccount());
    }
    // 如果需要密码校验,那么无状态的时候不需要验证
    if (jwtToken.isValidPassword() && isPasswordMatched(latestAccount, jwtToken) == false) {
        throw new AuthenticationException("用户名或密码错误! account=" + jwtToken.getAuthAccount());
    }
    return latestAccount;
}
Also used : IamAccount(com.diboot.iam.entity.IamAccount) AuthenticationException(org.apache.shiro.authc.AuthenticationException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 8 with IamAccount

use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.

the class SSOAuthServiceImpl method getAccount.

@Override
public IamAccount getAccount(BaseJwtAuthToken jwtToken) throws AuthenticationException {
    // 查询最新的记录
    LambdaQueryWrapper<IamAccount> queryWrapper = new LambdaQueryWrapper<IamAccount>().select(IamAccount::getAuthAccount, IamAccount::getUserType, IamAccount::getUserId, IamAccount::getStatus).eq(IamAccount::getUserType, jwtToken.getUserType()).eq(IamAccount::getTenantId, jwtToken.getTenantId()).eq(IamAccount::getAuthAccount, jwtToken.getAuthAccount()).orderByDesc(IamAccount::getId);
    IamAccount latestAccount = accountService.getSingleEntity(queryWrapper);
    if (latestAccount == null) {
        return null;
    }
    if (Cons.DICTCODE_ACCOUNT_STATUS.I.name().equals(latestAccount.getStatus())) {
        throw new AuthenticationException("用户账号已禁用! account=" + jwtToken.getAuthAccount());
    }
    if (Cons.DICTCODE_ACCOUNT_STATUS.L.name().equals(latestAccount.getStatus())) {
        throw new AuthenticationException("用户账号已锁定! account=" + jwtToken.getAuthAccount());
    }
    return latestAccount;
}
Also used : IamAccount(com.diboot.iam.entity.IamAccount) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 9 with IamAccount

use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.

the class WxMpMemberAuthServiceImpl method applyToken.

@Override
@Transactional(rollbackFor = Exception.class)
public String applyToken(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");
    }
    WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
    // 获取用户信息
    IamAccount account = iamAccountService.getSingleEntity(Wrappers.<IamAccount>lambdaQuery().eq(IamAccount::getUserType, IamMember.class.getSimpleName()).eq(IamAccount::getAuthAccount, accessToken.getOpenId()).eq(IamAccount::getAuthType, Cons.DICTCODE_AUTH_TYPE.WX_MP.name()));
    MobileCredential credential = new MobileCredential(accessToken.getOpenId());
    credential.setAuthType(Cons.DICTCODE_AUTH_TYPE.WX_MP.name());
    credential.setUserTypeClass(IamMember.class);
    // 账户存在,直接登陆
    if (V.notEmpty(account)) {
        return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
    }
    // 账户不存在,表示首次进入,那么需要存储信息
    WxOAuth2UserInfo userInfo = wxMpService.getOAuth2Service().getUserInfo(accessToken, null);
    IamMember iamMember = mpInfo2IamMemberEntity(userInfo).setUserId(0L).setOrgId(0L).setUserType(IamMember.class.getSimpleName());
    iamMemberService.createEntity(iamMember);
    // 创建iam_account账号
    IamAccount iamAccount = createIamAccountEntity(iamMember, iamMember.getId(), IamMember.class);
    iamAccountService.createEntity(iamAccount);
    return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
}
Also used : MobileCredential(com.diboot.mobile.dto.MobileCredential) BusinessException(com.diboot.core.exception.BusinessException) IamAccount(com.diboot.iam.entity.IamAccount) IamMember(com.diboot.mobile.entity.IamMember) WxOAuth2AccessToken(me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken) WxOAuth2UserInfo(me.chanjar.weixin.common.bean.WxOAuth2UserInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with IamAccount

use of com.diboot.iam.entity.IamAccount in project diboot by dibo-software.

the class WxMpUserAuthServiceImpl method applyToken.

@Override
@Transactional(rollbackFor = Exception.class)
public String applyToken(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");
    }
    WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
    // 获取用户信息
    IamAccount account = iamAccountService.getSingleEntity(Wrappers.<IamAccount>lambdaQuery().eq(IamAccount::getUserType, IamUser.class.getSimpleName()).eq(IamAccount::getAuthAccount, accessToken.getOpenId()).eq(IamAccount::getAuthType, Cons.DICTCODE_AUTH_TYPE.WX_MP.name()));
    MobileCredential credential = new MobileCredential(accessToken.getOpenId());
    credential.setAuthType(Cons.DICTCODE_AUTH_TYPE.WX_MP.name());
    // 账户存在,直接登陆
    if (V.isEmpty(account)) {
        throw new BusinessException(Status.FAIL_INVALID_PARAM, "请登陆后绑定再使用快捷登陆");
    }
    return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
}
Also used : MobileCredential(com.diboot.mobile.dto.MobileCredential) BusinessException(com.diboot.core.exception.BusinessException) IamAccount(com.diboot.iam.entity.IamAccount) WxOAuth2AccessToken(me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IamAccount (com.diboot.iam.entity.IamAccount)12 BusinessException (com.diboot.core.exception.BusinessException)5 IamMember (com.diboot.mobile.entity.IamMember)4 AuthenticationException (org.apache.shiro.authc.AuthenticationException)4 IamUser (com.diboot.iam.entity.IamUser)3 WxOAuth2AccessToken (me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken)3 Transactional (org.springframework.transaction.annotation.Transactional)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 MobileCredential (com.diboot.mobile.dto.MobileCredential)2 WxOAuth2UserInfo (me.chanjar.weixin.common.bean.WxOAuth2UserInfo)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 BaseService (com.diboot.core.service.BaseService)1 LabelValue (com.diboot.core.vo.LabelValue)1 AuthService (com.diboot.iam.auth.AuthService)1 IamExtensible (com.diboot.iam.auth.IamExtensible)1 BaseLoginUser (com.diboot.iam.entity.BaseLoginUser)1 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)1