Search in sources :

Example 16 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class AccountManageResource method changePersonal.

@Path("accounts/{id}/personal/change")
@POST
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccountVO> changePersonal(@PathParam("id") String id, @QueryParam("userCode") String userCode, ChangePersonalVO vo) {
    sessionDataStore.setCurrentUserCode(userCode);
    if (vo == null) {
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM));
    }
    try {
        Account account = accountManageService.changePersonal(vo.getAccountPersonalInfo());
        AccountVO accountVO = AccountVO.transform(account, true);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(accountVO);
    } catch (UserInterfaceException ex) {
        return new DataVO<>(ex);
    }
}
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) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 17 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class UserManageResource method allocateAccount.

@Path("users/{userId}/allocate")
@POST
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccountVO> allocateAccount(@QueryParam("userCode") String userCode, @PathParam("userId") String userId, AccountInfoVO accountInfoVO) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        accountInfoVO.setOwnerId(userId);
        Account account = userManageService.allocateAccount(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("Allocate 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) AccountVO(org.mx.comps.rbac.rest.vo.AccountVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 18 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class TestAccount method testAccountRoles.

@Test
public void testAccountRoles() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    AccountManageService accountService = context.getBean(AccountManageService.class);
    assertNotNull(service);
    UserManageService userManageService = context.getBean(UserManageService.class);
    assertNotNull(userManageService);
    RoleManageService roleManageService = context.getBean(RoleManageService.class);
    assertNotNull(roleManageService);
    try {
        TestUser.testInsertUser(service, userManageService);
        TestUser.testEditUser(service, userManageService);
        assertEquals(3, service.count(User.class));
        TestRole.testInsertRole(service, roleManageService);
        TestRole.testEditRole(service, roleManageService);
        testInsertAccount(service, accountService);
        testEditAccount(service, accountService);
        assertEquals(3, service.count(Role.class));
        assertEquals(3, service.count(Account.class));
        Account account1 = service.getById(account1Id, Account.class);
        assertNotNull(account1);
        assertTrue(account1.getRoles().isEmpty());
        Role role1 = service.getById(TestRole.role1Id, Role.class);
        Role role2 = service.getById(TestRole.role2Id, Role.class);
        Role role3 = service.getById(TestRole.role3Id, Role.class);
        assertNotNull(role1);
        assertNotNull(role2);
        assertNotNull(role3);
        AccountManageService.AccountInfo accountInfo = AccountManageService.AccountInfo.valueOf(account1.getCode(), "", account1.getDesc(), account1.getId(), TestUser.johnId, Arrays.asList(role1.getId(), role2.getId(), role3.getId()), account1.isValid());
        accountService.saveAccount(accountInfo);
        assertEquals(3, service.count(Account.class));
        account1 = service.getById(account1Id, Account.class);
        assertNotNull(account1);
        assertEquals(3, account1.getRoles().size());
        assertEquals(new HashSet<>(Arrays.asList(role1, role2, role3)), account1.getRoles());
        accountInfo = AccountManageService.AccountInfo.valueOf(account1.getCode(), "", account1.getDesc(), account1.getId(), TestUser.johnId, Arrays.asList(role1.getId(), role3.getId()), account1.isValid());
        accountService.saveAccount(accountInfo);
        assertEquals(3, service.count(Account.class));
        account1 = service.getById(account1Id, Account.class);
        assertNotNull(account1);
        assertEquals(2, account1.getRoles().size());
        assertEquals(new HashSet<>(Arrays.asList(role1, role3)), account1.getRoles());
        accountInfo = AccountManageService.AccountInfo.valueOf(account1.getCode(), "", account1.getDesc(), account1.getId(), TestUser.johnId, Arrays.asList(), account1.isValid());
        accountService.saveAccount(accountInfo);
        account1 = service.getById(account1Id, Account.class);
        assertNotNull(account1);
        assertTrue(account1.getRoles().isEmpty());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) Account(org.mx.comps.rbac.dal.entity.Account) User(org.mx.comps.rbac.dal.entity.User) AccountManageService(org.mx.comps.rbac.service.AccountManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserManageService(org.mx.comps.rbac.service.UserManageService) RoleManageService(org.mx.comps.rbac.service.RoleManageService) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 19 with Account

use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.

the class TestAccount method testDeleteAccount.

private void testDeleteAccount(GeneralDictAccessor service) {
    List<Account> accounts = service.list(Account.class);
    int accountNum = accounts.size();
    for (Account account : accounts) {
        service.remove(account);
        assertEquals(--accountNum, service.count(Account.class, true));
        assertEquals(accounts.size(), service.count(Account.class, false));
    }
    accountNum = accounts.size();
    for (Account account : accounts) {
        service.remove(account, false);
        assertEquals(0, service.count(Account.class, true));
        assertEquals(--accountNum, service.count(Account.class, false));
    }
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account)

Example 20 with Account

use of org.mx.comps.rbac.dal.entity.Account 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)

Aggregations

Account (org.mx.comps.rbac.dal.entity.Account)26 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)14 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)12 User (org.mx.comps.rbac.dal.entity.User)10 Role (org.mx.comps.rbac.dal.entity.Role)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 AccountManageService (org.mx.comps.rbac.service.AccountManageService)8 Test (org.junit.Test)6 UserManageService (org.mx.comps.rbac.service.UserManageService)6 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)6 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)5 UserInterfaceException (org.mx.error.UserInterfaceException)5 DataVO (org.mx.service.rest.vo.DataVO)5 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)5 Date (java.util.Date)4 HashSet (java.util.HashSet)3 LoginHistory (org.mx.comps.rbac.dal.entity.LoginHistory)3 RoleManageService (org.mx.comps.rbac.service.RoleManageService)3 Accredit (org.mx.comps.rbac.dal.entity.Accredit)2 Privilege (org.mx.comps.rbac.dal.entity.Privilege)2