use of org.apache.syncope.core.persistence.api.entity.resource.Provision in project syncope by apache.
the class AbstractPropagationTaskExecutor method getRemoteObject.
/**
* Get remote object for given task.
*
* @param connector connector facade proxy.
* @param task current propagation task.
* @param provision provision
* @param latest 'FALSE' to retrieve object using old connObjectKey if not null.
* @return remote connector object.
*/
protected ConnectorObject getRemoteObject(final PropagationTask task, final Connector connector, final Provision provision, final boolean latest) {
String connObjectKey = latest || task.getOldConnObjectKey() == null ? task.getConnObjectKey() : task.getOldConnObjectKey();
Set<MappingItem> linkingMappingItems = virSchemaDAO.findByProvision(provision).stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet());
ConnectorObject obj = null;
Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
if (connObjectKeyItem.isPresent()) {
try {
obj = connector.getObject(new ObjectClass(task.getObjectClassName()), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey), MappingUtils.buildOperationOptions(new IteratorChain<>(MappingUtils.getPropagationItems(provision.getMapping().getItems()).iterator(), linkingMappingItems.iterator())));
for (MappingItem item : linkingMappingItems) {
Attribute attr = obj.getAttributeByName(item.getExtAttrName());
if (attr == null) {
virAttrCache.expire(task.getAnyType(), task.getEntityKey(), item.getIntAttrName());
} else {
VirAttrCacheValue cacheValue = new VirAttrCacheValue();
cacheValue.setValues(attr.getValue());
virAttrCache.put(task.getAnyType(), task.getEntityKey(), item.getIntAttrName(), cacheValue);
}
}
} catch (TimeoutException toe) {
LOG.debug("Request timeout", toe);
throw toe;
} catch (RuntimeException ignore) {
LOG.debug("While resolving {}", connObjectKey, ignore);
}
}
return obj;
}
use of org.apache.syncope.core.persistence.api.entity.resource.Provision in project syncope by apache.
the class ResourceTest method emptyMapping.
@Test
public void emptyMapping() {
ExternalResource ldap = resourceDAO.find("resource-ldap");
assertNotNull(ldap);
assertNotNull(ldap.getProvision(anyTypeDAO.findUser()).get().getMapping());
assertNotNull(ldap.getProvision(anyTypeDAO.findGroup()).get().getMapping());
// need to avoid any class not defined in this Maven module
ldap.getPropagationActions().clear();
List<? extends MappingItem> items = ldap.getProvision(anyTypeDAO.findGroup()).get().getMapping().getItems();
assertNotNull(items);
assertFalse(items.isEmpty());
List<String> itemKeys = items.stream().map(Entity::getKey).collect(Collectors.toList());
Provision groupProvision = ldap.getProvision(anyTypeDAO.findGroup()).get();
virSchemaDAO.findByProvision(groupProvision).forEach(schema -> virSchemaDAO.delete(schema.getKey()));
ldap.getProvisions().remove(groupProvision);
resourceDAO.save(ldap);
resourceDAO.flush();
itemKeys.forEach(itemKey -> assertNull(entityManager().find(JPAMappingItem.class, itemKey)));
}
use of org.apache.syncope.core.persistence.api.entity.resource.Provision in project syncope by apache.
the class ResourceTest method save.
@Test
public void save() {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("ws-target-resource-save");
// specify the connector
ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
resource.setConnector(connector);
Provision provision = entityFactory.newEntity(Provision.class);
provision.setAnyType(anyTypeDAO.findUser());
provision.setObjectClass(ObjectClass.ACCOUNT);
provision.setResource(resource);
resource.add(provision);
Mapping mapping = entityFactory.newEntity(Mapping.class);
mapping.setProvision(provision);
provision.setMapping(mapping);
// specify mappings
for (int i = 0; i < 3; i++) {
MappingItem item = entityFactory.newEntity(MappingItem.class);
item.setExtAttrName("test" + i);
item.setIntAttrName("nonexistent" + i);
item.setMandatoryCondition("false");
item.setPurpose(MappingPurpose.PULL);
mapping.add(item);
item.setMapping(mapping);
}
MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
connObjectKey.setExtAttrName("username");
connObjectKey.setIntAttrName("username");
connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
mapping.setConnObjectKeyItem(connObjectKey);
connObjectKey.setMapping(mapping);
// map a derived attribute
MappingItem derived = entityFactory.newEntity(MappingItem.class);
derived.setConnObjectKey(false);
derived.setExtAttrName("fullname");
derived.setIntAttrName("cn");
derived.setPurpose(MappingPurpose.PROPAGATION);
mapping.add(derived);
derived.setMapping(mapping);
// save the resource
ExternalResource actual = resourceDAO.save(resource);
assertNotNull(actual);
assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
resourceDAO.flush();
resourceDAO.detach(actual);
connInstanceDAO.detach(connector);
// assign the new resource to an user
User user = userDAO.findByUsername("rossini");
assertNotNull(user);
user.add(actual);
resourceDAO.flush();
// retrieve resource
resource = resourceDAO.find(actual.getKey());
assertNotNull(resource);
resourceDAO.refresh(resource);
// check connector
connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
assertNotNull(connector.getResources());
assertNotNull(resource.getConnector());
assertTrue(resource.getConnector().equals(connector));
// check mappings
List<? extends MappingItem> items = resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems();
assertNotNull(items);
assertEquals(5, items.size());
// check user
user = userDAO.findByUsername("rossini");
assertNotNull(user);
assertNotNull(user.getResources());
assertTrue(user.getResources().contains(actual));
}
use of org.apache.syncope.core.persistence.api.entity.resource.Provision in project syncope by apache.
the class AbstractPullResultHandler method handle.
@Override
public boolean handle(final SyncDelta delta) {
Provision provision = null;
try {
provision = profile.getTask().getResource().getProvision(delta.getObject().getObjectClass()).orElse(null);
if (provision == null) {
throw new JobExecutionException("No provision found on " + profile.getTask().getResource() + " for " + delta.getObject().getObjectClass());
}
doHandle(delta, provision);
executor.reportHandled(delta.getObjectClass(), delta.getObject().getName());
LOG.debug("Successfully handled {}", delta);
if (profile.getTask().getPullMode() != PullMode.INCREMENTAL) {
if (executor.wasInterruptRequested()) {
LOG.debug("Pull interrupted");
executor.setInterrupted();
return false;
}
return true;
}
boolean shouldContinue;
synchronized (this) {
shouldContinue = latestResult == Result.SUCCESS;
this.latestResult = null;
}
if (shouldContinue) {
executor.setLatestSyncToken(delta.getObjectClass(), delta.getToken());
}
if (executor.wasInterruptRequested()) {
LOG.debug("Pull interrupted");
executor.setInterrupted();
return false;
}
return shouldContinue;
} catch (IgnoreProvisionException e) {
ProvisioningReport ignoreResult = new ProvisioningReport();
ignoreResult.setOperation(ResourceOperation.NONE);
ignoreResult.setAnyType(provision == null ? getAnyUtils().getAnyTypeKind().name() : provision.getAnyType().getKey());
ignoreResult.setStatus(ProvisioningReport.Status.IGNORE);
ignoreResult.setKey(null);
ignoreResult.setName(delta.getObject().getName().getNameValue());
profile.getResults().add(ignoreResult);
LOG.warn("Ignoring during pull", e);
executor.setLatestSyncToken(delta.getObjectClass(), delta.getToken());
executor.reportHandled(delta.getObjectClass(), delta.getObject().getName());
return true;
} catch (JobExecutionException e) {
LOG.error("Pull failed", e);
return false;
}
}
use of org.apache.syncope.core.persistence.api.entity.resource.Provision in project syncope by apache.
the class PushJobDelegate method doExecuteProvisioning.
@Override
protected String doExecuteProvisioning(final PushTask pushTask, final Connector connector, final boolean dryRun) throws JobExecutionException {
LOG.debug("Executing push on {}", pushTask.getResource());
List<PushActions> actions = new ArrayList<>();
pushTask.getActions().forEach(impl -> {
try {
actions.add(ImplementationManager.build(impl));
} catch (Exception e) {
LOG.warn("While building {}", impl, e);
}
});
profile = new ProvisioningProfile<>(connector, pushTask);
profile.getActions().addAll(actions);
profile.setDryRun(dryRun);
profile.setResAct(null);
if (!profile.isDryRun()) {
for (PushActions action : actions) {
action.beforeAll(profile);
}
}
status.set("Initialization completed");
// First realms...
if (pushTask.getResource().getOrgUnit() != null) {
status.set("Pushing realms");
rhandler = buildRealmHandler();
for (Realm realm : realmDAO.findDescendants(profile.getTask().getSourceRealm())) {
// Never push the root realm
if (realm.getParent() != null) {
try {
rhandler.handle(realm.getKey());
reportHandled(SyncopeConstants.REALM_ANYTYPE, realm.getName());
} catch (Exception e) {
LOG.warn("Failure pushing '{}' on '{}'", realm, pushTask.getResource(), e);
throw new JobExecutionException("While pushing " + realm + " on " + pushTask.getResource(), e);
}
}
}
}
// ...then provisions for any types
ahandler = buildAnyObjectHandler();
uhandler = buildUserHandler();
ghandler = buildGroupHandler();
for (Provision provision : pushTask.getResource().getProvisions()) {
if (provision.getMapping() != null) {
status.set("Pushing " + provision.getAnyType().getKey());
AnyDAO<?> anyDAO = getAnyDAO(provision.getAnyType().getKind());
SyncopePushResultHandler handler;
switch(provision.getAnyType().getKind()) {
case USER:
handler = uhandler;
break;
case GROUP:
handler = ghandler;
break;
case ANY_OBJECT:
default:
handler = ahandler;
}
Optional<? extends PushTaskAnyFilter> anyFilter = pushTask.getFilter(provision.getAnyType());
String filter = anyFilter.isPresent() ? anyFilter.get().getFIQLCond() : null;
SearchCond cond = StringUtils.isBlank(filter) ? anyDAO.getAllMatchingCond() : SearchCondConverter.convert(filter);
int count = searchDAO.count(Collections.singleton(profile.getTask().getSourceRealm().getFullPath()), cond, provision.getAnyType().getKind());
for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1 && !interrupt; page++) {
List<? extends Any<?>> anys = searchDAO.search(Collections.singleton(profile.getTask().getSourceRealm().getFullPath()), cond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), provision.getAnyType().getKind());
doHandle(anys, handler, pushTask.getResource());
}
}
}
if (!profile.isDryRun() && !interrupt) {
for (PushActions action : actions) {
action.afterAll(profile);
}
}
if (interrupt) {
interrupted = true;
}
status.set("Push done");
String result = createReport(profile.getResults(), pushTask.getResource(), dryRun);
LOG.debug("Push result: {}", result);
return result;
}
Aggregations