Search in sources :

Example 1 with PerunAttribute

use of cz.metacentrum.perun.ldapc.model.PerunAttribute 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 2 with PerunAttribute

use of cz.metacentrum.perun.ldapc.model.PerunAttribute in project perun by CESNET.

the class AbstractPerunEntry method modifyEntry.

@Override
public void modifyEntry(T bean, AttributeDefinition attr) {
    DirContextOperations entry = findByDN(buildDN(bean));
    List<PerunAttribute<T>> attrDefs = findAttributeDescriptionsByPerunAttr(getAttributeDescriptions(), attr);
    if (attrDefs.isEmpty()) {
        // this is not exceptional situation
        // throw new InternalErrorException("Attribute description for attribute " + attr.getName() + " not found");
        log.info("Attribute description for attribute {} not found, not modifying entry.", attr.getName());
        return;
    }
    for (PerunAttribute<T> attrDef : attrDefs) {
        mapToContext(bean, entry, attrDef, attr);
    }
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) PerunAttribute(cz.metacentrum.perun.ldapc.model.PerunAttribute)

Example 3 with PerunAttribute

use of cz.metacentrum.perun.ldapc.model.PerunAttribute in project perun by CESNET.

the class AbstractPerunEntry method removeAllAttributes.

@Override
public void removeAllAttributes(T bean) {
    DirContextOperations entry = findByDN(buildDN(bean));
    /* we have to find all existing entry attributes to resolve all the present options in names */
    NamingEnumeration<String> attrNames = entry.getAttributes().getIDs();
    while (attrNames.hasMoreElements()) {
        String attrName = attrNames.nextElement();
        Iterable<PerunAttribute<T>> attrDefs = findAttributeDescriptionsByLdapName(getAttributeDescriptions(), Arrays.asList(attrName));
        for (PerunAttribute<T> attrDef : attrDefs) {
            if (attrDef.requiresAttributeBean() && !attrDef.isRequired()) {
                entry.setAttributeValues(attrName, null);
            }
        }
    }
    if (entry.getModificationItems().length > 0) {
        ldapTemplate.modifyAttributes(entry);
    }
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) PerunAttribute(cz.metacentrum.perun.ldapc.model.PerunAttribute)

Example 4 with PerunAttribute

use of cz.metacentrum.perun.ldapc.model.PerunAttribute in project perun by CESNET.

the class AbstractPerunEntry method modifyEntry.

@Override
public void modifyEntry(T bean, Iterable<Pair<PerunAttribute<T>, AttributeDefinition>> attrs) {
    DirContextOperations entry = findByDN(buildDN(bean));
    for (Pair<PerunAttribute<T>, AttributeDefinition> pair : attrs) {
        mapToContext(bean, entry, pair.getLeft(), pair.getRight());
    }
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) PerunAttribute(cz.metacentrum.perun.ldapc.model.PerunAttribute)

Example 5 with PerunAttribute

use of cz.metacentrum.perun.ldapc.model.PerunAttribute in project perun by CESNET.

the class AbstractPerunEntry method beginSynchronizeEntry.

@Override
public SyncOperation beginSynchronizeEntry(T bean, Iterable<Attribute> attrs) {
    DirContextOperations entry;
    boolean newEntry = false;
    try {
        entry = findByDN(buildDN(bean));
    } catch (NameNotFoundException e) {
        newEntry = true;
        entry = new DirContextAdapter(buildDN(bean));
    }
    mapToContext(bean, entry);
    for (Attribute attribute : attrs) {
        for (PerunAttribute<T> attributeDesc : findAttributeDescriptionsByPerunAttr(attributeDescriptions, attribute)) {
            mapToContext(bean, entry, attributeDesc, attribute);
        }
    }
    /*
		if(newEntry) {
			ldapTemplate.bind(entry);
		} else {
			ldapTemplate.modifyAttributes(entry);
		}
		*/
    return new SyncOperationImpl(entry, newEntry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) NameNotFoundException(org.springframework.ldap.NameNotFoundException) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunAttribute(cz.metacentrum.perun.ldapc.model.PerunAttribute) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter)

Aggregations

PerunAttribute (cz.metacentrum.perun.ldapc.model.PerunAttribute)5 DirContextOperations (org.springframework.ldap.core.DirContextOperations)4 Attribute (cz.metacentrum.perun.core.api.Attribute)2 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 Pair (cz.metacentrum.perun.core.api.Pair)1 User (cz.metacentrum.perun.core.api.User)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)1 PerunVirtualAttribute (cz.metacentrum.perun.ldapc.model.PerunVirtualAttribute)1 ArrayList (java.util.ArrayList)1 NameNotFoundException (org.springframework.ldap.NameNotFoundException)1 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)1