Search in sources :

Example 1 with GroupTO

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

the class AnyOperations method patch.

public static GroupTO patch(final GroupTO groupTO, final GroupPatch groupPatch) {
    GroupTO result = SerializationUtils.clone(groupTO);
    patch(groupTO, groupPatch, result);
    if (groupPatch.getName() != null) {
        result.setName(groupPatch.getName().getValue());
    }
    if (groupPatch.getUserOwner() != null) {
        result.setGroupOwner(groupPatch.getUserOwner().getValue());
    }
    if (groupPatch.getGroupOwner() != null) {
        result.setGroupOwner(groupPatch.getGroupOwner().getValue());
    }
    result.setUDynMembershipCond(groupPatch.getUDynMembershipCond());
    result.getADynMembershipConds().clear();
    result.getADynMembershipConds().putAll(groupPatch.getADynMembershipConds());
    return result;
}
Also used : GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 2 with GroupTO

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

the class DefaultGroupWorkflowAdapter method doUpdate.

@Override
protected WorkflowResult<GroupPatch> doUpdate(final Group group, final GroupPatch groupPatch) {
    GroupTO original = dataBinder.getGroupTO(group, true);
    PropagationByResource propByRes = dataBinder.update(group, groupPatch);
    Set<AttrTO> virAttrs = groupPatch.getVirAttrs();
    GroupTO updated = dataBinder.getGroupTO(groupDAO.save(group), true);
    GroupPatch effectivePatch = AnyOperations.diff(updated, original, false);
    effectivePatch.getVirAttrs().clear();
    effectivePatch.getVirAttrs().addAll(virAttrs);
    return new WorkflowResult<>(effectivePatch, propByRes, "update");
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 3 with GroupTO

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

the class UserIssuesITCase method issueSYNCOPE1206.

@Test
public void issueSYNCOPE1206() {
    // 1. create group with dynamic user condition 'cool==true'
    GroupTO dynGroup = GroupITCase.getSampleTO("syncope1206");
    dynGroup.setUDynMembershipCond(SyncopeClient.getUserSearchConditionBuilder().is("cool").equalTo("true").query());
    dynGroup = createGroup(dynGroup).getEntity();
    assertNotNull(dynGroup);
    assertTrue(dynGroup.getResources().contains(RESOURCE_NAME_LDAP));
    // 2. create user (no value for cool, no dynamic membership, no propagation to LDAP)
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope1206@apache.org");
    userTO.getResources().clear();
    ProvisioningResult<UserTO> result = createUser(userTO);
    assertTrue(result.getPropagationStatuses().isEmpty());
    // 3. update user to match the dynamic condition: expect propagation to LDAP
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(result.getEntity().getKey());
    userPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO("cool", "true")).build());
    result = updateUser(userPatch);
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
    // 4. update again user to not match the dynamic condition any more: expect propagation to LDAP
    userPatch = new UserPatch();
    userPatch.setKey(result.getEntity().getKey());
    userPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO("cool", "false")).build());
    result = updateUser(userPatch);
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 4 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO 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 5 with GroupTO

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

the class UserIssuesITCase method issueSYNCOPE686.

@Test
public void issueSYNCOPE686() {
    // 1. read configured cipher algorithm in order to be able to restore it at the end of test
    AttrTO pwdCipherAlgo = configurationService.get("password.cipher.algorithm");
    String origpwdCipherAlgo = pwdCipherAlgo.getValues().get(0);
    // 2. set AES password cipher algorithm
    pwdCipherAlgo.getValues().set(0, "AES");
    configurationService.set(pwdCipherAlgo);
    try {
        // 3. create group with LDAP resource assigned
        GroupTO group = GroupITCase.getBasicSampleTO("syncope686");
        group.getResources().add(RESOURCE_NAME_LDAP);
        group = createGroup(group).getEntity();
        assertNotNull(group);
        // 4. create user with no resources
        UserTO userTO = UserITCase.getUniqueSampleTO("syncope686@apache.org");
        userTO.getResources().clear();
        userTO = createUser(userTO).getEntity();
        assertNotNull(userTO);
        // 5. update user with the new group, and don't provide any password
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(userTO.getKey());
        userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(group.getKey()).build());
        ProvisioningResult<UserTO> result = updateUser(userPatch);
        assertNotNull(result);
        // 5. verify that propagation was successful
        List<PropagationStatus> props = result.getPropagationStatuses();
        assertNotNull(props);
        assertEquals(1, props.size());
        PropagationStatus prop = props.iterator().next();
        assertNotNull(prop);
        assertEquals(RESOURCE_NAME_LDAP, prop.getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, prop.getStatus());
    } finally {
        // restore initial cipher algorithm
        pwdCipherAlgo.getValues().set(0, origpwdCipherAlgo);
        configurationService.set(pwdCipherAlgo);
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

GroupTO (org.apache.syncope.common.lib.to.GroupTO)90 Test (org.junit.jupiter.api.Test)47 UserTO (org.apache.syncope.common.lib.to.UserTO)34 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)23 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)16 List (java.util.List)15 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)14 Response (javax.ws.rs.core.Response)13 NamingException (javax.naming.NamingException)12 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 Map (java.util.Map)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 AccessControlException (java.security.AccessControlException)10 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Collections (java.util.Collections)9