use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE442.
@Test
public void issueSYNCOPE442() {
UserTO userTO = UserITCase.getUniqueSampleTO("syncope442@apache.org");
userTO.getVirAttrs().clear();
AttrTO virAttrTO = new AttrTO();
virAttrTO.setSchema("virtualdata");
virAttrTO.getValues().add("virattrcache");
userTO.getVirAttrs().add(virAttrTO);
userTO.getMemberships().clear();
userTO.getResources().clear();
userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
// 1. create user
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
// 2. check for virtual attribute value
userTO = userService.read(userTO.getKey());
assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
// ----------------------------------------
// 3. change connector URL so that we are sure that any provided value will come from virtual cache
// ----------------------------------------
String jdbcURL = null;
ConnInstanceTO connInstanceTO = connectorService.readByResource(RESOURCE_NAME_DBVIRATTR, Locale.ENGLISH.getLanguage());
for (ConnConfProperty prop : connInstanceTO.getConf()) {
if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
jdbcURL = prop.getValues().iterator().next().toString();
prop.getValues().clear();
prop.getValues().add("jdbc:h2:tcp://localhost:9092/xxx");
}
}
connectorService.update(connInstanceTO);
// ----------------------------------------
// ----------------------------------------
// 4. update value on external resource
// ----------------------------------------
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
String value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
assertEquals("virattrcache", value);
jdbcTemplate.update("UPDATE testpull set USERNAME='virattrcache2' WHERE ID=?", userTO.getKey());
value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
assertEquals("virattrcache2", value);
// ----------------------------------------
userTO = userService.read(userTO.getKey());
assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
// ----------------------------------------
for (ConnConfProperty prop : connInstanceTO.getConf()) {
if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
prop.getValues().clear();
prop.getValues().add(jdbcURL);
}
}
connectorService.update(connInstanceTO);
// ----------------------------------------
// cached value still in place...
userTO = userService.read(userTO.getKey());
assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
// force cache update by adding a resource which has virtualdata mapped for propagation
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
userTO = userService.read(userTO.getKey());
assertEquals("virattrcache2", userTO.getVirAttr("virtualdata").get().getValues().get(0));
}
use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.
the class PullTaskITCase method syncTokenWithErrors.
@Test
public void syncTokenWithErrors() {
ResourceTO origResource = resourceService.read(RESOURCE_NAME_DBPULL);
ConnInstanceTO origConnector = connectorService.read(origResource.getConnector(), null);
ResourceTO resForTest = SerializationUtils.clone(origResource);
resForTest.setKey("syncTokenWithErrors");
resForTest.setConnector(null);
ConnInstanceTO connForTest = SerializationUtils.clone(origConnector);
connForTest.setKey(null);
connForTest.setDisplayName("For syncTokenWithErrors");
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
try {
connForTest.getCapabilities().add(ConnectorCapability.SYNC);
ConnConfProperty changeLogColumn = connForTest.getConf("changeLogColumn").get();
assertNotNull(changeLogColumn);
assertTrue(changeLogColumn.getValues().isEmpty());
changeLogColumn.getValues().add("lastModification");
Response response = connectorService.create(connForTest);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
}
connForTest = getObject(response.getLocation(), ConnectorService.class, ConnInstanceTO.class);
assertNotNull(connForTest);
resForTest.setConnector(connForTest.getKey());
resForTest = createResource(resForTest);
assertNotNull(resForTest);
PullTaskTO pullTask = new PullTaskTO();
pullTask.setActive(true);
pullTask.setName("For syncTokenWithErrors");
pullTask.setResource(resForTest.getKey());
pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
pullTask.setPullMode(PullMode.INCREMENTAL);
pullTask.setPerformCreate(true);
pullTask.setPerformUpdate(true);
pullTask.setPerformDelete(true);
response = taskService.create(TaskType.PULL, pullTask);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
}
pullTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(pullTask);
jdbcTemplate.execute("DELETE FROM testpull");
jdbcTemplate.execute("INSERT INTO testpull VALUES " + "(1040, 'syncTokenWithErrors1', 'Surname1', " + "false, 'syncTokenWithErrors1@syncope.apache.org', '2014-05-23 13:53:24.293')");
jdbcTemplate.execute("INSERT INTO testpull VALUES " + "(1041, 'syncTokenWithErrors2', 'Surname2', " + "false, 'syncTokenWithErrors1@syncope.apache.org', '2015-05-23 13:53:24.293')");
ExecTO exec = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
resForTest = resourceService.read(resForTest.getKey());
assertTrue(resForTest.getProvision(AnyTypeKind.USER.name()).get().getSyncToken().contains("2014-05-23"));
jdbcTemplate.execute("UPDATE testpull " + "SET email='syncTokenWithErrors2@syncope.apache.org', lastModification='2016-05-23 13:53:24.293' " + "WHERE ID=1041");
exec = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
resForTest = resourceService.read(resForTest.getKey());
assertTrue(resForTest.getProvision(AnyTypeKind.USER.name()).get().getSyncToken().contains("2016-05-23"));
} finally {
if (resForTest.getConnector() != null) {
resourceService.delete(resForTest.getKey());
connectorService.delete(connForTest.getKey());
}
jdbcTemplate.execute("DELETE FROM testpull WHERE ID=1040");
jdbcTemplate.execute("DELETE FROM testpull WHERE ID=1041");
}
}
use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.
the class PullTaskITCase method issueSYNCOPE313LDAP.
@Test
public void issueSYNCOPE313LDAP() throws Exception {
// First of all, clear any potential conflict with existing user / group
ldapCleanup();
UserTO user = null;
PullTaskTO pullTask = null;
ConnInstanceTO resourceConnector = null;
ConnConfProperty property = null;
try {
// 1. create user in LDAP
String oldCleanPassword = "security123";
user = UserITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
user.setPassword(oldCleanPassword);
user.getResources().add(RESOURCE_NAME_LDAP);
user = createUser(user).getEntity();
assertNotNull(user);
assertFalse(user.getResources().isEmpty());
// 2. request to change password only on Syncope and not on LDAP
String newCleanPassword = "new-security123";
UserPatch userPatch = new UserPatch();
userPatch.setKey(user.getKey());
userPatch.setPassword(new PasswordPatch.Builder().value(newCleanPassword).build());
user = updateUser(userPatch).getEntity();
// 3. Check that the Syncope user now has the changed password
Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
assertNotNull(self);
// 4. Check that the LDAP resource has the old password
ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), oldCleanPassword, connObject.getAttr(Name.NAME).get().getValues().get(0)));
// 5. Update the LDAP Connector to retrieve passwords
ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
resourceConnector = connectorService.read(ldapResource.getConnector(), Locale.ENGLISH.getLanguage());
property = resourceConnector.getConf("retrievePasswordsWithSearch").get();
property.getValues().clear();
property.getValues().add(Boolean.TRUE);
connectorService.update(resourceConnector);
// 6. Pull the user from the resource
ImplementationTO pullActions = new ImplementationTO();
pullActions.setKey(LDAPPasswordPullActions.class.getSimpleName());
pullActions.setEngine(ImplementationEngine.JAVA);
pullActions.setType(ImplementationType.PULL_ACTIONS);
pullActions.setBody(LDAPPasswordPullActions.class.getName());
Response response = implementationService.create(pullActions);
pullActions = implementationService.read(pullActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(pullActions);
pullTask = new PullTaskTO();
pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
pullTask.setName("LDAP Pull Task");
pullTask.setActive(true);
pullTask.setPerformCreate(true);
pullTask.setPerformUpdate(true);
pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
pullTask.setResource(RESOURCE_NAME_LDAP);
pullTask.getActions().add(pullActions.getKey());
Response taskResponse = taskService.create(TaskType.PULL, pullTask);
pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(pullTask);
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// 7. Test the pulled user
self = clientFactory.create(user.getUsername(), oldCleanPassword).self();
assertNotNull(self);
} catch (Exception e) {
fail(e.getMessage());
} finally {
// Delete PullTask + user + reset the connector
if (pullTask != null) {
taskService.delete(TaskType.PULL, pullTask.getKey());
}
if (resourceConnector != null && property != null) {
property.getValues().clear();
property.getValues().add(Boolean.FALSE);
connectorService.update(resourceConnector);
}
if (user != null) {
deleteUser(user.getKey());
}
}
}
use of org.apache.syncope.common.lib.types.ConnConfProperty in project syncope by apache.
the class ConnectorITCase method update.
@Test
public void update() {
ConnInstanceTO connectorTO = new ConnInstanceTO();
connectorTO.setAdminRealm(SyncopeConstants.ROOT_REALM);
// set connector instance key
connectorTO.setKey("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b");
// set connector version
connectorTO.setVersion(connIdSoapVersion);
// set connector name
connectorTO.setConnectorName("net.tirasa.connid.bundles.soap.WebServiceConnector");
// set bundle name
connectorTO.setBundleName("net.tirasa.connid.bundles.soap");
connectorTO.setConnRequestTimeout(20);
// set the connector configuration using PropertyTO
Set<ConnConfProperty> conf = new HashSet<>();
ConnConfPropSchema endpointSchema = new ConnConfPropSchema();
endpointSchema.setName("endpoint");
endpointSchema.setType(String.class.getName());
endpointSchema.setRequired(true);
ConnConfProperty endpoint = new ConnConfProperty();
endpoint.setSchema(endpointSchema);
endpoint.getValues().add("http://localhost:8888/syncope-fit-build-tools/cxf/soap");
conf.add(endpoint);
ConnConfPropSchema servicenameSchema = new ConnConfPropSchema();
servicenameSchema.setName("servicename");
servicenameSchema.setType(String.class.getName());
servicenameSchema.setRequired(true);
ConnConfProperty servicename = new ConnConfProperty();
servicename.setSchema(servicenameSchema);
servicename.getValues().add("Provisioning");
conf.add(servicename);
// set connector configuration
connectorTO.getConf().addAll(conf);
connectorService.update(connectorTO);
ConnInstanceTO actual = connectorService.read(connectorTO.getKey(), Locale.ENGLISH.getLanguage());
assertNotNull(actual);
actual = connectorService.read(actual.getKey(), Locale.ENGLISH.getLanguage());
assertNotNull(actual);
assertEquals(actual.getBundleName(), connectorTO.getBundleName());
assertEquals(actual.getConnectorName(), connectorTO.getConnectorName());
assertEquals(actual.getVersion(), connectorTO.getVersion());
assertEquals(Integer.valueOf(20), actual.getConnRequestTimeout());
}
use of org.apache.syncope.common.lib.types.ConnConfProperty 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);
}
}
Aggregations