use of cz.metacentrum.perun.core.api.BanOnFacility in project perun by CESNET.
the class FacilitiesManagerEntry method getBansForUser.
public List<BanOnFacility> getBansForUser(PerunSession sess, int userId) throws InternalErrorException, UserNotExistsException {
Utils.checkPerunSession(sess);
User user = getPerunBl().getUsersManagerBl().getUserById(sess, userId);
List<BanOnFacility> usersBans = getFacilitiesManagerBl().getBansForUser(sess, userId);
//filtering
Iterator<BanOnFacility> iterator = usersBans.iterator();
while (iterator.hasNext()) {
BanOnFacility banForFiltering = iterator.next();
Facility facility = new Facility();
facility.setId(banForFiltering.getFacilityId());
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility))
iterator.remove();
}
return usersBans;
}
use of cz.metacentrum.perun.core.api.BanOnFacility in project perun by CESNET.
the class urn_perun_member_resource_attribute_def_virt_isBannedTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_member_resource_attribute_def_virt_isBanned();
session = mock(PerunSessionImpl.class, RETURNS_DEEP_STUBS);
facility = new Facility(1, "testFacility");
resource = new Resource(1, "testResource", "desc", 1, 1);
vo = new Vo(1, "testVo", "desc");
user = new User(1, "name", "surname", "middlename", "title", "title");
member = new Member(1, 1, 1, Status.VALID);
banOnResource = new BanOnResource(1, new Date(), "test", 1, 1);
banOnFacility = new BanOnFacility(1, new Date(), "test", 1, 1);
isBanned = new Attribute(classInstance.getAttributeDefinition());
isBanned.setValue(true);
message1 = "Ban " + banOnResource.serializeToString() + " was set for memberId 1 on resourceId 1";
message2 = "Ban " + banOnResource.serializeToString() + " was updated for memberId 1 on resourceId 1";
message3 = "Ban " + banOnResource.serializeToString() + " was removed for memberId 1 on resourceId 1";
message4 = "Ban " + banOnFacility.serializeToString() + " was set for userId 1 on facilityId 1";
message5 = "Ban " + banOnFacility.serializeToString() + " was updated for userId 1 on facilityId 1";
message6 = "Ban " + banOnFacility.serializeToString() + " was removed for userId 1 on facilityId 1";
wrongMessage = "Ban " + banOnFacility.serializeToString() + " was destroyed for userId 1 on facilityId 1";
}
use of cz.metacentrum.perun.core.api.BanOnFacility in project perun by CESNET.
the class FacilitiesManagerEntry method setBan.
@Override
public BanOnFacility setBan(PerunSession sess, BanOnFacility banOnFacility) throws InternalErrorException, PrivilegeException, BanAlreadyExistsException, FacilityNotExistsException, UserNotExistsException {
Utils.checkPerunSession(sess);
Utils.notNull(banOnFacility, "banOnFacility");
User user = getPerunBl().getUsersManagerBl().getUserById(sess, banOnFacility.getUserId());
Facility facility = this.getFacilitiesManagerBl().getFacilityById(sess, banOnFacility.getFacilityId());
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(sess, "setBan");
}
return getFacilitiesManagerBl().setBan(sess, banOnFacility);
}
use of cz.metacentrum.perun.core.api.BanOnFacility in project perun by CESNET.
the class FacilitiesManagerEntry method getBanById.
@Override
public BanOnFacility getBanById(PerunSession sess, int banId) throws InternalErrorException, BanNotExistsException, PrivilegeException {
Utils.checkPerunSession(sess);
BanOnFacility ban = getFacilitiesManagerBl().getBanById(sess, banId);
Facility facility = new Facility();
facility.setId(ban.getId());
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(sess, "getBanById");
}
return ban;
}
use of cz.metacentrum.perun.core.api.BanOnFacility in project perun by CESNET.
the class FacilitiesManagerEntry method getBansForFacility.
public List<BanOnFacility> getBansForFacility(PerunSession sess, int facilityId) throws InternalErrorException, PrivilegeException, FacilityNotExistsException {
Utils.checkPerunSession(sess);
Facility facility = this.getFacilitiesManagerBl().getFacilityById(sess, facilityId);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(sess, "getBansForFacility");
}
return getFacilitiesManagerBl().getBansForFacility(sess, facilityId);
}
Aggregations