Search in sources :

Example 41 with AttributesManagerBl

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

the class urn_perun_entityless_attribute_def_def_namespace_maxUIDTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_entityless_attribute_def_def_namespace_maxUID();
    session = mock(PerunSessionImpl.class);
    attributeToCheck = new Attribute(classInstance.getAttributeDefinition());
    reqAttribute = new Attribute(classInstance.getAttributeDefinition());
    PerunBl perunBl = mock(PerunBl.class);
    when(session.getPerunBl()).thenReturn(perunBl);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(session, key, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-minUID")).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 42 with AttributesManagerBl

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

the class urn_perun_facility_attribute_def_def_googleGroupsDomainTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_facility_attribute_def_def_googleGroupsDomain();
    session = mock(PerunSessionImpl.class);
    facility = new Facility();
    attributeToCheck = new Attribute();
    reqAttribute = new Attribute();
    PerunBl perunBl = mock(PerunBl.class);
    when(session.getPerunBl()).thenReturn(perunBl);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) 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 43 with AttributesManagerBl

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

the class urn_perun_group_attribute_def_def_synchronizationEnabledTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_group_attribute_def_def_synchronizationEnabled();
    attributeToCheck = new Attribute(classInstance.getAttributeDefinition());
    reqAttribute = new Attribute(classInstance.getAttributeDefinition());
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class);
    when(sess.getPerunBl().getGroupsManagerBl()).thenReturn(groupsManagerBl);
    when(sess.getPerunBl().getGroupsManagerBl().isGroupSynchronizedFromExternallSource(sess, group)).thenReturn(false);
    AttributesManagerBl attributesManagerBl;
    attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPMEMBERSQUERY_ATTRNAME)).thenReturn(reqAttribute);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME)).thenReturn(reqAttribute);
}
Also used : GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) 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 44 with AttributesManagerBl

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

the class UsersManagerBlImpl method setCandidateAttributes.

/**
 * For given user, set user attributes from given candidate.
 * Can set only user-def and user-opt attributes.
 *
 * @param sess session
 * @param user user
 * @param candidate candidate to take attributes
 * @throws AttributeNotExistsException if some of the given attributes dont exist
 * @throws WrongAttributeAssignmentException if some of the given attributes have unsupported namespace
 * @throws WrongReferenceAttributeValueException if some of the given attribute value cannot be set because of
 *                                               some other attribute constraint
 * @throws WrongAttributeValueException if some of the given attribute value is invalid
 */
private void setCandidateAttributes(PerunSession sess, User user, Candidate candidate) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, AttributeNotExistsException {
    if (candidate.getAttributes() == null) {
        return;
    }
    List<Attribute> attributesToSet = new ArrayList<>();
    AttributesManagerBl attrsManager = perunBl.getAttributesManagerBl();
    for (String attributeName : candidate.getAttributes().keySet()) {
        if (!attributeName.startsWith(AttributesManager.NS_USER_ATTR_DEF) && !attributeName.startsWith(AttributesManager.NS_USER_ATTR_OPT)) {
            throw new WrongAttributeAssignmentException("Cannot set non-(user DEF/OPT) attribute: " + attributeName);
        }
        AttributeDefinition definition = attrsManager.getAttributeDefinition(sess, attributeName);
        Attribute attribute = new Attribute(definition);
        attribute.setValue(attrsManager.stringToAttributeValue(candidate.getAttributes().get(attributeName), attribute.getType()));
        attributesToSet.add(attribute);
    }
    attrsManager.setAttributes(sess, user, attributesToSet);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

Example 45 with AttributesManagerBl

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

the class ResourcesManagerBlImpl method fillAndSetRequiredAttributesForGroups.

/**
 * Fill and set group and group-resource attributes required by given services
 * for all groups which are assigned to the given resource.
 *
 * @param sess session
 * @param services services of which required attributes are set
 * @param resource resource
 * @throws GroupResourceMismatchException GroupResourceMismatchException
 * @throws WrongAttributeAssignmentException WrongAttributeAssignmentException
 * @throws WrongAttributeValueException WrongAttributeValueException
 * @throws WrongReferenceAttributeValueException WrongReferenceAttributeValueException
 */
public void fillAndSetRequiredAttributesForGroups(PerunSession sess, List<Service> services, Resource resource) throws GroupResourceMismatchException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    AttributesManagerBl attributesManagerBl = getPerunBl().getAttributesManagerBl();
    List<Group> groups = getAssignedGroups(sess, resource);
    for (Group group : groups) {
        List<Attribute> attributes;
        attributes = attributesManagerBl.getRequiredAttributes(sess, services, resource, group, true);
        attributes = attributesManagerBl.fillAttributes(sess, resource, group, attributes, true);
        attributesManagerBl.setAttributes(sess, resource, group, attributes, true);
    }
}
Also used : AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) Group(cz.metacentrum.perun.core.api.Group) ResourceSelfServiceAddedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup) ResourceSelfServiceRemovedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

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