Search in sources :

Example 21 with Role

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

the class RoleManageServiceImpl method save.

/**
 * {@inheritDoc}
 *
 * @see RoleManageServiceCommonImpl#save(Role)
 */
@Override
public Role save(Role role) {
    Set<Privilege> oldPrivileges = new HashSet<>();
    Set<Account> oldAccounts = new HashSet<>();
    if (!StringUtils.isBlank(role.getId())) {
        Role checked = accessor.getById(role.getId(), Role.class);
        oldPrivileges.addAll(checked.getPrivileges());
        oldAccounts.addAll(checked.getAccounts());
    }
    accessor.save(role, false);
    Set<Privilege> privileges = role.getPrivileges();
    Set<Account> accounts = role.getAccounts();
    for (Privilege privilege : privileges) {
        if (oldPrivileges.contains(privilege)) {
            oldPrivileges.remove(privilege);
            continue;
        } else {
            privilege.getRoles().add(role);
            accessor.save(privilege, false);
        }
    }
    for (Privilege privilege : oldPrivileges) {
        privilege.getRoles().remove(role);
        accessor.save(privilege, false);
    }
    for (Account account : accounts) {
        if (oldAccounts.contains(account)) {
            oldAccounts.remove(account);
            continue;
        } else {
            account.getRoles().add(role);
            accessor.save(account, false);
        }
    }
    for (Account account : oldAccounts) {
        account.getRoles().remove(role);
        accessor.save(account, false);
    }
    return role;
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) Account(org.mx.comps.rbac.dal.entity.Account) Privilege(org.mx.comps.rbac.dal.entity.Privilege) HashSet(java.util.HashSet)

Example 22 with Role

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

the class AccreditManageServiceImpl method hasSameAccredit.

/**
 * {@inheritDoc}
 *
 * @see AccreditManageServiceCommonImpl#hasSameAccredit(AccreditInfo)
 */
@Override
protected boolean hasSameAccredit(AccreditInfo accreditInfo) {
    List<GeneralAccessor.ConditionTuple> conditions = new ArrayList<>();
    conditions.add(new GeneralAccessor.ConditionTuple("src.id", accreditInfo.getSrcAccountId()));
    conditions.add(new GeneralAccessor.ConditionTuple("tar.id", accreditInfo.getTarAccountId()));
    conditions.add(new GeneralAccessor.ConditionTuple("valid", true));
    List<Accredit> list = accessor.find(conditions, Accredit.class);
    List<Accredit> accredits = new ArrayList<>();
    if (list != null && !list.isEmpty()) {
        list.forEach(accredit -> {
            if (!accredit.isClosed()) {
                accredits.add(accredit);
            }
        });
    }
    if (accredits.isEmpty()) {
        return false;
    }
    for (Accredit accredit : accredits) {
        if (!accredit.isClosed()) {
            for (String roleId : accreditInfo.getRoleIds()) {
                boolean found = false;
                for (Role role : accredit.getRoles()) {
                    if (roleId.equals(role.getId())) {
                        found = true;
                    }
                }
                if (!found) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) Accredit(org.mx.comps.rbac.dal.entity.Accredit) ArrayList(java.util.ArrayList) GeneralAccessor(org.mx.dal.service.GeneralAccessor)

Aggregations

Role (org.mx.comps.rbac.dal.entity.Role)22 Account (org.mx.comps.rbac.dal.entity.Account)9 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)9 RoleManageService (org.mx.comps.rbac.service.RoleManageService)7 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)6 Test (org.junit.Test)5 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HashSet (java.util.HashSet)4 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)4 Accredit (org.mx.comps.rbac.dal.entity.Accredit)4 Privilege (org.mx.comps.rbac.dal.entity.Privilege)4 User (org.mx.comps.rbac.dal.entity.User)4 RoleVO (org.mx.comps.rbac.rest.vo.RoleVO)4 UserInterfaceException (org.mx.error.UserInterfaceException)4 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)4 AccountManageService (org.mx.comps.rbac.service.AccountManageService)3 UserManageService (org.mx.comps.rbac.service.UserManageService)3 DataVO (org.mx.service.rest.vo.DataVO)3 ArrayList (java.util.ArrayList)2