Search in sources :

Example 11 with User

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));
    }
}
Also used : User(org.mx.comps.rbac.dal.entity.User) UserVO(org.mx.comps.rbac.rest.vo.UserVO) 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 12 with User

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));
    }
}
Also used : User(org.mx.comps.rbac.dal.entity.User) UserVO(org.mx.comps.rbac.rest.vo.UserVO) 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 13 with User

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));
    }
}
Also used : User(org.mx.comps.rbac.dal.entity.User) UserVO(org.mx.comps.rbac.rest.vo.UserVO) 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 14 with User

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());
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) User(org.mx.comps.rbac.dal.entity.User) AccountManageService(org.mx.comps.rbac.service.AccountManageService)

Example 15 with User

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());
    }
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) User(org.mx.comps.rbac.dal.entity.User) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) AccountManageService(org.mx.comps.rbac.service.AccountManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserManageService(org.mx.comps.rbac.service.UserManageService) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

User (org.mx.comps.rbac.dal.entity.User)19 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)9 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)6 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)5 Account (org.mx.comps.rbac.dal.entity.Account)5 UserVO (org.mx.comps.rbac.rest.vo.UserVO)5 UserManageService (org.mx.comps.rbac.service.UserManageService)5 UserInterfaceException (org.mx.error.UserInterfaceException)5 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)5 Department (org.mx.comps.rbac.dal.entity.Department)4 DataVO (org.mx.service.rest.vo.DataVO)4 Test (org.junit.Test)3 AccountManageService (org.mx.comps.rbac.service.AccountManageService)3 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)3 ParseException (java.text.ParseException)2 DepartmentManageService (org.mx.comps.rbac.service.DepartmentManageService)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1