Search in sources :

Example 76 with Facility

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

the class urn_perun_user_facility_attribute_def_def_shellTest method testCheckAttributeValue.

/**
	 * Test of checkAttributeValue method, of class urn_perun_user_facility_attribute_def_def_shell.
	 * with all parameters properly set.
	 */
@Test
public void testCheckAttributeValue() throws Exception {
    System.out.println("testCheckAttributeValue()");
    Attribute attributeToCheck = new Attribute();
    attributeToCheck.setValue("/bin/bash");
    when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSession.class), any(Facility.class), any(User.class))).thenReturn(new ArrayList<Resource>() {

        {
            add(resource);
        }
    });
    when(session.getPerunBl().getFacilitiesManagerBl().getAssignedResources(any(PerunSession.class), any(Facility.class))).thenReturn(new ArrayList<Resource>() {

        {
            add(resource);
        }
    });
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), eq(AttributesManager.NS_RESOURCE_ATTR_DEF + ":shells"))).thenReturn(listOfShells);
    classInstance.checkAttributeValue(session, facility, user, attributeToCheck);
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility) Test(org.junit.Test)

Example 77 with Facility

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

the class urn_perun_user_facility_attribute_def_def_shellTest method testCheckAttributeValueWithEmptyAttribute.

/**
	 * Test of checkAttributeValue method, of class urn_perun_user_facility_attribute_def_def_shell.
	 * with empty attribute.
	 */
public void testCheckAttributeValueWithEmptyAttribute() throws Exception {
    System.out.println("testCheckAttributeValueWithEmptyAttribute()");
    when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSession.class), any(Facility.class), any(User.class))).thenReturn(new ArrayList<Resource>() {

        {
            add(resource);
        }
    });
    when(session.getPerunBl().getFacilitiesManagerBl().getAssignedResources(any(PerunSession.class), any(Facility.class))).thenReturn(new ArrayList<Resource>() {

        {
            add(resource);
        }
    });
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenReturn(listOfShells);
    classInstance.checkAttributeValue(session, facility, user, new Attribute());
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility)

Example 78 with Facility

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

the class OwnersManagerBlImpl method deleteOwner.

public void deleteOwner(PerunSession sess, Owner owner, boolean forceDelete) throws InternalErrorException, RelationExistsException, OwnerAlreadyRemovedException {
    // Check if the owner is assigned to some facility
    List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getOwnerFacilities(sess, owner);
    if (facilities != null && facilities.size() > 0) {
        if (!forceDelete) {
            throw new RelationExistsException("Owner own " + facilities.size() + " facilities");
        } else {
            for (Facility facility : facilities) {
                try {
                    getPerunBl().getFacilitiesManagerBl().removeOwner(sess, facility, owner);
                } catch (OwnerAlreadyRemovedException e) {
                    throw new InternalErrorException(e);
                }
            }
        }
    }
    //Remove all information about owner on facilities (facilities contacts)
    List<ContactGroup> ownerContactGroups = getPerunBl().getFacilitiesManagerBl().getFacilityContactGroups(sess, owner);
    if (!ownerContactGroups.isEmpty()) {
        if (forceDelete) {
            getPerunBl().getFacilitiesManagerBl().removeAllOwnerContacts(sess, owner);
        } else {
            throw new RelationExistsException("Owner has still some facilities contacts : " + ownerContactGroups);
        }
    }
    getOwnersManagerImpl().deleteOwner(sess, owner);
    getPerunBl().getAuditer().log(sess, "{} deleted.", owner);
}
Also used : RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) OwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.OwnerAlreadyRemovedException) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup)

Example 79 with Facility

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

the class SecurityTeamsManagerBlImpl method deleteSecurityTeam.

@Override
public void deleteSecurityTeam(PerunSession sess, SecurityTeam securityTeam, boolean forceDelete) throws SecurityTeamNotExistsException, InternalErrorException, RelationExistsException {
    // remove all users from blacklist, which were blacklisted by this security team.
    List<User> blacklist = getSecurityTeamsManagerImpl().getBlacklist(sess, Arrays.asList(securityTeam));
    if (blacklist != null && !blacklist.isEmpty() && !forceDelete) {
        throw new RelationExistsException("SecurityTeam has blacklisted users.");
    }
    for (User blacklistedUser : blacklist) {
        // calling BL will make auditer message about user to appear.
        getPerunBl().getSecurityTeamsManagerBl().removeUserFromBlacklist(sess, securityTeam, blacklistedUser);
    }
    // remove security team from all facilities
    List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getAssignedFacilities(sess, securityTeam);
    if (facilities != null && !facilities.isEmpty() && !forceDelete) {
        throw new RelationExistsException("SecurityTeam is assigned to some facilities.");
    }
    for (Facility facility : facilities) {
        // calling BL will make auditer message about facility to appear.
        getPerunBl().getFacilitiesManagerBl().removeSecurityTeam(sess, facility, securityTeam);
    }
    getSecurityTeamsManagerImpl().deleteSecurityTeam(sess, securityTeam);
    getPerunBl().getAuditer().log(sess, "{} was deleted.", securityTeam);
}
Also used : User(cz.metacentrum.perun.core.api.User) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Facility(cz.metacentrum.perun.core.api.Facility)

Example 80 with Facility

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

the class FacilitiesManagerBlImpl method getRichFacilities.

public List<RichFacility> getRichFacilities(PerunSession perunSession, List<Facility> facilities) throws InternalErrorException {
    List<RichFacility> richFacilities = new ArrayList<RichFacility>();
    if (facilities == null || facilities.isEmpty())
        return richFacilities;
    else {
        for (Facility f : facilities) {
            List<Owner> fOwners = this.getOwners(perunSession, f);
            RichFacility rf = new RichFacility(f, fOwners);
            richFacilities.add(rf);
        }
    }
    return richFacilities;
}
Also used : Owner(cz.metacentrum.perun.core.api.Owner) ArrayList(java.util.ArrayList) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) RichFacility(cz.metacentrum.perun.core.api.RichFacility) RichFacility(cz.metacentrum.perun.core.api.RichFacility)

Aggregations

Facility (cz.metacentrum.perun.core.api.Facility)188 Test (org.junit.Test)95 User (cz.metacentrum.perun.core.api.User)81 Attribute (cz.metacentrum.perun.core.api.Attribute)75 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)61 Resource (cz.metacentrum.perun.core.api.Resource)52 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)51 ArrayList (java.util.ArrayList)48 Group (cz.metacentrum.perun.core.api.Group)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)23 Member (cz.metacentrum.perun.core.api.Member)22 PerunSession (cz.metacentrum.perun.core.api.PerunSession)20 RichFacility (cz.metacentrum.perun.core.api.RichFacility)20 Host (cz.metacentrum.perun.core.api.Host)19 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)18 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)17 RichUser (cz.metacentrum.perun.core.api.RichUser)16 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 Vo (cz.metacentrum.perun.core.api.Vo)13