Search in sources :

Example 46 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_resource_attribute_def_def_unixGroupName_namespaceTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_resource_attribute_def_def_unixGroupName_namespace();
    attributeToCheck = new Attribute();
    attributeToCheck.setFriendlyName("unixGID-namespace");
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:")).thenReturn(attributeToCheck);
    GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class);
    when(sess.getPerunBl().getGroupsManagerBl()).thenReturn(groupsManagerBl);
    ModulesUtilsBl modulesUtilsBl = mock(ModulesUtilsBl.class);
    when(sess.getPerunBl().getModulesUtilsBl()).thenReturn(modulesUtilsBl);
    ResourcesManagerBl resourcesManagerBl = mock(ResourcesManagerBl.class);
    when(sess.getPerunBl().getResourcesManagerBl()).thenReturn(resourcesManagerBl);
}
Also used : ResourcesManagerBl(cz.metacentrum.perun.core.bl.ResourcesManagerBl) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) ModulesUtilsBl(cz.metacentrum.perun.core.bl.ModulesUtilsBl) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 47 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_user_attribute_def_def_login_namespace_eduroam_vsupTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_user_attribute_def_def_login_namespace_eduroam_vsup();
    session = mock(PerunSessionImpl.class);
    user = new User();
    attributeToCheck = new Attribute();
    attributeToCheck.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attributeToCheck.setFriendlyName("login-namespace:eduroam-vsup");
    attribute = new Attribute();
    attribute.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attribute.setFriendlyName("login-namespace:eduroam-vsup");
    attribute.setValue("same_value");
    PerunBl perunBl = mock(PerunBl.class);
    when(session.getPerunBl()).thenReturn(perunBl);
    ModulesUtilsBl modulesUtilsBl = mock(ModulesUtilsBl.class);
    when(perunBl.getModulesUtilsBl()).thenReturn(modulesUtilsBl);
    UsersManagerBl usersManagerBl = mock(UsersManagerBl.class);
    when(perunBl.getUsersManagerBl()).thenReturn(usersManagerBl);
    PasswordManagerModule module = mock(GenericPasswordManagerModule.class);
    when(session.getPerunBl().getUsersManagerBl().getPasswordManagerModule(session, "eduroam-vsup")).thenReturn(module);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(attributesManagerBl.getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:vsup")).thenReturn(attribute);
}
Also used : User(cz.metacentrum.perun.core.api.User) ModulesUtilsBl(cz.metacentrum.perun.core.bl.ModulesUtilsBl) Attribute(cz.metacentrum.perun.core.api.Attribute) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 48 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_resource_attribute_def_def_defaultHomeMountPointTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_resource_attribute_def_def_defaultHomeMountPoint();
    attributeToCheck = new Attribute();
    reqAttribute = new Attribute();
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, AttributesManager.NS_RESOURCE_ATTR_DEF + ":homeMountPoints")).thenReturn(reqAttribute);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 49 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_resource_attribute_def_def_homeMountPointsTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_resource_attribute_def_def_homeMountPoints();
    attributeToCheck = new Attribute();
    reqAttribute = new Attribute();
    sess = mock(PerunSessionImpl.class);
    Facility facility = new Facility();
    List<String> value = new ArrayList<>();
    value.add("/example");
    attributeToCheck.setValue(value);
    reqAttribute.setValue(value);
    PerunBl perunBl = mock(PerunBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":homeMountPoints")).thenReturn(reqAttribute);
    ResourcesManagerBl resourcesManagerBl = mock(ResourcesManagerBl.class);
    when(perunBl.getResourcesManagerBl()).thenReturn(resourcesManagerBl);
    when(resourcesManagerBl.getFacility(sess, resource)).thenReturn(facility);
}
Also used : ResourcesManagerBl(cz.metacentrum.perun.core.bl.ResourcesManagerBl) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Facility(cz.metacentrum.perun.core.api.Facility) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 50 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu method checkAttributeSemantics.

@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    List<String> emails = attribute.valueAsList();
    if (emails == null)
        emails = new ArrayList<>();
    // at least one value if adName is set
    AttributesManagerBl am = sess.getPerunBl().getAttributesManagerBl();
    try {
        if (emails.isEmpty()) {
            Attribute adName = am.getAttribute(sess, resource, group, ADNAME_ATTRIBUTE);
            if (adName.getValue() != null) {
                throw new WrongReferenceAttributeValueException(attribute, adName, resource, group, resource, group, "at least one email must be defined");
            }
            return;
        }
    } catch (AttributeNotExistsException | GroupResourceMismatchException e) {
        throw new InternalErrorException(e.getMessage(), e);
    }
    // check for duplicities among all members and groups
    AttributesManagerBl attributesManagerBl = sess.getPerunBl().getAttributesManagerBl();
    Set<Pair<Integer, Integer>> groupResourcePairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, attribute);
    groupResourcePairs.remove(new Pair<>(group.getId(), resource.getId()));
    if (!groupResourcePairs.isEmpty()) {
        throw new WrongReferenceAttributeValueException(attribute, attribute, group, resource, "some of the email addresses are already assigned to the following group_resource pairs: " + groupResourcePairs);
    }
    Attribute userO365EmailAddresses = new Attribute(new urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu().getAttributeDefinition());
    userO365EmailAddresses.setValue(emails);
    Set<Pair<Integer, Integer>> userPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, userO365EmailAddresses);
    if (!userPairs.isEmpty()) {
        throw new WrongReferenceAttributeValueException(attribute, userO365EmailAddresses, group, resource, "user " + BeansUtils.getSingleId(userPairs) + " ");
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Pair(cz.metacentrum.perun.core.api.Pair)

Aggregations

AttributesManagerBl (cz.metacentrum.perun.core.bl.AttributesManagerBl)56 Attribute (cz.metacentrum.perun.core.api.Attribute)48 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)44 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)43 Before (org.junit.Before)42 Facility (cz.metacentrum.perun.core.api.Facility)13 GroupsManagerBl (cz.metacentrum.perun.core.bl.GroupsManagerBl)11 User (cz.metacentrum.perun.core.api.User)9 ArrayList (java.util.ArrayList)9 ResourcesManagerBl (cz.metacentrum.perun.core.bl.ResourcesManagerBl)8 ModulesUtilsBl (cz.metacentrum.perun.core.bl.ModulesUtilsBl)6 UsersManagerBl (cz.metacentrum.perun.core.bl.UsersManagerBl)6 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)4 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)4 Group (cz.metacentrum.perun.core.api.Group)3 FacilitiesManagerBl (cz.metacentrum.perun.core.bl.FacilitiesManagerBl)3 AttributeChangedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser)2