Search in sources :

Example 6 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class AccountManageResource method invalidateAccount.

@Path("accounts/{id}")
@DELETE
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccountVO> invalidateAccount(@PathParam("id") String id, @QueryParam("userCode") String userCode) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        Account account = accessor.remove(id, Account.class);
        AccountVO accountVO = AccountVO.transform(account, true);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(accountVO);
    } catch (UserInterfaceException ex) {
        return new DataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("Invalidate account fail.", ex);
        }
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) DataVO(org.mx.service.rest.vo.DataVO) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 7 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class AccountManageResource method changePassword.

@Path("accounts/{id}/password/change")
@POST
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccountVO> changePassword(@PathParam("id") String id, @QueryParam("userCode") String userCode, ChangePasswordVO vo) {
    sessionDataStore.setCurrentUserCode(userCode);
    if (vo == null) {
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM));
    }
    String oldPassword = vo.getOldPassword();
    String newPassword = vo.getNewPassword();
    try {
        Account account = accountManageService.changePassword(id, oldPassword, newPassword);
        AccountVO accountVO = AccountVO.transform(account, true);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(accountVO);
    } catch (UserInterfaceException ex) {
        return new DataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error(String.format("Change user[%s] password fail.", userCode), ex);
        }
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) DataVO(org.mx.service.rest.vo.DataVO) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 8 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class AccountManageResource method saveAccount.

@Path("accounts/{id}")
@PUT
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccountVO> saveAccount(@PathParam("id") String id, @QueryParam("userCode") String userCode, AccountInfoVO accountInfoVO) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        accountInfoVO.setId(id);
        Account account = accountManageService.saveAccount(accountInfoVO.getAccountInfo());
        AccountVO accountVO = AccountVO.transform(account, true);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(accountVO);
    } catch (UserInterfaceException ex) {
        return new DataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("Save account fail.", ex);
        }
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) DataVO(org.mx.service.rest.vo.DataVO) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 9 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class AccountManageServiceCommonImpl method saveAccount.

/**
 * {@inheritDoc}
 *
 * @see AccountManageService#saveAccount(AccountInfo)
 */
@Override
public Account saveAccount(AccountInfo accountInfo) {
    if (accountInfo == null) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    try {
        String accountId = accountInfo.getAccountId();
        Account account;
        if (!StringUtils.isBlank(accountId)) {
            account = accessor.getById(accountId, Account.class);
            if (account == null) {
                if (logger.isErrorEnabled()) {
                    logger.error(String.format("The Account entity[%s] not found.", accountId));
                }
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
            }
        // 这里不允许修改密码,密码必须通过另外途径进行修改
        } else {
            String password = accountInfo.getPassword();
            if (StringUtils.isBlank(password)) {
                password = "ds110119";
            }
            account = EntityFactory.createEntity(Account.class);
            account.setPassword(DigestUtils.md5(password));
        }
        account.setCode(accountInfo.getCode());
        if (StringUtils.isBlank(accountInfo.getOwnerId())) {
            if (!"admin".equals(accountInfo.getCode())) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOALLOCATE_USER);
            }
        } else {
            User owner = accessor.getById(accountInfo.getOwnerId(), User.class);
            if (owner == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
            }
            account.setOwner(owner);
            account.setName(owner.getFullName());
        }
        account.setDesc(accountInfo.getDesc());
        if (account.getRoles() != null && !account.getRoles().isEmpty()) {
            account.getRoles().clear();
        }
        for (String roleId : accountInfo.getRoleIds()) {
            Role role = accessor.getById(roleId, Role.class);
            if (role == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
            }
            account.getRoles().add(role);
        }
        account.setValid(accountInfo.isValid());
        account = this.save(account);
        if (operateLogService != null) {
            operateLogService.writeLog(String.format("保存账户[code=%s, name=%s]成功。", account.getCode(), account.getName()));
        }
        return account;
    } catch (UserInterfaceDalErrorException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.DB_OPERATE_FAIL);
    } catch (NoSuchAlgorithmException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_DIGEST_PASSWORD_FAIL);
    }
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) Account(org.mx.comps.rbac.dal.entity.Account) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) User(org.mx.comps.rbac.dal.entity.User) UserInterfaceDalErrorException(org.mx.dal.error.UserInterfaceDalErrorException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 10 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class AccountManageServiceCommonImpl method changePersonal.

/**
 * {@inheritDoc}
 *
 * @see AccountManageService#changePersonal(AccountPersonalInfo)
 */
@Override
public Account changePersonal(AccountPersonalInfo accountPersonalInfo) {
    Account account = accessor.getById(accountPersonalInfo.getId(), Account.class);
    if (account == null) {
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
    }
    account.setFavoriteTools(accountPersonalInfo.getFavoriteTools());
    account = this.save(account);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("修改账户[code=%s, name=%s]的个性化信息成功。", account.getCode(), account.getName()));
    }
    return account;
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException)

Aggregations

Account (org.mx.comps.rbac.dal.entity.Account)26 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)14 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)12 User (org.mx.comps.rbac.dal.entity.User)10 Role (org.mx.comps.rbac.dal.entity.Role)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 AccountManageService (org.mx.comps.rbac.service.AccountManageService)8 Test (org.junit.Test)6 UserManageService (org.mx.comps.rbac.service.UserManageService)6 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)6 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)5 UserInterfaceException (org.mx.error.UserInterfaceException)5 DataVO (org.mx.service.rest.vo.DataVO)5 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)5 Date (java.util.Date)4 HashSet (java.util.HashSet)3 LoginHistory (org.mx.comps.rbac.dal.entity.LoginHistory)3 RoleManageService (org.mx.comps.rbac.service.RoleManageService)3 Accredit (org.mx.comps.rbac.dal.entity.Accredit)2 Privilege (org.mx.comps.rbac.dal.entity.Privilege)2