use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE260.
@Test
public void issueSYNCOPE260() {
// create new virtual schema for the resource below
ResourceTO ws2 = resourceService.read(RESOURCE_NAME_WS2);
ProvisionTO provision = ws2.getProvision(AnyTypeKind.USER.name()).get();
assertNotNull(provision);
VirSchemaTO virSchema = new VirSchemaTO();
virSchema.setKey("syncope260" + getUUIDString());
virSchema.setExtAttrName("companyName");
virSchema.setResource(RESOURCE_NAME_WS2);
virSchema.setAnyType(provision.getAnyType());
virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
assertNotNull(virSchema);
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("syncope260" + 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 user and check virtual attribute value propagation
// ----------------------------------
UserTO userTO = UserITCase.getUniqueSampleTO("260@a.com");
userTO.getAuxClasses().add(newClass.getKey());
userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue"));
userTO.getResources().add(RESOURCE_NAME_WS2);
ProvisioningResult<UserTO> result = createUser(userTO);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// update user virtual attribute and check virtual attribute value update propagation
// ----------------------------------
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue2"));
result = updateUser(userPatch);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// suspend/reactivate user and check virtual attribute value (unchanged)
// ----------------------------------
StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.SUSPEND).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertEquals("suspended", userTO.getStatus());
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertEquals("active", userTO.getStatus());
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// update user attribute and check virtual attribute value (unchanged)
// ----------------------------------
userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "Surname2"));
result = updateUser(userPatch);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("Surname2", connObjectTO.getAttr("SURNAME").get().getValues().get(0));
// virtual attribute value did not change
assertFalse(connObjectTO.getAttr("COMPANYNAME").get().getValues().isEmpty());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
}
use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.
the class VirSchemaITCase method issueSYNCOPE418.
@Test
public void issueSYNCOPE418() {
ResourceTO ws1 = resourceService.read(RESOURCE_NAME_WS1);
assertNotNull(ws1);
assertEquals(1, ws1.getProvisions().size());
assertTrue(ws1.getProvisions().get(0).getVirSchemas().isEmpty());
VirSchemaTO schema = new VirSchemaTO();
schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
schema.setExtAttrName("name");
schema.setResource(RESOURCE_NAME_WS1);
schema.setAnyType(ws1.getProvisions().get(0).getAnyType());
try {
createSchema(SchemaType.VIRTUAL, schema);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidVirSchema, e.getType());
assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidKey.name()));
}
}
use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.
the class VirSchemaITCase method crud.
@Test
public void crud() {
ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV);
assertNotNull(csv);
assertEquals(1, csv.getProvisions().size());
assertTrue(csv.getProvisions().get(0).getVirSchemas().isEmpty());
VirSchemaTO schema = new VirSchemaTO();
schema.setKey("virtualTest" + getUUIDString());
schema.setExtAttrName("name");
schema.setResource(RESOURCE_NAME_CSV);
schema.setAnyType(csv.getProvisions().get(0).getAnyType());
schema = createSchema(SchemaType.VIRTUAL, schema);
assertNotNull(schema);
assertEquals(csv.getProvisions().get(0).getAnyType(), schema.getAnyType());
csv = resourceService.read(RESOURCE_NAME_CSV);
assertNotNull(csv);
assertEquals(1, csv.getProvisions().size());
assertFalse(csv.getProvisions().get(0).getVirSchemas().isEmpty());
schema = schemaService.read(SchemaType.VIRTUAL, schema.getKey());
assertNotNull(schema);
schemaService.delete(SchemaType.VIRTUAL, schema.getKey());
try {
schemaService.read(SchemaType.VIRTUAL, schema.getKey());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
csv = resourceService.read(RESOURCE_NAME_CSV);
assertNotNull(csv);
assertEquals(1, csv.getProvisions().size());
assertTrue(csv.getProvisions().get(0).getVirSchemas().isEmpty());
}
use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.
the class ResourceServiceImpl method create.
@Override
public Response create(final ResourceTO resourceTO) {
ResourceTO created = logic.create(resourceTO);
URI location = uriInfo.getAbsolutePathBuilder().path(created.getKey()).build();
return Response.created(location).header(RESTHeaders.RESOURCE_KEY, created.getKey()).build();
}
use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.
the class HistoryConfDetails method addCurrentInstanceConf.
@SuppressWarnings("unchecked")
private void addCurrentInstanceConf() {
T conf = null;
if (selectedHistoryConfTO instanceof ConnInstanceHistoryConfTO) {
ConnInstanceTO current = new ConnectorRestClient().read(ConnInstanceHistoryConfTO.class.cast(selectedHistoryConfTO).getConnInstanceTO().getKey());
conf = (T) new ConnInstanceHistoryConfTO();
((ConnInstanceHistoryConfTO) conf).setConnInstanceTO(current);
} else if (selectedHistoryConfTO instanceof ResourceHistoryConfTO) {
ResourceTO current = new ResourceRestClient().read(ResourceHistoryConfTO.class.cast(selectedHistoryConfTO).getResourceTO().getKey());
conf = (T) new ResourceHistoryConfTO();
((ResourceHistoryConfTO) conf).setResourceTO(current);
}
if (conf != null) {
conf.setCreator(selectedHistoryConfTO.getCreator());
conf.setKey("current");
availableHistoryConfTOs.add(conf);
}
}
Aggregations