use of org.mx.comps.jwt.AuthenticateAround 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));
}
}
use of org.mx.comps.jwt.AuthenticateAround 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.jwt.AuthenticateAround 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));
}
}
use of org.mx.comps.jwt.AuthenticateAround 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.jwt.AuthenticateAround 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));
}
}
Aggregations