Search in sources :

Example 1 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class VosManagerEntry method getBanById.

@Override
public BanOnVo getBanById(PerunSession sess, int banId) throws BanNotExistsException, PrivilegeException {
    Utils.checkPerunSession(sess);
    BanOnVo ban = vosManagerBl.getBanById(sess, banId);
    // Authorization
    if (!AuthzResolver.authorizedInternal(sess, "vo-getBanById_int_policy", ban)) {
        throw new PrivilegeException("getBanById");
    }
    return ban;
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Example 2 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class VosManagerEntry method getBansForVo.

@Override
public List<BanOnVo> getBansForVo(PerunSession sess, int voId) throws PrivilegeException, VoNotExistsException {
    Utils.checkPerunSession(sess);
    Vo vo = vosManagerBl.getVoById(sess, voId);
    // Authorization
    if (!AuthzResolver.authorizedInternal(sess, "getBansForVo_int_policy", vo)) {
        throw new PrivilegeException("getBansForVo");
    }
    return vosManagerBl.getBansForVo(sess, voId);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) Vo(cz.metacentrum.perun.core.api.Vo)

Example 3 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class VosManagerEntry method removeBan.

@Override
public void removeBan(PerunSession sess, int banId) throws PrivilegeException, BanNotExistsException {
    Utils.checkPerunSession(sess);
    BanOnVo banOnVo = perunBl.getVosManagerBl().getBanById(sess, banId);
    // Authorization
    if (!AuthzResolver.authorizedInternal(sess, "vo-removeBan_int_policy", banOnVo)) {
        throw new PrivilegeException("removeBan");
    }
    vosManagerBl.removeBan(sess, banId);
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Example 4 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class MembersManagerBlImpl method moveMembersBans.

/**
 * Moves bans on resources and ban on VO from source member to target member.
 *
 * @param sess
 * @param sourceMember member to move bans from
 * @param targetMember member to move bans to
 */
private void moveMembersBans(PerunSession sess, Member sourceMember, Member targetMember) {
    // move members bans on resources
    List<BanOnResource> bansOnResources = getPerunBl().getResourcesManagerBl().getBansForMember(sess, sourceMember.getId());
    for (BanOnResource banOnResource : bansOnResources) {
        try {
            banOnResource.setMemberId(targetMember.getId());
            getPerunBl().getResourcesManagerBl().setBan(sess, banOnResource);
        } catch (BanAlreadyExistsException e) {
            log.warn("Moving ban on resource {} from source member {} to target member {}, but the target member" + " already has ban on the resource.", banOnResource, sourceMember, targetMember);
        }
    }
    // move members ban on VO
    Optional<BanOnVo> banOnVo = getPerunBl().getVosManagerBl().getBanForMember(sess, sourceMember.getId());
    if (banOnVo.isPresent()) {
        banOnVo.get().setMemberId(targetMember.getId());
        try {
            getPerunBl().getVosManagerBl().setBan(sess, banOnVo.get());
        } catch (MemberNotExistsException e) {
            throw new InternalErrorException(e);
        }
    }
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) BanAlreadyExistsException(cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource)

Example 5 with BanOnVo

use of cz.metacentrum.perun.core.api.BanOnVo in project perun by CESNET.

the class urn_perun_member_attribute_def_virt_isSuspended method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Member member, AttributeDefinition attributeDefinition) {
    Attribute attribute = new Attribute(attributeDefinition);
    Optional<BanOnVo> ban = sess.getPerunBl().getVosManagerBl().getBanForMember(sess, member.getId());
    if (!ban.isPresent()) {
        attribute.setValue(false);
    } else {
        Date startOfToday = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
        attribute.setValue(ban.get().getValidityTo().after(startOfToday));
    }
    return attribute;
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) Attribute(cz.metacentrum.perun.core.api.Attribute) Date(java.util.Date) LocalDate(java.time.LocalDate)

Aggregations

BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)22 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)13 Test (org.junit.Test)13 Member (cz.metacentrum.perun.core.api.Member)9 Vo (cz.metacentrum.perun.core.api.Vo)8 Date (java.util.Date)8 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)3 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)3 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)2 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 LocalDate (java.time.LocalDate)2 MemberUnsuspended (cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberUnsuspended)1 Attribute (cz.metacentrum.perun.core.api.Attribute)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Resource (cz.metacentrum.perun.core.api.Resource)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 User (cz.metacentrum.perun.core.api.User)1 BanAlreadyExistsException (cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1