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());
}
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations