Search in sources :

Example 66 with PerunBl

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

the class VirtualAttributeEventProcessor method processGroupAttributeChange.

public void processGroupAttributeChange(String msg, MessageBeans beans) {
    // ensure we have the correct beans available
    if (beans.getAttribute() == null || beans.getGroup() == null) {
        return;
    }
    try {
        PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
        /* get list of dependent attributes */
        Collection<PerunVirtualAttribute<User>> attrDefs = dependencyManager.getAttributeDependants(beans.getAttribute().getName());
        log.debug("Processing group {} attribute {} change, affected attributes {}", beans.getGroup(), beans.getAttribute(), attrDefs);
        if (attrDefs != null) {
            /* for each concerned user */
            for (User user : perun.getGroupsManagerBl().getGroupUsers(ldapcManager.getPerunSession(), beans.getGroup())) {
                /* get attribute value for each dependent attribute */
                Collection<Pair<PerunAttribute<User>, AttributeDefinition>> userAttrs = this.getAttributeValues(perun, user, attrDefs);
                log.debug("Modifying user {} entry with the new values {}", user.getId(), userAttrs);
                perunUser.modifyEntry(user, userAttrs);
            }
        }
    } catch (InternalErrorException e) {
        log.error("Error processing group {} attribute {} change: {}", beans.getGroup(), beans.getAttribute(), e.getMessage());
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) PerunVirtualAttribute(cz.metacentrum.perun.ldapc.model.PerunVirtualAttribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Pair(cz.metacentrum.perun.core.api.Pair)

Example 67 with PerunBl

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

the class VirtualAttributeEventProcessor method processGroupAttributeRemoval.

public void processGroupAttributeRemoval(String msg, MessageBeans beans) {
    // ensure we have the correct beans available
    if (beans.getGroup() == null || beans.getAttributeDef() == null) {
        return;
    }
    try {
        PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
        Collection<PerunVirtualAttribute<User>> attrDefs = dependencyManager.getAttributeDependants(beans.getAttributeDef().getName());
        log.debug("Processing group {} attribute {} removal, affected attributes {}", beans.getGroup(), beans.getAttributeDef(), attrDefs);
        if (attrDefs != null) {
            for (User user : perun.getGroupsManagerBl().getGroupUsers(ldapcManager.getPerunSession(), beans.getGroup())) {
                /* get attribute value for each dependent attribute */
                Collection<Pair<PerunAttribute<User>, AttributeDefinition>> userAttrs = this.getAttributeValues(perun, user, attrDefs);
                log.debug("Modifying user {} entry with the new values {}", user.getId(), userAttrs);
                perunUser.modifyEntry(user, userAttrs);
            }
        }
    } catch (InternalErrorException e) {
        log.error("Error processing group {} attribute {} removal: {}", beans.getGroup(), beans.getAttributeDef(), e.getMessage());
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) PerunVirtualAttribute(cz.metacentrum.perun.ldapc.model.PerunVirtualAttribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Pair(cz.metacentrum.perun.core.api.Pair)

Example 68 with PerunBl

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

the class VirtualAttributeEventProcessor method processMemberChange.

public void processMemberChange(String msg, MessageBeans beans) {
    // ensure we have the correct beans available
    if (beans.getMember() == null) {
        return;
    }
    try {
        PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
        User user = perun.getUsersManagerBl().getUserByMember(ldapcManager.getPerunSession(), beans.getMember());
        Collection<PerunVirtualAttribute<User>> attrDefs = dependencyManager.getAllAttributeDependants();
        log.debug("Processing member {} status change with attributes {}", user, attrDefs);
        Collection<Pair<PerunAttribute<User>, AttributeDefinition>> userAttrs = this.getAttributeValues(perun, user, attrDefs);
        log.debug("Modifying user {} entry with the new values {}", user.getId(), userAttrs);
        perunUser.modifyEntry(user, userAttrs);
    } catch (InternalErrorException e) {
        log.error("Error processing member {} status change: {}", beans.getMember(), e.getMessage());
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) PerunVirtualAttribute(cz.metacentrum.perun.ldapc.model.PerunVirtualAttribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Pair(cz.metacentrum.perun.core.api.Pair)

Example 69 with PerunBl

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

the class VirtualAttributeEventProcessor method processGroupMemberChange.

public void processGroupMemberChange(String msg, MessageBeans beans) {
    // ensure we have the correct beans available
    if (beans.getMember() == null || beans.getGroup() == null) {
        return;
    }
    try {
        PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
        User user = perun.getUsersManagerBl().getUserByMember(ldapcManager.getPerunSession(), beans.getMember());
        List<String> registeredAttrs = dependencyManager.getRegisteredAttributes();
        List<Attribute> groupAttrs = perun.getAttributesManagerBl().getAttributes(ldapcManager.getPerunSession(), beans.getGroup(), registeredAttrs);
        log.debug("Processing member {} status change in group {} with attributes {}", user, beans.getGroup(), groupAttrs);
        if (!groupAttrs.isEmpty()) {
            List<PerunVirtualAttribute<User>> attrDefs = new ArrayList<>();
            groupAttrs.forEach(attr -> attrDefs.addAll(dependencyManager.getAttributeDependants(attr.getName())));
            log.debug("Found attributes: {}", attrDefs);
            Collection<Pair<PerunAttribute<User>, AttributeDefinition>> userAttrs = this.getAttributeValues(perun, user, attrDefs);
            log.debug("Modifying user {} entry with the new values {}", user.getId(), userAttrs);
            perunUser.modifyEntry(user, userAttrs);
        }
    } catch (InternalErrorException e) {
        log.error("Error processing member {} change in group {}: {}", beans.getMember(), beans.getGroup(), e.getMessage());
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunAttribute(cz.metacentrum.perun.ldapc.model.PerunAttribute) PerunVirtualAttribute(cz.metacentrum.perun.ldapc.model.PerunVirtualAttribute) PerunVirtualAttribute(cz.metacentrum.perun.ldapc.model.PerunVirtualAttribute) ArrayList(java.util.ArrayList) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Pair(cz.metacentrum.perun.core.api.Pair)

Example 70 with PerunBl

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

the class FacilityAttributeProcessor method processVirtualAttributeChanged.

public void processVirtualAttributeChanged(String msg, MessageBeans beans) {
    PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
    if (beans.getAttribute() == null || beans.getFacility() == null) {
        return;
    }
    try {
        Attribute virtAttr = perun.getAttributesManagerBl().getAttribute(ldapcManager.getPerunSession(), beans.getFacility(), beans.getAttribute().getName());
        log.debug("Changing virtual attribute {} for facility {}", virtAttr, beans.getFacility());
        perunFacility.modifyEntry(beans.getFacility(), virtAttr);
    } catch (InternalErrorException | AttributeNotExistsException | WrongAttributeAssignmentException | NamingException e) {
        log.error("Error changing virtual attribute:", e);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) NamingException(org.springframework.ldap.NamingException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

PerunBl (cz.metacentrum.perun.core.bl.PerunBl)130 Attribute (cz.metacentrum.perun.core.api.Attribute)93 Before (org.junit.Before)65 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)64 AttributesManagerBl (cz.metacentrum.perun.core.bl.AttributesManagerBl)48 User (cz.metacentrum.perun.core.api.User)41 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)37 ArrayList (java.util.ArrayList)22 Vo (cz.metacentrum.perun.core.api.Vo)21 Facility (cz.metacentrum.perun.core.api.Facility)19 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)19 ModulesUtilsBl (cz.metacentrum.perun.core.bl.ModulesUtilsBl)19 ExtSource (cz.metacentrum.perun.core.api.ExtSource)16 Member (cz.metacentrum.perun.core.api.Member)16 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)16 UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)16 UsersManagerBl (cz.metacentrum.perun.core.bl.UsersManagerBl)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 GroupsManagerBl (cz.metacentrum.perun.core.bl.GroupsManagerBl)13 Group (cz.metacentrum.perun.core.api.Group)12