Search in sources :

Example 56 with Resource

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

the class FacilitiesManagerEntryIntegrationTest method getAllowedUsersWithVoAndServiceFilter.

@Test
public void getAllowedUsersWithVoAndServiceFilter() throws Exception {
    System.out.println(CLASS_NAME + "getAllowedUsers");
    Vo vo = setUpVo();
    Resource resource = setUpResource(vo);
    Service serv = new Service();
    serv.setName("TestService");
    perun.getServicesManager().createService(sess, serv);
    perun.getResourcesManager().assignService(sess, resource, serv);
    Member member = setUpMember(vo);
    User user = perun.getUsersManagerBl().getUserByMember(sess, member);
    Group group = setUpGroup(vo, member);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group, resource);
    // second vo and member, assign group but no service
    Vo vo2 = new Vo();
    vo2.setName("FacilitiesMangerTestVo2");
    vo2.setShortName("FMTVO2");
    assertNotNull("unable to create VO", perun.getVosManager().createVo(sess, vo2));
    Member member2 = setUpMember(vo2);
    User user2 = perun.getUsersManagerBl().getUserByMember(sess, member2);
    Group group2 = setUpGroup(vo2, member2);
    Resource resource2 = setUpResource(vo2);
    perun.getResourcesManager().assignService(sess, resource2, serv);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group2, resource2);
    List<User> users = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo, serv);
    assertTrue("our facility should have 1 allowed user", users.size() == 1);
    assertTrue("our user should be between allowed on facility", users.contains(user));
    List<User> users2 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, serv);
    assertTrue("our facility should have 1 allowed user", users2.size() == 1);
    assertTrue("our user should be between allowed on facility", users2.contains(user2));
    List<User> users3 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, null, serv);
    assertTrue("our facility should have 1 allowed user", users3.size() == 2);
    assertTrue("our user should be between allowed on facility", users3.contains(user));
    assertTrue("our user should be between allowed on facility", users3.contains(user2));
    List<User> users4 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo, null);
    assertTrue("our facility should have 1 allowed user", users4.size() == 1);
    assertTrue("our user should be between allowed on facility", users4.contains(user));
    List<User> users5 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, null);
    assertTrue("our facility should have 1 allowed user", users5.size() == 1);
    assertTrue("our user should be between allowed on facility", users5.contains(user2));
    // remove service from resource2 to test other edge cases
    perun.getResourcesManager().removeService(sess, resource2, serv);
    List<User> users6 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo, serv);
    assertTrue("our facility should have 1 allowed user", users6.size() == 1);
    assertTrue("our user should be between allowed on facility", users6.contains(user));
    List<User> users7 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, serv);
    assertTrue("our user shouldn't be allowed on facility with vo filter on", users7.size() == 0);
    List<User> users8 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, null, serv);
    assertTrue("our facility should have 1 allowed user", users8.size() == 1);
    assertTrue("our user should be between allowed on facility", users8.contains(user));
    assertTrue("our user shouldn't be between allowed on facility", !users8.contains(user2));
    List<User> users9 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo, null);
    assertTrue("our facility should have 1 allowed user", users9.size() == 1);
    assertTrue("our user should be between allowed on facility", users9.contains(user));
    List<User> users10 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, null);
    assertTrue("our facility should have 1 allowed user", users10.size() == 1);
    assertTrue("our user should be between allowed on facility", users10.contains(user2));
    // create different service to test another edge cases
    Service serv2 = new Service();
    serv2.setName("TestService2");
    serv2 = perun.getServicesManager().createService(sess, serv2);
    perun.getResourcesManager().assignService(sess, resource2, serv2);
    List<User> users11 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo, serv2);
    assertTrue("our facility shouldn't have allowed user with vo and service filter on", users11.size() == 0);
    List<User> users12 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, serv2);
    assertTrue("our facility should have 1 allowed user", users12.size() == 1);
    assertTrue("our user should be between allowed on facility", users12.contains(user2));
    List<User> users13 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, null, serv2);
    assertTrue("our facility should have 1 allowed user", users13.size() == 1);
    assertTrue("our user should be between allowed on facility", users13.contains(user2));
    List<User> users14 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo, null);
    assertTrue("our facility should have 1 allowed user", users14.size() == 1);
    assertTrue("our user should be between allowed on facility", users14.contains(user));
    List<User> users15 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, null);
    assertTrue("our facility should have 1 allowed user", users15.size() == 1);
    assertTrue("our user should be between allowed on facility", users15.contains(user2));
    List<User> users16 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, null, null);
    assertTrue("our facility should have 2 allowed users", users16.size() == 2);
    assertTrue("our user should be between allowed on facility", users16.contains(user));
    assertTrue("our user should be between allowed on facility", users16.contains(user2));
    // disabled members shouldn't be allowed
    perun.getMembersManager().setStatus(sess, member, Status.DISABLED);
    List<User> users17 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, null, null);
    assertTrue("our facility should have 1 allowed user", users17.size() == 1);
    assertTrue("our user should be between allowed on facility", users17.contains(user2));
    List<User> users18 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo, null);
    assertTrue("our facility shouldn't have allowed user with vo filter on", users18.size() == 0);
    List<User> users19 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, null);
    assertTrue("our facility should have 1 allowed user", users19.size() == 1);
    assertTrue("our user should be between allowed on facility", users19.contains(user2));
    List<User> users20 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, serv);
    assertTrue("our facility shouldn't have allowed user with vo and service filter on", users20.size() == 0);
    List<User> users21 = perun.getFacilitiesManager().getAllowedUsers(sess, facility, vo2, serv2);
    assertTrue("our facility should have 1 allowed user", users21.size() == 1);
    assertTrue("our user should be between allowed on facility", users21.contains(user2));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) Vo(cz.metacentrum.perun.core.api.Vo) Service(cz.metacentrum.perun.core.api.Service) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 57 with Resource

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

the class AttributesManagerEntryIntegrationTest method getResourceRequiredFacilityUserAttributesWhenResourceNotExists.

@Test(expected = ResourceNotExistsException.class)
public void getResourceRequiredFacilityUserAttributesWhenResourceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getResourceRequiredFacilityUserAttributesWhenResourceNotExists");
    vo = setUpVo();
    member = setUpMember();
    facility = setUpFacility();
    User user = perun.getUsersManager().getUserByMember(sess, member);
    attributesManager.getResourceRequiredAttributes(sess, new Resource(), facility, user);
// shouldn't find resource
}
Also used : User(cz.metacentrum.perun.core.api.User) Resource(cz.metacentrum.perun.core.api.Resource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 58 with Resource

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

the class AttributesManagerEntryIntegrationTest method removeResourceAttributeWhenResourceNotExists.

@Test(expected = ResourceNotExistsException.class)
public void removeResourceAttributeWhenResourceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "removeResourceAttributeWhenResourceNotExists");
    attributes = setUpResourceAttribute();
    attributesManager.removeAttribute(sess, new Resource(), attributes.get(0));
// shouldn't find resource
}
Also used : Resource(cz.metacentrum.perun.core.api.Resource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 59 with Resource

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

the class AttributesManagerEntryIntegrationTest method removeAllMemberResourceAttributesWhenResourceNotExists.

@Test(expected = ResourceNotExistsException.class)
public void removeAllMemberResourceAttributesWhenResourceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "removeAllMemberResourceAttributesWhenResourceNotExists");
    vo = setUpVo();
    member = setUpMember();
    attributesManager.removeAllAttributes(sess, new Resource(), member);
// shouldn't find resource
}
Also used : Resource(cz.metacentrum.perun.core.api.Resource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 60 with Resource

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

the class AttributesManagerEntryIntegrationTest method setGroupNameWillProduceSettingMoreThanOneGIDAtOnce.

// ==============  1. GET ATTRIBUTES ================================
@Test
public void setGroupNameWillProduceSettingMoreThanOneGIDAtOnce() throws Exception {
    System.out.println(CLASS_NAME + "setGroupNameWillProduceSettingMoreThanOneGIDAtOnce");
    //special variables
    String namespaceAAA = "AAA";
    String namespaceBBB = "BBB";
    //create attribute group_name in namespace aaa
    AttributeDefinition g_gn_AAA_def = new AttributeDefinition();
    g_gn_AAA_def.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    g_gn_AAA_def.setDescription("groupName in namespace AAA");
    g_gn_AAA_def.setFriendlyName("unixGroupName-namespace:" + namespaceAAA);
    g_gn_AAA_def.setType(String.class.getName());
    g_gn_AAA_def = perun.getAttributesManagerBl().createAttribute(sess, g_gn_AAA_def);
    Attribute g_gn_AAA = new Attribute(g_gn_AAA_def);
    g_gn_AAA.setValue("testGroupName");
    //create attribute group_name in namespace aaa
    AttributeDefinition g_gn_BBB_def = new AttributeDefinition();
    g_gn_BBB_def.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    g_gn_BBB_def.setDescription("groupName in namespace BBB");
    g_gn_BBB_def.setFriendlyName("unixGroupName-namespace:" + namespaceBBB);
    g_gn_BBB_def.setType(String.class.getName());
    g_gn_BBB_def = perun.getAttributesManagerBl().createAttribute(sess, g_gn_BBB_def);
    //create attribute gid in namespace aaa
    AttributeDefinition g_gid_AAA_def = new AttributeDefinition();
    g_gid_AAA_def.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    g_gid_AAA_def.setDescription("gid in namespace AAA");
    g_gid_AAA_def.setFriendlyName("unixGID-namespace:" + namespaceAAA);
    g_gid_AAA_def.setType(Integer.class.getName());
    g_gid_AAA_def = perun.getAttributesManagerBl().createAttribute(sess, g_gid_AAA_def);
    //create attribute gid in namespace bbb
    AttributeDefinition g_gid_BBB_def = new AttributeDefinition();
    g_gid_BBB_def.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
    g_gid_BBB_def.setDescription("gid in namespace BBB");
    g_gid_BBB_def.setFriendlyName("unixGID-namespace:" + namespaceBBB);
    g_gid_BBB_def.setType(Integer.class.getName());
    g_gid_BBB_def = perun.getAttributesManagerBl().createAttribute(sess, g_gid_BBB_def);
    //create attribute group_name in namespace aaa
    AttributeDefinition r_gn_AAA_def = new AttributeDefinition();
    r_gn_AAA_def.setNamespace(AttributesManager.NS_RESOURCE_ATTR_DEF);
    r_gn_AAA_def.setDescription("groupName in namespace AAA");
    r_gn_AAA_def.setFriendlyName("unixGroupName-namespace:" + namespaceAAA);
    r_gn_AAA_def.setType(String.class.getName());
    r_gn_AAA_def = perun.getAttributesManagerBl().createAttribute(sess, r_gn_AAA_def);
    //create attribute group_name in namespace aaa
    AttributeDefinition r_gn_BBB_def = new AttributeDefinition();
    r_gn_BBB_def.setNamespace(AttributesManager.NS_RESOURCE_ATTR_DEF);
    r_gn_BBB_def.setDescription("groupName in namespace BBB");
    r_gn_BBB_def.setFriendlyName("unixGroupName-namespace:" + namespaceBBB);
    r_gn_BBB_def.setType(String.class.getName());
    r_gn_BBB_def = perun.getAttributesManagerBl().createAttribute(sess, r_gn_BBB_def);
    //create attribute gid in namespace aaa
    AttributeDefinition r_gid_AAA_def = new AttributeDefinition();
    r_gid_AAA_def.setNamespace(AttributesManager.NS_RESOURCE_ATTR_DEF);
    r_gid_AAA_def.setDescription("gid in namespace AAA");
    r_gid_AAA_def.setFriendlyName("unixGID-namespace:" + namespaceAAA);
    r_gid_AAA_def.setType(Integer.class.getName());
    r_gid_AAA_def = perun.getAttributesManagerBl().createAttribute(sess, r_gid_AAA_def);
    //create attribute gid in namespace bbb
    AttributeDefinition r_gid_BBB_def = new AttributeDefinition();
    r_gid_BBB_def.setNamespace(AttributesManager.NS_RESOURCE_ATTR_DEF);
    r_gid_BBB_def.setDescription("gid in namespace BBB");
    r_gid_BBB_def.setFriendlyName("unixGID-namespace:" + namespaceBBB);
    r_gid_BBB_def.setType(Integer.class.getName());
    r_gid_BBB_def = perun.getAttributesManagerBl().createAttribute(sess, r_gid_BBB_def);
    //Create special enviroment
    Vo v1 = new Vo(0, "TestingVo01", "TestingVo01");
    v1 = perun.getVosManagerBl().createVo(sess, v1);
    Facility f1 = new Facility(0, "Facility01_test");
    f1 = perun.getFacilitiesManagerBl().createFacility(sess, f1);
    Facility f2 = new Facility(0, "Facility02_test");
    f2 = perun.getFacilitiesManagerBl().createFacility(sess, f2);
    Resource r1 = new Resource(0, "TestingResource01", "TestingResource01", f1.getId(), v1.getId());
    r1 = perun.getResourcesManagerBl().createResource(sess, r1, v1, f1);
    Resource r2 = new Resource(0, "TestingResource02", "TestingResource02", f2.getId(), v1.getId());
    r2 = perun.getResourcesManagerBl().createResource(sess, r2, v1, f2);
    Group g1 = new Group("Testing_group01", "Testing group01");
    g1 = perun.getGroupsManagerBl().createGroup(sess, v1, g1);
    perun.getResourcesManagerBl().assignGroupToResource(sess, g1, r1);
    perun.getResourcesManagerBl().assignGroupToResource(sess, g1, r2);
    //Create minGID and maxGID for new namespace
    AttributeDefinition maxGIDAttrDef = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:entityless:attribute-def:def:namespace-maxGID");
    Attribute maxGIDAAA = new Attribute(maxGIDAttrDef);
    maxGIDAAA.setValue(10000);
    Attribute maxGIDBBB = new Attribute(maxGIDAttrDef);
    maxGIDBBB.setValue(10000);
    AttributeDefinition minGIDAttrDef = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:entityless:attribute-def:def:namespace-minGID");
    Attribute minGIDAAA = new Attribute(minGIDAttrDef);
    minGIDAAA.setValue(100);
    Attribute minGIDBBB = new Attribute(minGIDAttrDef);
    minGIDBBB.setValue(100);
    perun.getAttributesManagerBl().setAttribute(sess, namespaceAAA, minGIDAAA);
    perun.getAttributesManagerBl().setAttribute(sess, namespaceBBB, minGIDBBB);
    perun.getAttributesManagerBl().setAttribute(sess, namespaceAAA, maxGIDAAA);
    perun.getAttributesManagerBl().setAttribute(sess, namespaceBBB, maxGIDBBB);
    //set new namespace for facility (gid and groupName)
    AttributeDefinition groupNameNamespaceForFacilitiesAttrDef = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:facility:attribute-def:def:unixGroupName-namespace");
    Attribute groupNameNamespaceForFacilities = new Attribute(groupNameNamespaceForFacilitiesAttrDef);
    groupNameNamespaceForFacilities.setValue(namespaceAAA);
    perun.getAttributesManagerBl().setAttribute(sess, f1, groupNameNamespaceForFacilities);
    perun.getAttributesManagerBl().setAttribute(sess, f2, groupNameNamespaceForFacilities);
    AttributeDefinition GIDNamespaceForFacilitiesAttrDef = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:facility:attribute-def:def:unixGID-namespace");
    Attribute GIDNamespaceForFacilities = new Attribute(GIDNamespaceForFacilitiesAttrDef);
    GIDNamespaceForFacilities.setValue(namespaceAAA);
    perun.getAttributesManagerBl().setAttribute(sess, f1, GIDNamespaceForFacilities);
    GIDNamespaceForFacilities.setValue(namespaceBBB);
    perun.getAttributesManagerBl().setAttribute(sess, f2, GIDNamespaceForFacilities);
    //create new service and assigne it to resources
    Service s1 = new Service(0, "testService01");
    s1 = perun.getServicesManagerBl().createService(sess, s1);
    perun.getResourcesManagerBl().assignService(sess, r1, s1);
    perun.getResourcesManagerBl().assignService(sess, r2, s1);
    //create other required attributes and add them to the service
    AttributeDefinition f_v_maxGID = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:facility:attribute-def:virt:maxGID");
    AttributeDefinition f_v_minGID = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:facility:attribute-def:virt:minGID");
    AttributeDefinition g_v_gn = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:group_resource:attribute-def:virt:unixGroupName");
    AttributeDefinition g_v_gid = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:group_resource:attribute-def:virt:unixGID");
    perun.getServicesManagerBl().addRequiredAttribute(sess, s1, groupNameNamespaceForFacilitiesAttrDef);
    perun.getServicesManagerBl().addRequiredAttribute(sess, s1, GIDNamespaceForFacilitiesAttrDef);
    perun.getServicesManagerBl().addRequiredAttribute(sess, s1, f_v_maxGID);
    perun.getServicesManagerBl().addRequiredAttribute(sess, s1, f_v_minGID);
    perun.getServicesManagerBl().addRequiredAttribute(sess, s1, g_v_gn);
    perun.getServicesManagerBl().addRequiredAttribute(sess, s1, g_v_gid);
    //set group_name to group g1
    perun.getAttributesManagerBl().setAttribute(sess, g1, g_gn_AAA);
    Attribute groupGIDInAAA = perun.getAttributesManagerBl().getAttribute(sess, g1, g_gid_AAA_def.getName());
    Attribute groupGIDInBBB = perun.getAttributesManagerBl().getAttribute(sess, g1, g_gid_BBB_def.getName());
    assertEquals(new Integer(100), (Integer) groupGIDInAAA.getValue());
    assertEquals(new Integer(100), (Integer) groupGIDInBBB.getValue());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Resource(cz.metacentrum.perun.core.api.Resource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) Service(cz.metacentrum.perun.core.api.Service) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Resource (cz.metacentrum.perun.core.api.Resource)176 Test (org.junit.Test)110 Attribute (cz.metacentrum.perun.core.api.Attribute)82 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)79 Facility (cz.metacentrum.perun.core.api.Facility)56 User (cz.metacentrum.perun.core.api.User)55 Group (cz.metacentrum.perun.core.api.Group)49 ArrayList (java.util.ArrayList)41 Vo (cz.metacentrum.perun.core.api.Vo)31 Member (cz.metacentrum.perun.core.api.Member)29 PerunSession (cz.metacentrum.perun.core.api.PerunSession)29 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)26 RichResource (cz.metacentrum.perun.core.api.RichResource)25 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)20 RichUser (cz.metacentrum.perun.core.api.RichUser)18 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)18 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)17 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)17 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)15 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)14