use of org.apache.syncope.core.provisioning.api.Connector in project syncope by apache.
the class LDAPMembershipPullActions method populateMemberships.
/**
* Pull Syncope memberships with the situation read on the external resource's group.
*
* @param profile pull profile
* @param delta representing the pullong group
* @param groupTO group after modification performed by the handler
* @throws JobExecutionException if anything goes wrong
*/
protected void populateMemberships(final ProvisioningProfile<?, ?> profile, final SyncDelta delta, final GroupTO groupTO) throws JobExecutionException {
Connector connector = profile.getConnector();
getMembAttrValues(delta, connector).stream().map(membValue -> {
Set<String> memb = memberships.get(membValue.toString());
if (memb == null) {
memb = new HashSet<>();
memberships.put(membValue.toString(), memb);
}
return memb;
}).forEachOrdered(memb -> {
memb.add(groupTO.getKey());
});
}
use of org.apache.syncope.core.provisioning.api.Connector in project syncope by apache.
the class VirAttrHandlerImpl method getValues.
private Map<VirSchema, List<String>> getValues(final Any<?> any, final Set<VirSchema> schemas) {
Set<ExternalResource> ownedResources = anyUtilsFactory.getInstance(any).getAllResources(any);
Map<VirSchema, List<String>> result = new HashMap<>();
Map<Provision, Set<VirSchema>> toRead = new HashMap<>();
for (VirSchema schema : schemas) {
if (ownedResources.contains(schema.getProvision().getResource())) {
VirAttrCacheValue virAttrCacheValue = virAttrCache.get(any.getType().getKey(), any.getKey(), schema.getKey());
if (virAttrCache.isValidEntry(virAttrCacheValue)) {
LOG.debug("Values for {} found in cache: {}", schema, virAttrCacheValue);
result.put(schema, virAttrCacheValue.getValues());
} else {
Set<VirSchema> schemasToRead = toRead.get(schema.getProvision());
if (schemasToRead == null) {
schemasToRead = new HashSet<>();
toRead.put(schema.getProvision(), schemasToRead);
}
schemasToRead.add(schema);
}
} else {
LOG.debug("Not considering {} since {} is not assigned to {}", schema, any, schema.getProvision().getResource());
}
}
for (Map.Entry<Provision, Set<VirSchema>> entry : toRead.entrySet()) {
LOG.debug("About to read from {}: {}", entry.getKey(), entry.getValue());
Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(entry.getKey());
String connObjectKeyValue = connObjectKeyItem.isPresent() ? mappingManager.getConnObjectKeyValue(any, entry.getKey()).orElse(null) : null;
if (!connObjectKeyItem.isPresent() || connObjectKeyValue == null) {
LOG.error("No ConnObjectKey or value found for {}, ignoring...", entry.getKey());
} else {
Set<MappingItem> linkingMappingItems = new HashSet<>();
linkingMappingItems.add(connObjectKeyItem.get());
linkingMappingItems.addAll(entry.getValue().stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet()));
Connector connector = connFactory.getConnector(entry.getKey().getResource());
try {
ConnectorObject connectorObject = connector.getObject(entry.getKey().getObjectClass(), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue), MappingUtils.buildOperationOptions(linkingMappingItems.iterator()));
if (connectorObject == null) {
LOG.debug("No read from {} with filter '{} == {}'", entry.getKey(), connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue);
} else {
entry.getValue().forEach(schema -> {
Attribute attr = connectorObject.getAttributeByName(schema.getExtAttrName());
if (attr != null) {
VirAttrCacheValue virAttrCacheValue = new VirAttrCacheValue();
virAttrCacheValue.setValues(attr.getValue());
virAttrCache.put(any.getType().getKey(), any.getKey(), schema.getKey(), virAttrCacheValue);
LOG.debug("Values for {} set in cache: {}", schema, virAttrCacheValue);
result.put(schema, virAttrCacheValue.getValues());
}
});
}
} catch (Exception e) {
LOG.error("Error reading from {}", entry.getKey(), e);
}
}
}
return result;
}
Aggregations