use of cz.metacentrum.perun.core.api.Facility 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.Facility in project perun by CESNET.
the class FacilitiesManagerEntry method getFacilityByName.
public Facility getFacilityByName(PerunSession sess, String name) throws InternalErrorException, FacilityNotExistsException, PrivilegeException {
Utils.checkPerunSession(sess);
Utils.notNull(name, "name");
Facility facility = getFacilitiesManagerBl().getFacilityByName(sess, name);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility) && !AuthzResolver.isAuthorized(sess, Role.ENGINE) && !AuthzResolver.isAuthorized(sess, Role.RPC)) {
throw new PrivilegeException(sess, "getFacilityByName");
}
return facility;
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class urn_perun_member_resource_attribute_def_virt_isBanned method resolveVirtualAttributeValueChange.
@Override
public List<String> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, String message) throws InternalErrorException, WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeAssignmentException {
List<String> resolvingMessages = new ArrayList<>();
if (message == null)
return resolvingMessages;
Matcher banModificationMatcher = banModification.matcher(message);
List<Pair<Resource, Member>> listOfAffectedObjects = new ArrayList<>();
String operationType = "";
if (banModificationMatcher.find()) {
try {
String banType = banModificationMatcher.group(1);
operationType = banModificationMatcher.group(2);
int firstHolderId = Integer.valueOf(banModificationMatcher.group(3));
int secondHolderId = Integer.valueOf(banModificationMatcher.group(4));
if (operationType.equals(OPERATION_UPDATED)) {
operationType = OPERATION_SET;
} else if (!operationType.equals(OPERATION_SET) && !operationType.equals(OPERATION_REMOVED)) {
throw new InternalErrorException("Type of operation '" + operationType + "' is unknown by module.");
}
if (banType.equals(BanOnResource.class.getSimpleName())) {
Member member = perunSession.getPerunBl().getMembersManagerBl().getMemberById(perunSession, firstHolderId);
Resource resource = perunSession.getPerunBl().getResourcesManagerBl().getResourceById(perunSession, secondHolderId);
listOfAffectedObjects.add(new Pair(resource, member));
} else if (banType.equals(BanOnFacility.class.getSimpleName())) {
User user = perunSession.getPerunBl().getUsersManagerBl().getUserById(perunSession, firstHolderId);
Facility facility = perunSession.getPerunBl().getFacilitiesManagerBl().getFacilityById(perunSession, secondHolderId);
listOfAffectedObjects = getAffectedMemberResourceObjects(perunSession, user, facility);
} else {
throw new InternalErrorException("Type of ban '" + banType + "' is unkown by module.");
}
} catch (Exception e) {
log.error("Can't resolve virtual attribute value change for " + this.getClass().getSimpleName() + " module because of exception.", e);
//return empty array, do not throw exception because it can create problems
return new ArrayList<>();
}
}
for (Pair<Resource, Member> affectedObjects : listOfAffectedObjects) {
try {
Attribute attrVirtMemberResourceIsBanned = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, affectedObjects.getLeft(), affectedObjects.getRight(), AttributesManager.NS_MEMBER_RESOURCE_ATTR_VIRT + ":isBanned");
resolvingMessages.add(attrVirtMemberResourceIsBanned.serializeToString() + " " + operationType + " for " + affectedObjects.getLeft().serializeToString() + " and " + affectedObjects.getRight().serializeToString());
} catch (AttributeNotExistsException ex) {
//This means that attribute isBanned not exists at all so we can skip this process
log.info("Virtual attribute {} not exists.", this.getClass().getSimpleName());
break;
}
}
return resolvingMessages;
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class urn_perun_resource_attribute_def_def_fairshareGroupName method checkAttributeValue.
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
//Null is ok, it means this resource is not fairshare group
if (attribute.getValue() == null) {
return;
}
String gName = (String) attribute.getValue();
//Test if gName matchers regex
Matcher matcher = pattern.matcher(gName);
if (!matcher.matches()) {
throw new WrongAttributeValueException(attribute, resource, "Wrong format of group fairshare name. Max length is 12, only letters are allowed.");
}
//On facility must be fairshare group name unique (between all resources of this facility)
Facility facility = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource);
List<Resource> facilityResources = perunSession.getPerunBl().getFacilitiesManagerBl().getAssignedResources(perunSession, facility);
facilityResources.remove(resource);
List<String> resourcesFairshareGroupNames = new ArrayList<>();
for (Resource res : facilityResources) {
try {
Attribute resFairshareName = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, res, attribute.getName());
if (resFairshareName.getValue() == null)
continue;
resourcesFairshareGroupNames.add((String) resFairshareName.getValue());
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
if (resourcesFairshareGroupNames.contains(gName))
throw new WrongAttributeValueException(attribute, resource, "This name is already taken (not unique). Choose another one.");
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method setUpWorld.
/**
* How the world look: "->" means "have a binding, connection with"
*
* vo1 -> member1OfUser1, member2OfUser2, member1OfUser3 && group1InVo1, group2InVo1, membersGroupOfVo1 && resource1InVo1, resource2InVo1
* vo2 -> member2OfUser1, member1OfUser2, member2OfUser3 && group1InVo2, group2InVo2, membersGroupOfVo2 && resource1InVo2, resource2InVo2
*
* user1 -> member1OfUser1, member2OfUser1 && userExtSource1
* user2 -> member1OfUser2, member2OfUser2 && userExtSource2
* user3 -> member1OfUser3, member2OfUser3 && userExtSource3
*
* member1OfUser1 IS allowed
* member2OfUser1 IS disallowed
* member1OfUser2 IS allowed
* member2OfUser2 IS disallowed
* member1OfUser3 IS allowed
* member2OfUser3 IS allowed
*
* group1InVo1 -> member1OfUser1, member2OfUser2, member1OfUser3
* group2InVo1 -> member1OfUser1, member2OfUser2
* group1InVo2 -> member2OfUser1, member1OfUser2
* group2InVo2 -> member2OfUser1, member1OfUser2, member2OfUser3
*
* facility1 -> host1OnFacility1, host2OnFacility1
* facility2 -> host1OnFacility2, host2OnFacility2
* facility3 -> host1OnFacility3, host2OnFacility3
*
* resource1InVo1 -> facility1 && group1InVo1, group2InVo1
* resource2InVo1 -> facility2 && group2InVo1
* resource1InVo2 -> facility2 && group1InVo2, group2InVo2
* resource2InVo2 -> facility3 && group2InVo2
*/
public void setUpWorld() throws Exception {
//Create VO
vo1 = perun.getVosManagerBl().createVo(sess, new Vo(0, "vo1Test", "v1T"));
vo2 = perun.getVosManagerBl().createVo(sess, new Vo(0, "vo2Test", "v2T"));
//Create Groups(members groups in vos), Members and Users from Candidates
Candidate can1 = new Candidate();
can1.setFirstName("user1");
can1.setId(0);
can1.setMiddleName("");
can1.setLastName("Test");
can1.setTitleBefore("");
can1.setTitleAfter("");
UserExtSource userExtSource1 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user1TestLogin");
UserExtSource userExtSource2 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user2TestLogin");
UserExtSource userExtSource3 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user3TestLogin");
can1.setUserExtSource(userExtSource1);
can1.setAttributes(new HashMap<String, String>());
member1OfUser1 = perun.getMembersManagerBl().createMemberSync(sess, vo1, can1);
user1 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser1);
member2OfUser1 = perun.getMembersManagerBl().createMember(sess, vo2, user1);
can1.setFirstName("user2");
can1.setUserExtSource(userExtSource2);
member1OfUser2 = perun.getMembersManagerBl().createMemberSync(sess, vo2, can1);
user2 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser2);
member2OfUser2 = perun.getMembersManagerBl().createMember(sess, vo1, user2);
can1.setFirstName("user3");
can1.setUserExtSource(userExtSource3);
member1OfUser3 = perun.getMembersManagerBl().createMemberSync(sess, vo1, can1);
user3 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser3);
member2OfUser3 = perun.getMembersManagerBl().createMember(sess, vo2, user3);
//Validate members
member1OfUser1 = perun.getMembersManagerBl().validateMember(sess, member1OfUser1);
member2OfUser1 = perun.getMembersManagerBl().validateMember(sess, member2OfUser1);
member1OfUser2 = perun.getMembersManagerBl().validateMember(sess, member1OfUser2);
member2OfUser2 = perun.getMembersManagerBl().validateMember(sess, member2OfUser2);
member1OfUser3 = perun.getMembersManagerBl().validateMember(sess, member1OfUser3);
member2OfUser3 = perun.getMembersManagerBl().validateMember(sess, member2OfUser3);
//Invalidate some members to Disallowed them
perun.getMembersManagerBl().invalidateMember(sess, member2OfUser1);
perun.getMembersManagerBl().invalidateMember(sess, member2OfUser2);
//Create groups and add members to them
membersGroupOfVo1 = perun.getGroupsManagerBl().getGroupByName(sess, vo1, VosManager.MEMBERS_GROUP);
membersGroupOfVo2 = perun.getGroupsManagerBl().getGroupByName(sess, vo2, VosManager.MEMBERS_GROUP);
group1InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, new Group("testGroup1InVo1", ""));
group2InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, new Group("testGroup2InVo1", ""));
group1InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, new Group("testGroup1InVo2", ""));
group2InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, new Group("testGroup2InVo2", ""));
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member1OfUser1);
perun.getGroupsManagerBl().addMember(sess, group2InVo1, member1OfUser1);
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member2OfUser2);
perun.getGroupsManagerBl().addMember(sess, group2InVo1, member2OfUser2);
perun.getGroupsManagerBl().addMember(sess, group1InVo2, member2OfUser1);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member2OfUser1);
perun.getGroupsManagerBl().addMember(sess, group1InVo2, member1OfUser2);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member1OfUser2);
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member1OfUser3);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member2OfUser3);
//Create Facility
facility1 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility1"));
facility2 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility2"));
facility3 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility3"));
//Create Host on Facilities
host1OnFacility1 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility1"), facility1);
host2OnFacility1 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility1"), facility1);
host1OnFacility2 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility2"), facility2);
host2OnFacility2 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility2"), facility2);
host1OnFacility3 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility3"), facility3);
host2OnFacility3 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility3"), facility3);
//Create resources and assing group to them
resource1InVo1 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource1InVo1", "", facility1.getId(), vo1.getId()), vo1, facility1);
resource2InVo1 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource2InVo1", "", facility2.getId(), vo1.getId()), vo1, facility2);
resource1InVo2 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource1InVo2", "", facility2.getId(), vo2.getId()), vo2, facility2);
resource2InVo2 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource2InVo2", "", facility3.getId(), vo2.getId()), vo2, facility3);
perun.getResourcesManagerBl().assignGroupToResource(sess, group1InVo1, resource1InVo1);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo1, resource1InVo1);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo1, resource2InVo1);
perun.getResourcesManagerBl().assignGroupToResource(sess, group1InVo2, resource1InVo2);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo2, resource1InVo2);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo2, resource2InVo2);
}
Aggregations