use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class UserManageResource method deleteUser.
@Path("users/{userId}")
@DELETE
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<UserVO> deleteUser(@QueryParam("userCode") String userCode, @PathParam("userId") String userId) {
sessionDataStore.setCurrentUserCode(userCode);
try {
User user = accessor.remove(userId, User.class);
UserVO userVO = UserVO.transform(user);
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(userVO);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Delete user fail.", ex);
}
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class UserManageResource method saveUser.
@Path("users/{userId}")
@PUT
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<UserVO> saveUser(@QueryParam("userCode") String userCode, @PathParam("userId") String userId, UserInfoVO userInfoVO) {
sessionDataStore.setCurrentUserCode(userCode);
try {
userInfoVO.setId(userId);
User user = userManageService.saveUser(userInfoVO.getUserInfo());
UserVO userVO = UserVO.transform(user);
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(userVO);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Save user fail.", ex);
}
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class UserManageResource method getUser.
@Path("users/{id}")
@GET
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<UserVO> getUser(@PathParam("id") String id) {
try {
User user = accessor.getById(id, User.class);
UserVO userVO = UserVO.transform(user);
return new DataVO<>(userVO);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Get user fail.", ex);
}
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class TestAccount method testInsertAccount.
public static void testInsertAccount(GeneralDictAccessor service, AccountManageService accountService) throws NoSuchAlgorithmException {
User john = service.getById(TestUser.johnId, User.class);
assertNotNull(john);
AccountManageService.AccountInfo accountInfo = AccountManageService.AccountInfo.valueOf("account1", "password", "description account.", "", TestUser.johnId, Arrays.asList(), true);
Account account1 = accountService.saveAccount(accountInfo);
assertEquals(1, service.count(Account.class));
assertNotNull(account1);
assertNotNull(account1.getId());
account1Id = account1.getId();
assertEquals("description account.", account1.getDesc());
assertEquals("account1", account1.getCode());
assertEquals(john.getFullName(), account1.getName());
assertEquals(DigestUtils.md5("password"), account1.getPassword());
assertEquals("admin", account1.getOperator());
assertTrue(account1.isValid());
assertTrue(account1.getCreatedTime() > 0);
assertTrue(account1.getUpdatedTime() > 0);
account1 = service.getById(account1Id, Account.class);
assertNotNull(account1);
assertNotNull(account1.getId());
assertEquals("description account.", account1.getDesc());
assertEquals("account1", account1.getCode());
assertEquals(john.getFullName(), account1.getName());
assertEquals(DigestUtils.md5("password"), account1.getPassword());
assertEquals("admin", account1.getOperator());
account1 = service.getByCode(account1.getCode(), Account.class);
assertNotNull(account1);
assertNotNull(account1.getId());
assertEquals("description account.", account1.getDesc());
assertEquals("account1", account1.getCode());
assertEquals(john.getFullName(), account1.getName());
assertEquals(DigestUtils.md5("password"), account1.getPassword());
assertEquals("admin", account1.getOperator());
assertEquals(john, account1.getOwner());
assertTrue(account1.isValid());
accountInfo = AccountManageService.AccountInfo.valueOf("account2", "", "description account.", "", TestUser.johnId, Arrays.asList(), true);
Account account2 = accountService.saveAccount(accountInfo);
assertEquals(2, service.count(Account.class));
assertNotNull(account2);
assertNotNull(account2.getId());
account2Id = account2.getId();
assertEquals("account2", account2.getCode());
assertEquals(DigestUtils.md5("ds110119"), account2.getPassword());
assertEquals(john.getFullName(), account2.getName());
assertEquals(john, account2.getOwner());
assertTrue(account2.isValid());
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class TestUser method testAllocateAccount.
@Test
public void testAllocateAccount() {
GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
assertNotNull(service);
UserManageService userService = context.getBean(UserManageService.class);
assertNotNull(service);
AccountManageService accountManageService = context.getBean(AccountManageService.class);
assertNotNull(accountManageService);
try {
testInsertUser(service, userService);
testEditUser(service, userService);
assertEquals(3, service.count(User.class));
User john = service.getById(joshId, User.class);
assertNotNull(john);
assertEquals(0, service.count(Account.class));
// 用户不存在
AccountManageService.AccountInfo accountInfo = AccountManageService.AccountInfo.valueOf("john---", "password", "desc", "", "asdfasd", Arrays.asList(), true);
try {
userService.allocateAccount(accountInfo);
fail("here need a exception");
} catch (UserInterfaceRbacErrorException ex) {
assertEquals(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND.getErrorCode(), ex.getErrorCode());
}
// 正常创建
accountInfo = AccountManageService.AccountInfo.valueOf("John.Peng", "edmund!@#123", "desc", "", john.getId(), Arrays.asList(), true);
Account account = userService.allocateAccount(accountInfo);
assertNotNull(account);
assertEquals(3, service.count(User.class));
assertEquals(1, service.count(Account.class));
account = service.getByCode("John.Peng", Account.class);
assertNotNull(account);
assertNotNull(account.getOwner());
assertEquals(john, account.getOwner());
assertEquals(DigestUtils.md5("edmund!@#123"), account.getPassword());
assertEquals(john.getFullName(), account.getName());
assertEquals("desc", account.getDesc());
assertEquals(0, account.getRoles().size());
// 账户已存在
try {
userService.allocateAccount(accountInfo);
fail("here need a exception");
} catch (UserInterfaceRbacErrorException ex) {
assertEquals(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_HAS_EXIST.getErrorCode(), ex.getErrorCode());
}
} catch (Exception ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
}
Aggregations