Search in sources :

Example 31 with SecurityTeam

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

the class SecurityTeamsManagerEntryIntegrationTest method testGetAdminsWithoutSecurityTeam.

@Test(expected = SecurityTeamNotExistsException.class)
public void testGetAdminsWithoutSecurityTeam() throws Exception {
    System.out.println(CLASS_NAME + "testGetAdminsWithoutSecurityTeam");
    SecurityTeam st = new SecurityTeam(0, "Name", "Desc");
    securityTeamsManagerEntry.getAdmins(sess, st);
}
Also used : SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 32 with SecurityTeam

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

the class SecurityTeamsManagerEntryIntegrationTest method testGetBlacklistBySecurityTeamSecurityTeamNotExists.

@Test(expected = SecurityTeamNotExistsException.class)
public void testGetBlacklistBySecurityTeamSecurityTeamNotExists() throws Exception {
    System.out.println(CLASS_NAME + "testGetBlacklistBySecurityTeamSecurityTeamNotExists");
    setUpSecurityTeams();
    setUpUsers();
    setUpFacilities();
    setUpBlacklists();
    SecurityTeam st = new SecurityTeam(0, "Security0", "Description test 0");
    securityTeamsManagerEntry.getBlacklist(sess, st);
}
Also used : SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 33 with SecurityTeam

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

the class SecurityTeamsManagerEntryIntegrationTest method testGetSecurityTeamsSecurityAdmin.

@Test
public void testGetSecurityTeamsSecurityAdmin() throws Exception {
    System.out.println(CLASS_NAME + "testGetSecurityTeamsSecurityAdmin");
    AuthzRoles roles = sess.getPerunPrincipal().getRoles();
    try {
        setUpSecurityTeams();
        setUpUsers();
        List<SecurityTeam> expected = new ArrayList<>();
        expected.add(st0);
        sess.getPerunPrincipal().setRoles(new AuthzRoles(Role.SECURITYADMIN, st0));
        List<SecurityTeam> actual = securityTeamsManagerEntry.getSecurityTeams(sess);
        assertEquals(expected, actual);
    } finally {
        sess.getPerunPrincipal().setRoles(roles);
    }
}
Also used : AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 34 with SecurityTeam

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

the class SecurityTeamsManagerEntry method updateSecurityTeam.

@Override
public SecurityTeam updateSecurityTeam(PerunSession sess, SecurityTeam securityTeam) throws InternalErrorException, PrivilegeException, SecurityTeamNotExistsException, SecurityTeamExistsException {
    Utils.checkPerunSession(sess);
    Utils.notNull(securityTeam, "securityTeam");
    Utils.notNull(securityTeam.getName(), "securityTeam.name");
    if (!AuthzResolver.isAuthorized(sess, Role.SECURITYADMIN, securityTeam)) {
        throw new PrivilegeException(sess, "updateSecurityTeam");
    }
    if (securityTeam.getName().length() > 128) {
        throw new InternalErrorException("Security Team name is too long, >128 characters");
    }
    if (!securityTeam.getName().matches("^[-_a-zA-z0-9.]{1,128}$")) {
        throw new InternalErrorException("Wrong Security name - must matches [-_a-zA-z0-9.]+ and not be longer than 128 characters.");
    }
    getSecurityTeamsManagerBl().checkSecurityTeamExists(sess, securityTeam);
    try {
        SecurityTeam existingTeam = getSecurityTeamsManagerBl().getSecurityTeamByName(sess, securityTeam.getName());
        if (existingTeam != null && existingTeam.getId() != securityTeam.getId()) {
            throw new SecurityTeamExistsException("SecurityTeam with name='" + securityTeam.getName() + "' already exists.");
        }
    } catch (SecurityTeamNotExistsException ex) {
    // OK since we are renaming security team to non-taken value
    }
    // don't store empty description
    if (securityTeam.getDescription() != null && securityTeam.getDescription().trim().isEmpty()) {
        securityTeam.setDescription(null);
    }
    return getSecurityTeamsManagerBl().updateSecurityTeam(sess, securityTeam);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) SecurityTeamExistsException(cz.metacentrum.perun.core.api.exceptions.SecurityTeamExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) SecurityTeamNotExistsException(cz.metacentrum.perun.core.api.exceptions.SecurityTeamNotExistsException)

Example 35 with SecurityTeam

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

the class FacilitiesManagerBlImpl method deleteFacility.

public void deleteFacility(PerunSession sess, Facility facility) throws InternalErrorException, RelationExistsException, FacilityAlreadyRemovedException, HostAlreadyRemovedException, GroupAlreadyRemovedException, ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
    if (getFacilitiesManagerImpl().getAssignedResources(sess, facility).size() > 0) {
        throw new RelationExistsException("Facility is still used as a resource");
    }
    //remove hosts
    List<Host> hosts = this.getHosts(sess, facility);
    for (Host host : hosts) {
        this.removeHost(sess, host);
    }
    //remove destinations
    getPerunBl().getServicesManagerBl().removeAllDestinations(sess, facility);
    // remove assigned security teams
    List<SecurityTeam> teams = getAssignedSecurityTeams(sess, facility);
    for (SecurityTeam team : teams) {
        removeSecurityTeam(sess, facility, team);
    }
    // remove assigned facility contacts
    List<ContactGroup> contacts = getFacilityContactGroups(sess, facility);
    if (contacts != null && !contacts.isEmpty()) {
        removeFacilityContacts(sess, contacts);
    }
    // remove associated attributes
    try {
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (WrongReferenceAttributeValueException e) {
        throw new InternalErrorException(e);
    }
    //Remove all facility bans
    List<BanOnFacility> bansOnFacility = this.getBansForFacility(sess, facility.getId());
    for (BanOnFacility banOnFacility : bansOnFacility) {
        try {
            this.removeBan(sess, banOnFacility.getId());
        } catch (BanNotExistsException ex) {
        //it is ok, we just want to remove it anyway
        }
    }
    // delete facility
    getFacilitiesManagerImpl().deleteFacilityOwners(sess, facility);
    getFacilitiesManagerImpl().deleteFacility(sess, facility);
    getPerunBl().getAuditer().log(sess, "Facility deleted {}.", facility);
}
Also used : Host(cz.metacentrum.perun.core.api.Host) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Aggregations

SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)37 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)30 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)4 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)3 AuthzRoles (cz.metacentrum.perun.core.impl.AuthzRoles)3 Facility (cz.metacentrum.perun.core.api.Facility)2 Group (cz.metacentrum.perun.core.api.Group)2 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)1 Host (cz.metacentrum.perun.core.api.Host)1 User (cz.metacentrum.perun.core.api.User)1 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1 RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)1 SecurityTeamExistsException (cz.metacentrum.perun.core.api.exceptions.SecurityTeamExistsException)1 SecurityTeamNotExistsException (cz.metacentrum.perun.core.api.exceptions.SecurityTeamNotExistsException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1 HashSet (java.util.HashSet)1