Search in sources :

Example 1 with UserInterfaceSystemErrorException

use of org.mx.error.UserInterfaceSystemErrorException in project main by JohnPeng739.

the class FfeeAccountManageServiceImpl method regist.

/**
 * 使用用户名、密码方式注册账户。
 *
 * @see FfeeAccountManageService#regist(String, String, String)
 */
@Override
@Transactional()
public FfeeAccount regist(String code, String name, String password) {
    if (StringUtils.isBlank(code) || StringUtils.isBlank(name) || StringUtils.isBlank(password)) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    Account account = accessor.getByCode(code, Account.class);
    if (account != null) {
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_HAS_EXIST);
    }
    Role role = accessor.getByCode("user", Role.class);
    if (role == null) {
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
    }
    account = EntityFactory.createEntity(Account.class);
    account.setCode(code);
    account.setName(name);
    try {
        account.setPassword(DigestUtils.md5(password));
    } catch (NoSuchAlgorithmException ex) {
        if (logger.isErrorEnabled()) {
            logger.error("Digest the password fail.", ex);
        }
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_DIGEST_PASSWORD_FAIL);
    }
    account = accessor.save(account, false);
    FfeeAccount ffeeAccount = EntityFactory.createEntity(FfeeAccount.class);
    ffeeAccount.setAccount(account);
    ffeeAccount.setSourceType(FfeeAccount.AccountSourceType.NORMAL);
    ffeeAccount = accessor.save(ffeeAccount, false);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("常规账户[%s]注册成功。", name));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Create a normal registry FFEE account[%s - %s] successfully.", code, name));
    }
    return ffeeAccount;
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) FfeeAccount(org.mx.tools.ffee.dal.entity.FfeeAccount) Account(org.mx.comps.rbac.dal.entity.Account) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) FfeeAccount(org.mx.tools.ffee.dal.entity.FfeeAccount) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UserInterfaceSystemErrorException

use of org.mx.error.UserInterfaceSystemErrorException in project main by JohnPeng739.

the class AccountManageResource method loginHistories.

@Path("loginHistories")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<LoginHistoryVO>> loginHistories(Pagination pagination) {
    if (pagination == null) {
        pagination = new Pagination();
    }
    try {
        List<LoginHistory> histories = accessor.list(pagination, LoginHistory.class);
        List<LoginHistoryVO> vos = LoginHistoryVO.transform(histories);
        return new PaginationDataVO(pagination, vos);
    } catch (UserInterfaceException ex) {
        return new PaginationDataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("List login histories fail.", ex);
        }
        return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Pagination(org.mx.dal.Pagination) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) LoginHistory(org.mx.comps.rbac.dal.entity.LoginHistory) 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 3 with UserInterfaceSystemErrorException

use of org.mx.error.UserInterfaceSystemErrorException 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 4 with UserInterfaceSystemErrorException

use of org.mx.error.UserInterfaceSystemErrorException in project main by JohnPeng739.

the class AccountManageResource method logout.

@Path("logout/{id}")
@GET
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<LoginHistoryVO> logout(@PathParam("id") String id, @QueryParam("userCode") String userCode, @Context Request request) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        LoginHistory loginHistory = accountManageService.logout(id);
        LoginHistoryVO loginHistoryVO = LoginHistoryVO.transform(loginHistory);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(loginHistoryVO);
    } catch (UserInterfaceException ex) {
        return new DataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error(String.format("User[%s] logout fail.", userCode), ex);
        }
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : LoginHistory(org.mx.comps.rbac.dal.entity.LoginHistory) 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 5 with UserInterfaceSystemErrorException

use of org.mx.error.UserInterfaceSystemErrorException 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)

Aggregations

UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)40 UserInterfaceException (org.mx.error.UserInterfaceException)30 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)30 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)27 DataVO (org.mx.service.rest.vo.DataVO)23 Account (org.mx.comps.rbac.dal.entity.Account)12 User (org.mx.comps.rbac.dal.entity.User)10 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)10 Role (org.mx.comps.rbac.dal.entity.Role)9 Accredit (org.mx.comps.rbac.dal.entity.Accredit)7 Pagination (org.mx.dal.Pagination)7 Department (org.mx.comps.rbac.dal.entity.Department)6 Privilege (org.mx.comps.rbac.dal.entity.Privilege)5 UserVO (org.mx.comps.rbac.rest.vo.UserVO)5 Date (java.util.Date)4 LoginHistory (org.mx.comps.rbac.dal.entity.LoginHistory)4 AccreditVO (org.mx.comps.rbac.rest.vo.AccreditVO)4 DepartmentVO (org.mx.comps.rbac.rest.vo.DepartmentVO)4 PrivilegeVO (org.mx.comps.rbac.rest.vo.PrivilegeVO)4 RoleVO (org.mx.comps.rbac.rest.vo.RoleVO)4