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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations