Search in sources :

Example 1 with AuthzRoles

use of cz.metacentrum.perun.core.impl.AuthzRoles in project perun by CESNET.

the class FacilitiesManagerEntryIntegrationTest method addHostSameHostDifferentAdmin.

@Test(expected = PrivilegeException.class)
public void addHostSameHostDifferentAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostSameHostDifferentAdmin");
    // Initialize host
    Host host = new Host(0, "testHost");
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set up two members
    Member memberOne = setUpMember(vo);
    Member memberTwo = setUpMember(vo);
    // Set users as admins of different facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, memberOne);
    facilitiesManagerEntry.addAdmin(sess, facility, userOne);
    User userTwo = perun.getUsersManagerBl().getUserByMember(sess, memberTwo);
    facilitiesManagerEntry.addAdmin(sess, secondFacility, userTwo);
    // Sets userOne as actor in this test with role facility admin for facility
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, facility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds host to facility
    facilitiesManagerEntry.addHost(sess, host, facility);
    assertTrue(facilitiesManagerEntry.getHosts(sess, facility).size() == 1);
    // Change actor in this test to userTwo
    authzRoles = new AuthzRoles(Role.FACILITYADMIN, secondFacility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userTwo);
    // Adds same host to secondFacility with different admin -> should throw exception
    facilitiesManagerEntry.addHost(sess, host, secondFacility);
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) Host(cz.metacentrum.perun.core.api.Host) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with AuthzRoles

use of cz.metacentrum.perun.core.impl.AuthzRoles in project perun by CESNET.

the class FacilitiesManagerEntryIntegrationTest method addHostAndDestinationSameNameSameAdmin.

@Test
public void addHostAndDestinationSameNameSameAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostAndDestinationSameNameSameAdmin");
    // Initialize host, destination and service
    String hostName = "TestHost";
    Host hostOne = new Host(0, hostName);
    Destination destination = new Destination(0, hostName, Destination.DESTINATIONHOSTTYPE);
    Service service = new Service(0, "testService");
    ServicesManager servicesManagerEntry = perun.getServicesManager();
    service = servicesManagerEntry.createService(sess, service);
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set up two members
    Member memberOne = setUpMember(vo);
    // Set userOne as admin for both facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, memberOne);
    facilitiesManagerEntry.addAdmin(sess, facility, userOne);
    facilitiesManagerEntry.addAdmin(sess, secondFacility, userOne);
    // Sets userOne as actor in this test with role facility admin for facility
    List<PerunBean> list = new ArrayList<PerunBean>();
    list.add(facility);
    list.add(secondFacility);
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, list);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds host to facility
    facilitiesManagerEntry.addHost(sess, hostOne, facility);
    assertTrue(facilitiesManagerEntry.getHosts(sess, facility).size() == 1);
    // Adds destination with same name as host to facility
    servicesManagerEntry.addDestination(sess, service, facility, destination);
    assertTrue(servicesManagerEntry.getDestinations(sess, service, facility).size() == 1);
    // Adds same host to second facility
    facilitiesManagerEntry.addHost(sess, hostOne, secondFacility);
    assertTrue(facilitiesManagerEntry.getHosts(sess, secondFacility).size() == 1);
    // Adds destination with same name as host to secondFacility
    servicesManagerEntry.addDestination(sess, service, secondFacility, destination);
    assertTrue(servicesManagerEntry.getDestinations(sess, service, secondFacility).size() == 1);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) PerunBean(cz.metacentrum.perun.core.api.PerunBean) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ServicesManager(cz.metacentrum.perun.core.api.ServicesManager) ArrayList(java.util.ArrayList) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) Service(cz.metacentrum.perun.core.api.Service) Host(cz.metacentrum.perun.core.api.Host) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with AuthzRoles

use of cz.metacentrum.perun.core.impl.AuthzRoles in project perun by CESNET.

the class FacilitiesManagerEntryIntegrationTest method addHostsStringsSameHostsDifferentAdmin.

@Test(expected = PrivilegeException.class)
public void addHostsStringsSameHostsDifferentAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostsStringsSameHostsDifferentAdmin");
    // Sets list of hostnames
    String hostName = "testHostOne";
    List<String> listOfHosts = new ArrayList<String>();
    listOfHosts.add(hostName);
    hostName = "testHostTwo";
    listOfHosts.add(hostName);
    // Set up two members
    Member memberOne = setUpMember(vo);
    Member memberTwo = setUpMember(vo);
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set users as admins of different facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, memberOne);
    facilitiesManagerEntry.addAdmin(sess, facility, userOne);
    User userTwo = perun.getUsersManagerBl().getUserByMember(sess, memberTwo);
    facilitiesManagerEntry.addAdmin(sess, secondFacility, userTwo);
    // Sets userOne as actor in this test with role facility admin for facility
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, facility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds hosts to facility
    facilitiesManagerEntry.addHosts(sess, facility, listOfHosts);
    // Change actor in this test to userTwo
    authzRoles = new AuthzRoles(Role.FACILITYADMIN, secondFacility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userTwo);
    // Adds same hosts to secondFacility with different admin -> should throw exception
    facilitiesManagerEntry.addHosts(sess, secondFacility, listOfHosts);
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with AuthzRoles

use of cz.metacentrum.perun.core.impl.AuthzRoles in project perun by CESNET.

the class ServicesManagerEntryIntegrationTest method addDestinationSameDestinationDifferentAdmin.

@Test(expected = PrivilegeException.class)
public void addDestinationSameDestinationDifferentAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addDestinationSameDestinationDifferentAdmin");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    service = setUpService();
    Destination testDestination = new Destination(0, "TestDestination", Destination.DESTINATIONHOSTTYPE);
    member = setUpMember();
    Member memberTwo = setUpMember();
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set users as admins of different facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, member);
    perun.getFacilitiesManager().addAdmin(sess, facility, userOne);
    User userTwo = perun.getUsersManagerBl().getUserByMember(sess, memberTwo);
    perun.getFacilitiesManager().addAdmin(sess, secondFacility, userTwo);
    // Sets userOne as actor in this test with role facility admin for facility
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, facility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds destination to facility
    perun.getServicesManager().addDestination(sess, service, facility, testDestination);
    assertTrue(perun.getServicesManager().getDestinations(sess, service, facility).size() == 1);
    // Change actor in this test to userTwo
    authzRoles = new AuthzRoles(Role.FACILITYADMIN, secondFacility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userTwo);
    // Adds same destination to secondFacility -> should throw exception
    perun.getServicesManager().addDestination(sess, service, secondFacility, testDestination);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) RichDestination(cz.metacentrum.perun.core.api.RichDestination) User(cz.metacentrum.perun.core.api.User) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 5 with AuthzRoles

use of cz.metacentrum.perun.core.impl.AuthzRoles in project perun by CESNET.

the class AuthzResolverIntegrationTest method addAllSubgroupsToAuthzRoles.

@Test
public void addAllSubgroupsToAuthzRoles() throws Exception {
    System.out.println(CLASS_NAME + "addAllSubgroupsToAuthzRoles");
    Vo testVo = new Vo(1000, "AuthzResolver-testVo", "AuthzResolver-testVo");
    testVo = perun.getVosManagerBl().createVo(sess, testVo);
    Group testGroupA = new Group("AuthzResolver-testGroupA", "testGroupA");
    Group testGroupB = new Group("AuthzResolver-testGroupB", "testGroupB");
    Group testGroupC = new Group("AuthzResolver-testGroupC", "testGroupC");
    testGroupA = perun.getGroupsManagerBl().createGroup(sess, testVo, testGroupA);
    testGroupB = perun.getGroupsManagerBl().createGroup(sess, testGroupA, testGroupB);
    testGroupC = perun.getGroupsManagerBl().createGroup(sess, testGroupB, testGroupC);
    HashMap<String, Set<Integer>> mapWithRights = new HashMap<String, Set<Integer>>();
    Set<Integer> listWithIds = new HashSet<Integer>();
    listWithIds.add(testGroupA.getId());
    mapWithRights.put("Vo", listWithIds);
    mapWithRights.put("Group", listWithIds);
    AuthzRoles authzRoles = new AuthzRoles(Role.GROUPADMIN, mapWithRights);
    authzRoles = AuthzResolverBlImpl.addAllSubgroupsToAuthzRoles(sess, authzRoles);
    assertTrue(authzRoles.hasRole(Role.GROUPADMIN));
    assertTrue(!authzRoles.hasRole(Role.VOADMIN));
    assertTrue(authzRoles.get(Role.GROUPADMIN).containsKey("Group"));
    assertTrue(authzRoles.get(Role.GROUPADMIN).containsKey("Vo"));
    assertTrue(authzRoles.get(Role.GROUPADMIN).get("Group").contains(testGroupA.getId()));
    assertTrue(authzRoles.get(Role.GROUPADMIN).get("Group").contains(testGroupB.getId()));
    assertTrue(authzRoles.get(Role.GROUPADMIN).get("Group").contains(testGroupC.getId()));
    assertTrue(authzRoles.get(Role.GROUPADMIN).get("Group").size() == 3);
    assertTrue(authzRoles.get(Role.GROUPADMIN).get("Vo").contains(testGroupA.getId()));
    assertTrue(authzRoles.get(Role.GROUPADMIN).get("Vo").size() == 1);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) HashSet(java.util.HashSet) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

AuthzRoles (cz.metacentrum.perun.core.impl.AuthzRoles)14 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)12 Test (org.junit.Test)12 Facility (cz.metacentrum.perun.core.api.Facility)8 Member (cz.metacentrum.perun.core.api.Member)8 User (cz.metacentrum.perun.core.api.User)8 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)7 RichUser (cz.metacentrum.perun.core.api.RichUser)7 Destination (cz.metacentrum.perun.core.api.Destination)5 Host (cz.metacentrum.perun.core.api.Host)5 ArrayList (java.util.ArrayList)5 Service (cz.metacentrum.perun.core.api.Service)4 ServicesManager (cz.metacentrum.perun.core.api.ServicesManager)4 SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)3 PerunBean (cz.metacentrum.perun.core.api.PerunBean)1 RichDestination (cz.metacentrum.perun.core.api.RichDestination)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1