Search in sources :

Example 26 with AttributesManagerBl

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

the class urn_perun_group_attribute_def_def_groupStructureSynchronizationEnabled method changedAttributeHook.

@Override
public void changedAttributeHook(PerunSessionImpl session, Group group, Attribute attribute) {
    if (attribute.getValue() == null) {
        try {
            AttributesManagerBl attributesManager = session.getPerunBl().getAttributesManagerBl();
            AttributeDefinition removeAttrDef = attributesManager.getAttributeDefinition(session, new urn_perun_group_attribute_def_def_flatGroupStructureEnabled().getAttributeDefinition().getName());
            attributesManager.removeAttributeWithoutCheck(session, group, removeAttrDef);
        } catch (WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        } catch (AttributeNotExistsException ex) {
            log.debug("Attribute for flat group structure synchronization does not exist", ex);
        }
    }
}
Also used : WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

Example 27 with AttributesManagerBl

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

the class UserVirtualAttributeCollectedFromUserExtSource method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition destinationAttributeDefinition) {
    T ctx = initModifyValueContext(sess, user, destinationAttributeDefinition);
    Attribute destinationAttribute = new Attribute(destinationAttributeDefinition);
    // for values use set because of avoiding duplicities
    Set<String> valuesWithoutDuplicities = new HashSet<>();
    String sourceAttributeFriendlyName = getSourceAttributeFriendlyName();
    List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
    AttributesManagerBl am = sess.getPerunBl().getAttributesManagerBl();
    for (UserExtSource userExtSource : userExtSources) {
        try {
            String sourceAttributeName = getSourceAttributeName();
            Attribute a = am.getAttribute(sess, userExtSource, sourceAttributeName);
            Object value = a.getValue();
            if (value != null && value instanceof String) {
                // Apache mod_shib joins multiple values with ';', split them again
                String[] rawValues = ((String) value).split(";");
                // add non-null values returned by modifyValue()
                Arrays.stream(rawValues).map(v -> modifyValue(sess, ctx, userExtSource, v)).filter(Objects::nonNull).forEachOrdered(valuesWithoutDuplicities::add);
            } else if (value != null && value instanceof ArrayList) {
                // If values are already separated to list of strings
                a.valueAsList().stream().map(v -> modifyValue(sess, ctx, userExtSource, v)).filter(Objects::nonNull).forEachOrdered(valuesWithoutDuplicities::add);
            }
        } catch (WrongAttributeAssignmentException | AttributeNotExistsException e) {
            log.error("cannot read " + sourceAttributeFriendlyName + " from userExtSource " + userExtSource.getId() + " of user " + user.getId(), e);
        }
    }
    // convert set to list (values in list will be without duplicities)
    destinationAttribute.setValue(new ArrayList<>(valuesWithoutDuplicities));
    return destinationAttribute;
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) AttributeRemovedForUes(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUes) AttributeSetForUes(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUes) LoggerFactory(org.slf4j.LoggerFactory) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AllAttributesRemovedForUserExtSource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUserExtSource) Attribute(cz.metacentrum.perun.core.api.Attribute) Logger(org.slf4j.Logger) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Set(java.util.Set) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) User(cz.metacentrum.perun.core.api.User) Objects(java.util.Objects) List(java.util.List) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) AllAttributesRemovedForUserExtSource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Objects(java.util.Objects) HashSet(java.util.HashSet) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

Example 28 with AttributesManagerBl

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

the class UsersManagerBlImpl method convertUsersToRichUsersWithAttributesByNames.

@Override
public List<RichUser> convertUsersToRichUsersWithAttributesByNames(PerunSession sess, List<User> users, List<String> attrNames) {
    // TODO - optimzization needed - at least there should be single select on RichUser object in impl !!
    List<RichUser> result = new ArrayList<>();
    AttributesManagerBl attributesManagerBl = this.getPerunBl().getAttributesManagerBl();
    for (User u : users) {
        RichUser ru = new RichUser(u, getUserExtSources(sess, u));
        ru.setUserAttributes(attributesManagerBl.getAttributes(sess, u, attrNames));
        result.add(ru);
    }
    return result;
}
Also used : OwnershipRemovedForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser) User(cz.metacentrum.perun.core.api.User) OwnershipEnabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser) UserAddedToOwnersOfSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser) RichUser(cz.metacentrum.perun.core.api.RichUser) OwnershipDisabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) AllUserExtSourcesDeletedForUser(cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

Example 29 with AttributesManagerBl

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

the class UsersManagerBlImpl method convertUserToRichUserWithAttributesByNames.

@Override
public RichUser convertUserToRichUserWithAttributesByNames(PerunSession sess, User user, List<String> attrNames) {
    AttributesManagerBl attributesManagerBl = this.getPerunBl().getAttributesManagerBl();
    RichUser richUser = new RichUser(user, getUserExtSources(sess, user));
    richUser.setUserAttributes(attributesManagerBl.getAttributes(sess, user, attrNames));
    return richUser;
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

Example 30 with AttributesManagerBl

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

the class ResourcesManagerBlImpl method assignService.

public void assignService(PerunSession sess, Resource resource, Service service) throws InternalErrorException, ServiceNotExistsException, ServiceAlreadyAssignedException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    getResourcesManagerImpl().assignService(sess, resource, service);
    getPerunBl().getAuditer().log(sess, "{} asigned to {}", service, resource);
    AttributesManagerBl attributesManagerBl = getPerunBl().getAttributesManagerBl();
    try {
        //group and group-resource
        List<Group> groups = getAssignedGroups(sess, resource);
        for (Group group : groups) {
            List<Attribute> attributes;
            attributes = attributesManagerBl.getRequiredAttributes(sess, service, resource, group, true);
            attributes = attributesManagerBl.fillAttributes(sess, resource, group, attributes, true);
            attributesManagerBl.setAttributes(sess, resource, group, attributes, true);
        }
        // call check of facility's resource's member's user's attributes
        Facility facility = getFacility(sess, resource);
        attributesManagerBl.checkAttributesValue(sess, facility, attributesManagerBl.getRequiredAttributes(sess, facility));
        attributesManagerBl.checkAttributesValue(sess, resource, attributesManagerBl.getRequiredAttributes(sess, resource));
        List<Member> members = getAllowedMembers(sess, resource);
        for (Member member : members) {
            User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
            // use complex method for getting and setting member-resource, member, user-facility and user-facility required attributes for the service
            getPerunBl().getAttributesManagerBl().setRequiredAttributes(sess, service, facility, resource, user, member);
        }
    } catch (WrongAttributeAssignmentException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
}
Also used : 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