Search in sources :

Example 6 with VirSchemaTO

use of org.apache.syncope.common.lib.to.VirSchemaTO in project syncope by apache.

the class SchemaDataBinderImpl method getVirSchemaTO.

@Override
public VirSchemaTO getVirSchemaTO(final VirSchema schema) {
    VirSchemaTO schemaTO = new VirSchemaTO();
    BeanUtils.copyProperties(schema, schemaTO, IGNORE_PROPERTIES);
    schemaTO.setAnyTypeClass(schema.getAnyTypeClass() == null ? null : schema.getAnyTypeClass().getKey());
    schemaTO.setResource(schema.getProvision().getResource().getKey());
    schemaTO.setAnyType(schema.getProvision().getAnyType().getKey());
    return schemaTO;
}
Also used : VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO)

Example 7 with VirSchemaTO

use of org.apache.syncope.common.lib.to.VirSchemaTO 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));
// ----------------------------------
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 8 with VirSchemaTO

use of org.apache.syncope.common.lib.to.VirSchemaTO 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()));
    }
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) Test(org.junit.jupiter.api.Test)

Example 9 with VirSchemaTO

use of org.apache.syncope.common.lib.to.VirSchemaTO in project syncope by apache.

the class VirSchemaITCase method issueSYNCOPE323.

@Test
public void issueSYNCOPE323() {
    VirSchemaTO actual = schemaService.read(SchemaType.VIRTUAL, "virtualdata");
    assertNotNull(actual);
    try {
        createSchema(SchemaType.VIRTUAL, actual);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.CONFLICT, e.getType().getResponseStatus());
        assertEquals(ClientExceptionType.EntityExists, e.getType());
    }
    actual.setKey(null);
    try {
        createSchema(SchemaType.VIRTUAL, actual);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.BAD_REQUEST, e.getType().getResponseStatus());
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) Test(org.junit.jupiter.api.Test)

Example 10 with VirSchemaTO

use of org.apache.syncope.common.lib.to.VirSchemaTO 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());
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) Test(org.junit.jupiter.api.Test)

Aggregations

VirSchemaTO (org.apache.syncope.common.lib.to.VirSchemaTO)12 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 Test (org.junit.jupiter.api.Test)7 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)6 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)4 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)4 UserTO (org.apache.syncope.common.lib.to.UserTO)4 Response (javax.ws.rs.core.Response)3 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)3 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)3 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)3 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)3 GroupTO (org.apache.syncope.common.lib.to.GroupTO)3 ItemTO (org.apache.syncope.common.lib.to.ItemTO)3 MappingTO (org.apache.syncope.common.lib.to.MappingTO)3 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)3 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)3 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)3 AnyTypeClassService (org.apache.syncope.common.rest.api.service.AnyTypeClassService)3 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)3