use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnectorITCase method authorizations.
@Test
public void authorizations() {
SyncopeClient puccini = clientFactory.create("puccini", ADMIN_PWD);
ConnectorService pcs = puccini.getService(ConnectorService.class);
// 1. list connectors: get only the ones allowed
List<ConnInstanceTO> connInstances = pcs.list(null);
assertEquals(2, connInstances.size());
assertTrue(connInstances.stream().allMatch(connInstance -> "a6d017fd-a705-4507-bb7c-6ab6a6745997".equals(connInstance.getKey()) || "44c02549-19c3-483c-8025-4919c3283c37".equals(connInstance.getKey())));
// 2. attempt to read a connector with a different admin realm: fail
try {
pcs.read("88a7a819-dab5-46b4-9b90-0b9769eabdb8", null);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
}
// 3. read and upate a connector in the realm for which entitlements are owned: succeed
try {
ConnInstanceTO scriptedsql = pcs.read("a6d017fd-a705-4507-bb7c-6ab6a6745997", null);
ConnConfProperty reloadScriptOnExecution = scriptedsql.getConf("reloadScriptOnExecution").get();
assertEquals("true", reloadScriptOnExecution.getValues().get(0).toString());
reloadScriptOnExecution.getValues().set(0, "false");
pcs.update(scriptedsql);
scriptedsql = pcs.read(scriptedsql.getKey(), null);
reloadScriptOnExecution = scriptedsql.getConf("reloadScriptOnExecution").get();
assertEquals("false", reloadScriptOnExecution.getValues().get(0).toString());
} finally {
ConnInstanceTO scriptedsql = connectorService.read("a6d017fd-a705-4507-bb7c-6ab6a6745997", null);
ConnConfProperty reloadScriptOnExecution = scriptedsql.getConf("reloadScriptOnExecution").get();
reloadScriptOnExecution.getValues().set(0, "true");
connectorService.update(scriptedsql);
}
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnectorITCase method createWithException.
@Test
public void createWithException() {
assertThrows(SyncopeClientException.class, () -> {
ConnInstanceTO connectorTO = new ConnInstanceTO();
Response response = connectorService.create(connectorTO);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
}
});
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnectorITCase method buildObjectClassInfo.
@Test
public void buildObjectClassInfo() {
ConnInstanceTO ws = connectorService.read("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08", Locale.ENGLISH.getLanguage());
assertNotNull(ws);
List<ConnIdObjectClassTO> objectClassInfo = connectorService.buildObjectClassInfo(ws, true);
assertNotNull(objectClassInfo);
assertEquals(1, objectClassInfo.size());
assertEquals(ObjectClass.ACCOUNT_NAME, objectClassInfo.get(0).getType());
assertTrue(objectClassInfo.get(0).getAttributes().contains("promoThirdPartyDisclaimer"));
ConnInstanceTO ldap = connectorService.read("74141a3b-0762-4720-a4aa-fc3e374ef3ef", Locale.ENGLISH.getLanguage());
assertNotNull(ldap);
objectClassInfo = connectorService.buildObjectClassInfo(ldap, true);
assertNotNull(objectClassInfo);
Collection<String> objectClasses = objectClassInfo.stream().map(info -> info.getType()).collect(Collectors.toSet());
assertTrue(objectClasses.contains(ObjectClass.ACCOUNT_NAME));
assertTrue(objectClasses.contains(ObjectClass.GROUP_NAME));
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnectorITCase method history.
@Test
public void history() {
List<ConnInstanceHistoryConfTO> history = connectorHistoryService.list("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
assertNotNull(history);
int pre = history.size();
ConnInstanceTO ldapConn = connectorService.read("74141a3b-0762-4720-a4aa-fc3e374ef3ef", null);
String originalDisplayName = ldapConn.getDisplayName();
Set<ConnectorCapability> originalCapabilities = new HashSet<>(ldapConn.getCapabilities());
ConnConfProperty originalConfProp = SerializationUtils.clone(ldapConn.getConf("maintainPosixGroupMembership").get());
assertEquals(1, originalConfProp.getValues().size());
assertEquals("false", originalConfProp.getValues().get(0));
ldapConn.setDisplayName(originalDisplayName + " modified");
ldapConn.getCapabilities().clear();
ldapConn.getConf("maintainPosixGroupMembership").get().getValues().set(0, "true");
connectorService.update(ldapConn);
ldapConn = connectorService.read("74141a3b-0762-4720-a4aa-fc3e374ef3ef", null);
assertNotEquals(originalDisplayName, ldapConn.getDisplayName());
assertNotEquals(originalCapabilities, ldapConn.getCapabilities());
assertNotEquals(originalConfProp, ldapConn.getConf("maintainPosixGroupMembership"));
history = connectorHistoryService.list("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
assertEquals(pre + 1, history.size());
connectorHistoryService.restore(history.get(0).getKey());
ldapConn = connectorService.read("74141a3b-0762-4720-a4aa-fc3e374ef3ef", null);
assertEquals(originalDisplayName, ldapConn.getDisplayName());
assertEquals(originalCapabilities, ldapConn.getCapabilities());
assertEquals(originalConfProp, ldapConn.getConf("maintainPosixGroupMembership").get());
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO 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;
}
Aggregations