use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class TopologyTogglePanel method getResourceFragment.
private Fragment getResourceFragment(final TopologyNode node, final PageReference pageRef) {
Fragment fragment = new Fragment("actions", "resourceActions", this);
AjaxLink<String> delete = new IndicatingOnConfirmAjaxLink<String>("delete", true) {
private static final long serialVersionUID = 3776750333491622263L;
@Override
public void onClick(final AjaxRequestTarget target) {
try {
resourceRestClient.delete(node.getKey());
target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey()));
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
toggle(target, false);
} catch (SyncopeClientException e) {
LOG.error("While deleting resource {}", node.getKey(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
};
MetaDataRoleAuthorizationStrategy.authorize(delete, RENDER, StandardEntitlement.RESOURCE_DELETE);
fragment.add(delete);
AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit") {
private static final long serialVersionUID = 3776750333491622263L;
@Override
public void onClick(final AjaxRequestTarget target) {
ResourceTO resource = resourceRestClient.read(node.getKey());
ConnInstanceTO connInstance = connectorRestClient.read(resource.getConnector());
IModel<ResourceTO> model = new CompoundPropertyModel<>(resource);
modal.setFormModel(model);
target.add(modal.setContent(new ResourceWizardBuilder(resource, pageRef).build(BaseModal.CONTENT_ID, SyncopeConsoleSession.get().owns(StandardEntitlement.RESOURCE_UPDATE, connInstance.getAdminRealm()) ? AjaxWizard.Mode.EDIT : AjaxWizard.Mode.READONLY)));
modal.header(new Model<>(MessageFormat.format(getString("resource.edit"), node.getKey())));
modal.show(true);
}
@Override
public String getAjaxIndicatorMarkupId() {
return Constants.VEIL_INDICATOR_MARKUP_ID;
}
};
MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.RESOURCE_READ);
fragment.add(edit);
AjaxLink<String> status = new IndicatingAjaxLink<String>("status") {
private static final long serialVersionUID = 3776750333491622263L;
@Override
public void onClick(final AjaxRequestTarget target) {
ResourceTO modelObject = resourceRestClient.read(node.getKey());
target.add(propTaskModal.setContent(new ResourceStatusModal(propTaskModal, pageRef, modelObject)));
propTaskModal.header(new Model<>(MessageFormat.format(getString("resource.provisioning.status"), node.getKey())));
propTaskModal.show(true);
}
@Override
public String getAjaxIndicatorMarkupId() {
return Constants.VEIL_INDICATOR_MARKUP_ID;
}
};
MetaDataRoleAuthorizationStrategy.authorize(status, RENDER, StandardEntitlement.USER_UPDATE);
fragment.add(status);
AjaxLink<String> provision = new IndicatingAjaxLink<String>("provision") {
private static final long serialVersionUID = 3776750333491622263L;
@Override
public void onClick(final AjaxRequestTarget target) {
ResourceTO resource = resourceRestClient.read(node.getKey());
ConnInstanceTO connInstance = connectorRestClient.read(resource.getConnector());
if (SyncopeConsoleSession.get().owns(StandardEntitlement.RESOURCE_UPDATE, connInstance.getAdminRealm())) {
provisionModal.addSubmitButton();
} else {
provisionModal.removeSubmitButton();
}
IModel<ResourceTO> model = new CompoundPropertyModel<>(resource);
provisionModal.setFormModel(model);
target.add(provisionModal.setContent(new ResourceProvisionPanel(provisionModal, resource, connInstance.getAdminRealm(), pageRef)));
provisionModal.header(new Model<>(MessageFormat.format(getString("resource.edit"), node.getKey())));
provisionModal.show(true);
}
@Override
public String getAjaxIndicatorMarkupId() {
return Constants.VEIL_INDICATOR_MARKUP_ID;
}
};
MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.RESOURCE_READ);
fragment.add(provision);
AjaxLink<String> explore = new IndicatingAjaxLink<String>("explore") {
private static final long serialVersionUID = 3776750333491622263L;
@Override
public void onClick(final AjaxRequestTarget target) {
ResourceTO resource = resourceRestClient.read(node.getKey());
target.add(propTaskModal.setContent(new ConnObjects(resource, pageRef)));
propTaskModal.header(new StringResourceModel("resource.explore.list", Model.of(node)));
propTaskModal.show(true);
}
@Override
public String getAjaxIndicatorMarkupId() {
return Constants.VEIL_INDICATOR_MARKUP_ID;
}
};
MetaDataRoleAuthorizationStrategy.authorize(explore, RENDER, StandardEntitlement.RESOURCE_LIST_CONNOBJECT);
fragment.add(explore);
AjaxLink<String> propagation = new IndicatingAjaxLink<String>("propagation") {
private static final long serialVersionUID = 3776750333491622263L;
@Override
@SuppressWarnings("unchecked")
public void onClick(final AjaxRequestTarget target) {
target.add(propTaskModal.setContent(new PropagationTasks(propTaskModal, node.getKey(), pageRef)));
propTaskModal.header(new Model<>(MessageFormat.format(getString("task.propagation.list"), node.getKey())));
propTaskModal.show(true);
}
@Override
public String getAjaxIndicatorMarkupId() {
return Constants.VEIL_INDICATOR_MARKUP_ID;
}
};
MetaDataRoleAuthorizationStrategy.authorize(propagation, RENDER, StandardEntitlement.TASK_LIST);
fragment.add(propagation);
AjaxLink<String> pull = new IndicatingAjaxLink<String>("pull") {
private static final long serialVersionUID = 3776750333491622263L;
@Override
public void onClick(final AjaxRequestTarget target) {
target.add(schedTaskModal.setContent(new PullTasks(schedTaskModal, pageRef, node.getKey())));
schedTaskModal.header(new Model<>(MessageFormat.format(getString("task.pull.list"), node.getKey())));
schedTaskModal.show(true);
}
@Override
public String getAjaxIndicatorMarkupId() {
return Constants.VEIL_INDICATOR_MARKUP_ID;
}
};
MetaDataRoleAuthorizationStrategy.authorize(pull, RENDER, StandardEntitlement.TASK_LIST);
fragment.add(pull);
AjaxLink<String> push = new IndicatingAjaxLink<String>("push") {
private static final long serialVersionUID = 3776750333491622263L;
@Override
public void onClick(final AjaxRequestTarget target) {
target.add(schedTaskModal.setContent(new PushTasks(schedTaskModal, pageRef, node.getKey())));
schedTaskModal.header(new Model<>(MessageFormat.format(getString("task.push.list"), node.getKey())));
schedTaskModal.show(true);
}
@Override
public String getAjaxIndicatorMarkupId() {
return Constants.VEIL_INDICATOR_MARKUP_ID;
}
};
MetaDataRoleAuthorizationStrategy.authorize(push, RENDER, StandardEntitlement.TASK_LIST);
fragment.add(push);
AjaxLink<String> history = new IndicatingAjaxLink<String>("history") {
private static final long serialVersionUID = -1876519166660008562L;
@Override
public void onClick(final AjaxRequestTarget target) {
String resourceKey = String.class.cast(node.getKey());
final ResourceTO modelObject = resourceRestClient.read(String.class.cast(node.getKey()));
target.add(historyModal.setContent(new HistoryConfList<>(historyModal, resourceKey, pageRef, modelObject)));
historyModal.header(new Model<>(MessageFormat.format(getString("resource.menu.history"), node.getDisplayName())));
historyModal.show(true);
}
@Override
public String getAjaxIndicatorMarkupId() {
return Constants.VEIL_INDICATOR_MARKUP_ID;
}
};
MetaDataRoleAuthorizationStrategy.authorize(history, RENDER, StandardEntitlement.RESOURCE_HISTORY_LIST);
fragment.add(history);
// [SYNCOPE-1161] - Option to clone a resource
AjaxLink<String> clone = new IndicatingOnConfirmAjaxLink<String>("clone", "confirmClone", true) {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target) {
try {
ResourceTO resource = resourceRestClient.read(node.getKey());
resource.setKey("Copy of " + resource.getKey());
// reset some resource objects keys
if (resource.getOrgUnit() != null) {
resource.getOrgUnit().setKey(null);
for (ItemTO item : resource.getOrgUnit().getItems()) {
item.setKey(null);
}
}
for (ProvisionTO provision : resource.getProvisions()) {
provision.setKey(null);
if (provision.getMapping() != null) {
for (ItemTO item : provision.getMapping().getItems()) {
item.setKey(null);
}
provision.getMapping().getLinkingItems().clear();
}
provision.getVirSchemas().clear();
}
resourceRestClient.create(resource);
// refresh Topology
send(pageRef.getPage(), Broadcast.DEPTH, new AbstractResourceWizardBuilder.CreateEvent(resource.getKey(), resource.getKey(), TopologyNode.Kind.RESOURCE, resource.getConnector(), target));
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
toggle(target, false);
} catch (SyncopeClientException e) {
LOG.error("While cloning resource {}", node.getKey(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
};
MetaDataRoleAuthorizationStrategy.authorize(clone, RENDER, StandardEntitlement.RESOURCE_CREATE);
fragment.add(clone);
return fragment;
}
use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class ResourceDataBinderImpl method getResourceTO.
@Override
public ResourceTO getResourceTO(final ExternalResource resource) {
ResourceTO resourceTO = new ResourceTO();
// set the resource name
resourceTO.setKey(resource.getKey());
// set the connector instance
ConnInstance connector = resource.getConnector();
resourceTO.setConnector(connector == null ? null : connector.getKey());
resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());
// set the provision information
resource.getProvisions().stream().map(provision -> {
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setKey(provision.getKey());
provisionTO.setAnyType(provision.getAnyType().getKey());
provisionTO.setObjectClass(provision.getObjectClass().getObjectClassValue());
provisionTO.getAuxClasses().addAll(provision.getAuxClasses().stream().map(cls -> cls.getKey()).collect(Collectors.toList()));
provisionTO.setSyncToken(provision.getSerializedSyncToken());
if (provision.getMapping() != null) {
MappingTO mappingTO = new MappingTO();
provisionTO.setMapping(mappingTO);
mappingTO.setConnObjectLink(provision.getMapping().getConnObjectLink());
populateItems(provision.getMapping().getItems(), mappingTO);
}
virSchemaDAO.findByProvision(provision).forEach(virSchema -> {
provisionTO.getVirSchemas().add(virSchema.getKey());
MappingItem linkingMappingItem = virSchema.asLinkingMappingItem();
ItemTO itemTO = new ItemTO();
itemTO.setKey(linkingMappingItem.getKey());
BeanUtils.copyProperties(linkingMappingItem, itemTO, ITEM_IGNORE_PROPERTIES);
provisionTO.getMapping().getLinkingItems().add(itemTO);
});
return provisionTO;
}).forEachOrdered(provisionTO -> {
resourceTO.getProvisions().add(provisionTO);
});
if (resource.getOrgUnit() != null) {
OrgUnit orgUnit = resource.getOrgUnit();
OrgUnitTO orgUnitTO = new OrgUnitTO();
orgUnitTO.setKey(orgUnit.getKey());
orgUnitTO.setObjectClass(orgUnit.getObjectClass().getObjectClassValue());
orgUnitTO.setSyncToken(orgUnit.getSerializedSyncToken());
orgUnitTO.setConnObjectLink(orgUnit.getConnObjectLink());
populateItems(orgUnit.getItems(), orgUnitTO);
resourceTO.setOrgUnit(orgUnitTO);
}
resourceTO.setEnforceMandatoryCondition(resource.isEnforceMandatoryCondition());
resourceTO.setPropagationPriority(resource.getPropagationPriority());
resourceTO.setRandomPwdIfNotProvided(resource.isRandomPwdIfNotProvided());
resourceTO.setCreateTraceLevel(resource.getCreateTraceLevel());
resourceTO.setUpdateTraceLevel(resource.getUpdateTraceLevel());
resourceTO.setDeleteTraceLevel(resource.getDeleteTraceLevel());
resourceTO.setProvisioningTraceLevel(resource.getProvisioningTraceLevel());
resourceTO.setPasswordPolicy(resource.getPasswordPolicy() == null ? null : resource.getPasswordPolicy().getKey());
resourceTO.setAccountPolicy(resource.getAccountPolicy() == null ? null : resource.getAccountPolicy().getKey());
resourceTO.setPullPolicy(resource.getPullPolicy() == null ? null : resource.getPullPolicy().getKey());
resourceTO.getConfOverride().addAll(resource.getConfOverride());
Collections.sort(resourceTO.getConfOverride());
resourceTO.setOverrideCapabilities(resource.isOverrideCapabilities());
resourceTO.getCapabilitiesOverride().addAll(resource.getCapabilitiesOverride());
resourceTO.getPropagationActions().addAll(resource.getPropagationActions().stream().map(Entity::getKey).collect(Collectors.toList()));
return resourceTO;
}
use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class MultitenancyITCase method createResourceAndPull.
@Test
public void createResourceAndPull() {
// read connector
ConnInstanceTO conn = adminClient.getService(ConnectorService.class).read("b7ea96c3-c633-488b-98a0-b52ac35850f7", Locale.ENGLISH.getLanguage());
assertNotNull(conn);
assertEquals("LDAP", conn.getDisplayName());
// prepare resource
ResourceTO resource = new ResourceTO();
resource.setKey("new-ldap-resource");
resource.setConnector(conn.getKey());
try {
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resource.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
mapping.setConnObjectLink("'uid=' + username + ',ou=people,o=isp'");
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("username");
item.setExtAttrName("cn");
item.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(item);
item = new ItemTO();
item.setPassword(true);
item.setIntAttrName("password");
item.setExtAttrName("userPassword");
item.setPurpose(MappingPurpose.BOTH);
item.setMandatoryCondition("true");
mapping.add(item);
item = new ItemTO();
item.setIntAttrName("key");
item.setPurpose(MappingPurpose.BOTH);
item.setExtAttrName("sn");
item.setMandatoryCondition("true");
mapping.add(item);
item = new ItemTO();
item.setIntAttrName("email");
item.setPurpose(MappingPurpose.BOTH);
item.setExtAttrName("mail");
mapping.add(item);
// create resource
Response response = adminClient.getService(ResourceService.class).create(resource);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
resource = adminClient.getService(ResourceService.class).read(resource.getKey());
assertNotNull(resource);
// create pull task
PullTaskTO task = new PullTaskTO();
task.setName("LDAP Pull Task");
task.setActive(true);
task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
task.setResource(resource.getKey());
task.setPullMode(PullMode.FULL_RECONCILIATION);
task.setPerformCreate(true);
response = adminClient.getService(TaskService.class).create(TaskType.PULL, task);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
task = adminClient.getService(TaskService.class).read(TaskType.PULL, StringUtils.substringAfterLast(response.getLocation().toASCIIString(), "/"), true);
assertNotNull(resource);
// pull
ExecTO execution = AbstractTaskITCase.execProvisioningTask(adminClient.getService(TaskService.class), TaskType.PULL, task.getKey(), 50, false);
// verify execution status
String status = execution.getStatus();
assertNotNull(status);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(status));
// verify that pulled user is found
PagedResult<UserTO> matchingUsers = adminClient.getService(UserService.class).search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
assertNotNull(matchingUsers);
assertEquals(1, matchingUsers.getResult().size());
} finally {
adminClient.getService(ResourceService.class).delete(resource.getKey());
}
}
use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class PropagationTaskITCase method propagationJEXLTransformer.
@Test
public void propagationJEXLTransformer() {
// 0. Set propagation JEXL MappingItemTransformer
ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
ResourceTO originalResource = SerializationUtils.clone(resource);
ProvisionTO provision = resource.getProvision("PRINTER").get();
assertNotNull(provision);
Optional<ItemTO> mappingItem = provision.getMapping().getItems().stream().filter(item -> "location".equals(item.getIntAttrName())).findFirst();
assertTrue(mappingItem.isPresent());
assertTrue(mappingItem.get().getTransformers().isEmpty());
String suffix = getUUIDString();
mappingItem.get().setPropagationJEXLTransformer("value + '" + suffix + "'");
try {
resourceService.update(resource);
// 1. create printer on external resource
AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("propagationJEXLTransformer");
String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
assertFalse(originalLocation.endsWith(suffix));
anyObjectTO = createAnyObject(anyObjectTO).getEntity();
assertNotNull(anyObjectTO);
// 2. verify that JEXL MappingItemTransformer was applied during propagation
// (location ends with given suffix on external resource)
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).endsWith(suffix));
assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).endsWith(suffix));
} finally {
resourceService.update(originalResource);
}
}
use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class PullTaskITCase method reconcileFromScriptedSQL.
@Test
public void reconcileFromScriptedSQL() throws IOException {
// 0. reset sync token and set MappingItemTransformer
ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
ResourceTO originalResource = SerializationUtils.clone(resource);
ProvisionTO provision = resource.getProvision("PRINTER").get();
assertNotNull(provision);
ItemTO mappingItem = provision.getMapping().getItems().stream().filter(object -> "location".equals(object.getIntAttrName())).findFirst().get();
assertNotNull(mappingItem);
final String prefix = "PREFIX_";
ImplementationTO transformer = new ImplementationTO();
transformer.setKey("PrefixItemTransformer");
transformer.setEngine(ImplementationEngine.GROOVY);
transformer.setType(ImplementationType.ITEM_TRANSFORMER);
transformer.setBody(IOUtils.toString(getClass().getResourceAsStream("/PrefixItemTransformer.groovy"), StandardCharsets.UTF_8));
Response response = implementationService.create(transformer);
transformer = implementationService.read(transformer.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(transformer);
mappingItem.getTransformers().clear();
mappingItem.getTransformers().add(transformer.getKey());
try {
resourceService.update(resource);
resourceService.removeSyncToken(resource.getKey(), provision.getAnyType());
// insert a deleted record in the external resource (SYNCOPE-923), which will be returned
// as sync event prior to the CREATE_OR_UPDATE events generated by the actions below (before pull)
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
jdbcTemplate.update("INSERT INTO TESTPRINTER (id, printername, location, deleted, lastmodification) VALUES (?,?,?,?,?)", UUID.randomUUID().toString(), "Mysterious Printer", "Nowhere", true, new Date());
// 1. create printer on external resource
AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("pull");
String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
assertFalse(originalLocation.startsWith(prefix));
anyObjectTO = createAnyObject(anyObjectTO).getEntity();
assertNotNull(anyObjectTO);
// 2. verify that PrefixMappingItemTransformer was applied during propagation
// (location starts with given prefix on external resource)
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).startsWith(prefix));
assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).startsWith(prefix));
// 3. unlink any existing printer and delete from Syncope (printer is now only on external resource)
PagedResult<AnyObjectTO> matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
assertTrue(matchingPrinters.getSize() > 0);
for (AnyObjectTO printer : matchingPrinters.getResult()) {
anyObjectService.deassociate(new DeassociationPatch.Builder().key(printer.getKey()).action(ResourceDeassociationAction.UNLINK).resource(RESOURCE_NAME_DBSCRIPTED).build());
anyObjectService.delete(printer.getKey());
}
// ensure that the pull task does not have the DELETE capability (SYNCOPE-923)
PullTaskTO pullTask = taskService.read(TaskType.PULL, "30cfd653-257b-495f-8665-281281dbcb3d", false);
assertNotNull(pullTask);
assertFalse(pullTask.isPerformDelete());
// 4. pull
execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
// 5. verify that printer was re-created in Syncope (implies that location does not start with given prefix,
// hence PrefixItemTransformer was applied during pull)
matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
assertTrue(matchingPrinters.getSize() > 0);
// 6. verify that synctoken was updated
assertNotNull(resourceService.read(RESOURCE_NAME_DBSCRIPTED).getProvision(anyObjectTO.getType()).get().getSyncToken());
} finally {
resourceService.update(originalResource);
}
}
Aggregations