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));
}
}
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));
}
}
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));
}
}
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);
}
}
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;
}
Aggregations