Search in sources :

Example 1 with ProvisioningResult

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

the class UserIssuesITCase method issueSYNCOPE1099.

@Test
public void issueSYNCOPE1099() {
    // 1. create group with dynamic condition and resource
    GroupTO group = GroupITCase.getSampleTO("syncope1099G");
    group.getResources().clear();
    group.getResources().add(RESOURCE_NAME_TESTDB);
    group.setUDynMembershipCond("firstname==issueSYNCOPE1099");
    group = createGroup(group).getEntity();
    assertNotNull(group);
    // 2. create user matching the condition above
    UserTO user = UserITCase.getUniqueSampleTO("syncope1099U@apache.org");
    user.getPlainAttr("firstname").get().getValues().set(0, "issueSYNCOPE1099");
    ProvisioningResult<UserTO> created = createUser(user);
    assertNotNull(created);
    // 3. verify that dynamic membership is set and that resource is consequently assigned
    user = created.getEntity();
    String groupKey = group.getKey();
    assertTrue(user.getDynMemberships().stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
    assertTrue(user.getResources().contains(RESOURCE_NAME_TESTDB));
    // 4. verify that propagation happened towards the resource of the dynamic group
    assertFalse(created.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_TESTDB, created.getPropagationStatuses().get(0).getResource());
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Autowired(org.springframework.beans.factory.annotation.Autowired) NamingException(javax.naming.NamingException) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) RESTHeaders(org.apache.syncope.common.rest.api.RESTHeaders) OperationalAttributes(org.identityconnectors.framework.common.objects.OperationalAttributes) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) MappingTO(org.apache.syncope.common.lib.to.MappingTO) Collection(java.util.Collection) LDAPPasswordPropagationActions(org.apache.syncope.core.provisioning.java.propagation.LDAPPasswordPropagationActions) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) DBPasswordPropagationActions(org.apache.syncope.core.provisioning.java.propagation.DBPasswordPropagationActions) StandardCharsets(java.nio.charset.StandardCharsets) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) ImplementationEngine(org.apache.syncope.common.lib.types.ImplementationEngine) Base64(java.util.Base64) List(java.util.List) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Response(javax.ws.rs.core.Response) DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) POJOHelper(org.apache.syncope.core.provisioning.api.serialization.POJOHelper) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RealmTO(org.apache.syncope.common.lib.to.RealmTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO) Encryptor(org.apache.syncope.core.spring.security.Encryptor) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) IOUtils(org.apache.cxf.helpers.IOUtils) IOException(java.io.IOException) Name(org.identityconnectors.framework.common.objects.Name) PolicyType(org.apache.syncope.common.lib.types.PolicyType) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) Collections(java.util.Collections) UserTO(org.apache.syncope.common.lib.to.UserTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 2 with ProvisioningResult

use of org.apache.syncope.common.lib.to.ProvisioningResult 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);
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Autowired(org.springframework.beans.factory.annotation.Autowired) SerializationUtils(org.apache.commons.lang3.SerializationUtils) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Locale(java.util.Locale) Map(java.util.Map) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) StatusPatchType(org.apache.syncope.common.lib.types.StatusPatchType) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) List(java.util.List) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) 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) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 3 with ProvisioningResult

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

the class MultitenancyITCase method createUser.

@Test
public void createUser() {
    assertNull(adminClient.getService(RealmService.class).list().get(0).getPasswordPolicy());
    UserTO user = new UserTO();
    user.setRealm(SyncopeConstants.ROOT_REALM);
    user.setUsername(getUUIDString());
    user.setPassword("password");
    Response response = adminClient.getService(UserService.class).create(user, true);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    user = response.readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(user);
}
Also used : Response(javax.ws.rs.core.Response) UserService(org.apache.syncope.common.rest.api.service.UserService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) Test(org.junit.jupiter.api.Test)

Example 4 with ProvisioningResult

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

the class GroupITCase method update.

@Test
public void update() {
    GroupTO groupTO = getSampleTO("latestGroup" + getUUIDString());
    groupTO = createGroup(groupTO).getEntity();
    assertEquals(1, groupTO.getPlainAttrs().size());
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    String modName = "finalGroup" + getUUIDString();
    groupPatch.setName(new StringReplacePatchItem.Builder().value(modName).build());
    groupPatch.getPlainAttrs().add(attrAddReplacePatch("show", "FALSE"));
    groupTO = updateGroup(groupPatch).getEntity();
    assertEquals(modName, groupTO.getName());
    assertEquals(2, groupTO.getPlainAttrs().size());
    groupTO.getPlainAttr("show").get().getValues().clear();
    groupTO = groupService.update(groupTO).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
    }).getEntity();
    assertFalse(groupTO.getPlainAttr("show").isPresent());
}
Also used : StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 5 with ProvisioningResult

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

the class AbstractAnyLogic method afterDelete.

protected ProvisioningResult<TO> afterDelete(final TO input, final List<PropagationStatus> statuses, final List<LogicActions> actions) {
    TO any = input;
    for (LogicActions action : actions) {
        any = action.afterDelete(any);
    }
    ProvisioningResult<TO> result = new ProvisioningResult<>();
    result.setEntity(any);
    result.getPropagationStatuses().addAll(statuses);
    return result;
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) AnyTO(org.apache.syncope.common.lib.to.AnyTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) UserTO(org.apache.syncope.common.lib.to.UserTO) LogicActions(org.apache.syncope.core.provisioning.api.LogicActions)

Aggregations

ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)39 UserTO (org.apache.syncope.common.lib.to.UserTO)24 Test (org.junit.jupiter.api.Test)21 GroupTO (org.apache.syncope.common.lib.to.GroupTO)14 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 Response (javax.ws.rs.core.Response)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)8 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)8 UserService (org.apache.syncope.common.rest.api.service.UserService)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 GenericType (javax.ws.rs.core.GenericType)6 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)6 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)5 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)4 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)4