Search in sources :

Example 6 with Privilege

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

the class PrivilegeManageResource method getPrivilege.

@Path("privileges/{id}")
@GET
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<PrivilegeVO> getPrivilege(@PathParam("id") String id) {
    try {
        Privilege privilege = accessor.getById(id, Privilege.class);
        PrivilegeVO vo = PrivilegeVO.transform(privilege, true);
        return new DataVO<>(vo);
    } catch (UserInterfaceException ex) {
        return new DataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("Get privilege fail.", ex);
        }
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : DataVO(org.mx.service.rest.vo.DataVO) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) PrivilegeVO(org.mx.comps.rbac.rest.vo.PrivilegeVO) Privilege(org.mx.comps.rbac.dal.entity.Privilege) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 7 with Privilege

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

the class TestPrivilege method testDeletePrivilege.

private void testDeletePrivilege(GeneralDictAccessor service) {
    List<Privilege> ps = service.list(Privilege.class);
    int pnum = ps.size();
    for (Privilege p : ps) {
        service.remove(p);
        assertEquals(--pnum, service.count(Privilege.class));
        assertEquals(ps.size(), service.count(Privilege.class, false));
    }
    pnum = ps.size();
    for (Privilege p : ps) {
        service.remove(p, false);
        assertEquals(--pnum, service.count(Privilege.class, false));
    }
}
Also used : Privilege(org.mx.comps.rbac.dal.entity.Privilege)

Example 8 with Privilege

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

the class TestPrivilege method testInsertPrivilege.

public static void testInsertPrivilege(GeneralDictAccessor service) {
    Privilege p1 = EntityFactory.createEntity(Privilege.class);
    p1.setCode("privilege1");
    p1.setName("privilege1");
    p1.setDesc("desc");
    p1 = service.save(p1);
    assertEquals(1, service.count(Privilege.class));
    assertNotNull(p1);
    assertNotNull(p1.getId());
    p1Id = p1.getId();
    p1 = service.getById(p1Id, Privilege.class);
    assertNotNull(p1);
    assertEquals("privilege1", p1.getCode());
    assertEquals("privilege1", p1.getName());
    assertEquals("desc", p1.getDesc());
    assertTrue(p1.isValid());
    Privilege p2 = EntityFactory.createEntity(Privilege.class);
    p2.setCode("privilege2");
    p2.setName("privilege2");
    p2.setDesc("desc");
    service.save(p2);
    assertEquals(2, service.count(Privilege.class));
    p2 = service.getById(p2.getId(), Privilege.class);
    assertNotNull(p2);
    p2Id = p2.getId();
    assertEquals("privilege2", p2.getCode());
    assertEquals("privilege2", p2.getName());
    assertEquals("desc", p2.getDesc());
    assertTrue(p2.isValid());
}
Also used : Privilege(org.mx.comps.rbac.dal.entity.Privilege)

Example 9 with Privilege

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

the class TestPrivilege method testEditPrivilege.

public static void testEditPrivilege(GeneralDictAccessor service) {
    Privilege p3 = EntityFactory.createEntity(Privilege.class);
    p3.setCode("privilege3");
    p3.setName("privilege3");
    service.save(p3);
    assertEquals(3, service.count(Privilege.class));
    p3 = service.getById(p3.getId(), Privilege.class);
    assertNotNull(p3);
    p3Id = p3.getId();
    assertEquals("privilege3", p3.getCode());
    assertEquals("privilege3", p3.getName());
    p3.setName("new name");
    p3.setValid(false);
    service.save(p3);
    assertEquals(2, service.count(Privilege.class));
    assertEquals(3, service.count(Privilege.class, false));
    p3.setName("privilege3");
    p3.setValid(true);
    service.save(p3);
    assertEquals(3, service.count(Privilege.class));
}
Also used : Privilege(org.mx.comps.rbac.dal.entity.Privilege)

Example 10 with Privilege

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

the class RoleManageServiceCommonImpl method saveRole.

/**
 * {@inheritDoc}
 *
 * @see RoleManageService#saveRole(RoleInfo)
 */
@Override
public Role saveRole(RoleInfo roleInfo) {
    if (roleInfo == null) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    String id = roleInfo.getRoleId();
    Role role;
    if (!StringUtils.isBlank(id)) {
        role = accessor.getById(id, Role.class);
        if (role == null) {
            throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
        }
    } else {
        role = EntityFactory.createEntity(Role.class);
    }
    role.setCode(roleInfo.getCode());
    role.setName(roleInfo.getName());
    role.setDesc(roleInfo.getDesc());
    if (role.getAccounts() != null && !role.getAccounts().isEmpty()) {
        role.getAccounts().clear();
    }
    if (roleInfo.getAccountIds() != null && !roleInfo.getAccountIds().isEmpty()) {
        for (String accountId : roleInfo.getAccountIds()) {
            Account account = accessor.getById(accountId, Account.class);
            if (account == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
            }
            role.getAccounts().add(account);
        }
    }
    if (role.getPrivileges() != null && !role.getPrivileges().isEmpty()) {
        role.getPrivileges().clear();
        for (String privilegeId : roleInfo.getPrivilegeIds()) {
            Privilege privilege = accessor.getById(privilegeId, Privilege.class);
            if (privilege == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.PRIVILEGE_NOT_FOUND);
            }
            role.getPrivileges().add(privilege);
        }
    }
    role.setValid(roleInfo.isValid());
    role = this.save(role);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("保存角色[code=%s, name=%s]信息成功。", roleInfo.getCode(), roleInfo.getName()));
    }
    return role;
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) Account(org.mx.comps.rbac.dal.entity.Account) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) Privilege(org.mx.comps.rbac.dal.entity.Privilege)

Aggregations

Privilege (org.mx.comps.rbac.dal.entity.Privilege)11 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)5 Role (org.mx.comps.rbac.dal.entity.Role)4 PrivilegeVO (org.mx.comps.rbac.rest.vo.PrivilegeVO)4 UserInterfaceException (org.mx.error.UserInterfaceException)4 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)4 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)3 DataVO (org.mx.service.rest.vo.DataVO)3 Test (org.junit.Test)2 Account (org.mx.comps.rbac.dal.entity.Account)2 RoleManageService (org.mx.comps.rbac.service.RoleManageService)2 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)2 HashSet (java.util.HashSet)1 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)1 Pagination (org.mx.dal.Pagination)1