use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE397.
@Test
public void issueSYNCOPE397() {
ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV);
// change mapping of resource-csv
MappingTO origMapping = SerializationUtils.clone(csv.getProvisions().get(0).getMapping());
try {
// remove this mapping
Optional<ItemTO> email = csv.getProvisions().get(0).getMapping().getItems().stream().filter(item -> "email".equals(item.getIntAttrName())).findFirst();
if (email.isPresent()) {
csv.getProvisions().get(0).getMapping().getItems().remove(email.get());
}
resourceService.update(csv);
csv = resourceService.read(RESOURCE_NAME_CSV);
assertNotNull(csv.getProvisions().get(0).getMapping());
// create new virtual schema for the resource below
ProvisionTO provision = csv.getProvision(AnyTypeKind.USER.name()).get();
assertNotNull(provision);
VirSchemaTO virSchema = new VirSchemaTO();
virSchema.setKey("syncope397" + getUUIDString());
virSchema.setExtAttrName("email");
virSchema.setResource(RESOURCE_NAME_CSV);
virSchema.setAnyType(provision.getAnyType());
virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
assertNotNull(virSchema);
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("syncope397" + getUUIDString());
newClass.getVirSchemas().add(virSchema.getKey());
Response response = anyTypeClassService.create(newClass);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
// create a new user
UserTO userTO = UserITCase.getUniqueSampleTO("397@syncope.apache.org");
userTO.getAuxClasses().add("csv");
userTO.getAuxClasses().add(newClass.getKey());
userTO.getResources().clear();
userTO.getMemberships().clear();
userTO.getVirAttrs().clear();
userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testone.org"));
// assign resource-csv to user
userTO.getResources().add(RESOURCE_NAME_CSV);
// save user
userTO = createUser(userTO).getEntity();
// make std controls about user
assertNotNull(userTO);
assertTrue(RESOURCE_NAME_CSV.equals(userTO.getResources().iterator().next()));
assertEquals("test@testone.org", userTO.getVirAttrs().iterator().next().getValues().get(0));
// update user
UserTO toBeUpdated = userService.read(userTO.getKey());
UserPatch userPatch = new UserPatch();
userPatch.setKey(toBeUpdated.getKey());
userPatch.setPassword(new PasswordPatch.Builder().value("password234").build());
// assign new resource to user
userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
// modify virtual attribute
userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testoneone.com"));
// check Syncope change password
userPatch.setPassword(new PasswordPatch.Builder().value("password234").onSyncope(true).resource(RESOURCE_NAME_WS2).build());
ProvisioningResult<UserTO> result = updateUser(userPatch);
assertNotNull(result);
toBeUpdated = result.getEntity();
assertTrue(toBeUpdated.getVirAttrs().iterator().next().getValues().contains("test@testoneone.com"));
// check if propagates correctly with assertEquals on size of tasks list
assertEquals(2, result.getPropagationStatuses().size());
} finally {
// restore mapping of resource-csv
csv.getProvisions().get(0).setMapping(origMapping);
resourceService.update(csv);
}
}
use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.
the class PropagationTaskITCase method privileges.
@Test
public void privileges() {
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
ldap.setKey("ldapWithPrivileges");
ItemTO item = new ItemTO();
item.setIntAttrName("privileges[mightyApp]");
item.setExtAttrName("businessCategory");
item.setPurpose(MappingPurpose.PROPAGATION);
ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
provision.getVirSchemas().clear();
provision.getMapping().add(item);
ldap = createResource(ldap);
try {
UserTO user = UserITCase.getUniqueSampleTO("privilege@syncope.apache.org");
user.getResources().add(ldap.getKey());
user.getRoles().add("Other");
ProvisioningResult<UserTO> result = createUser(user);
assertEquals(1, result.getPropagationStatuses().size());
assertNotNull(result.getPropagationStatuses().get(0).getAfterObj());
AttrTO businessCategory = result.getPropagationStatuses().get(0).getAfterObj().getAttr("businessCategory").orElse(null);
assertNotNull(businessCategory);
assertEquals(1, businessCategory.getValues().size());
assertEquals("postMighty", businessCategory.getValues().get(0));
} finally {
resourceService.delete(ldap.getKey());
}
}
use of org.apache.syncope.common.lib.to.ResourceTO 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.to.ResourceTO 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.to.ResourceTO in project syncope by apache.
the class ExceptionMapperITCase method invalidRequests.
@Test
public void invalidRequests() {
try {
taskService.search(new TaskQuery.Builder(TaskType.NOTIFICATION).resource(RESOURCE_NAME_LDAP).build());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
taskService.search(new TaskQuery.Builder(TaskType.PULL).anyTypeKind(AnyTypeKind.ANY_OBJECT).build());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
taskService.search(new TaskQuery.Builder(TaskType.PULL).notification("e00945b5-1184-4d43-8e45-4318a8dcdfd4").build());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
anyTypeService.delete(AnyTypeKind.USER.name());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(AccessTokenService.class).login();
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
ItemTO mapping = ldap.getProvisions().get(0).getMapping().getItems().get(0);
mapping.setIntAttrName("memberships.cn");
resourceService.update(ldap);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidMapping, e.getType());
}
}
Aggregations