Search in sources :

Example 1 with ConnObjectTO

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

the class UserITCase method groupAttrPropagation.

@Test
public void groupAttrPropagation() {
    UserTO userTO = getUniqueSampleTO("checkGroupAttrPropagation@syncope.apache.org");
    userTO.getResources().clear();
    userTO.getMemberships().clear();
    userTO.getVirAttrs().clear();
    userTO.getAuxClasses().add("csv");
    userTO.getMemberships().add(new MembershipTO.Builder().group("37d15e4c-cdc1-460b-a591-8505c8133806").build());
    userTO.getResources().add(RESOURCE_NAME_CSV);
    UserTO actual = createUser(userTO).getEntity();
    assertNotNull(actual);
    assertNotNull(actual.getDerAttr("csvuserid"));
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_CSV, AnyTypeKind.USER.name(), actual.getKey());
    assertNotNull(connObjectTO);
    assertEquals("sx-dx", connObjectTO.getAttr("THEIRGROUP").get().getValues().get(0));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 2 with ConnObjectTO

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

the class UserIssuesITCase method issueSYNCOPE647.

@Test
public void issueSYNCOPE647() {
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope647@syncope.apache.org");
    userTO.getResources().clear();
    userTO.getMemberships().clear();
    userTO.getVirAttrs().clear();
    userTO.getAuxClasses().add("csv");
    userTO.getAuxClasses().add("generic membership");
    userTO.getPlainAttrs().add(attrTO("postalAddress", "postalAddress"));
    userTO.getResources().add(RESOURCE_NAME_LDAP);
    UserTO actual = createUser(userTO).getEntity();
    assertNotNull(actual);
    assertNotNull(actual.getDerAttr("csvuserid"));
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), actual.getKey());
    assertNotNull(connObjectTO);
    assertEquals("postalAddress", connObjectTO.getAttr("postalAddress").get().getValues().get(0));
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(actual.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("postalAddress", "newPostalAddress"));
    actual = updateUser(userPatch).getEntity();
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), actual.getKey());
    assertNotNull(connObjectTO);
    assertEquals("newPostalAddress", connObjectTO.getAttr("postalAddress").get().getValues().get(0));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 3 with ConnObjectTO

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

the class UserIssuesITCase method issueSYNCOPE122.

@Test
public void issueSYNCOPE122() {
    // 1. create user on testdb and testdb2
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope122@apache.org");
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_TESTDB);
    userTO.getResources().add(RESOURCE_NAME_TESTDB2);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertTrue(userTO.getResources().contains(RESOURCE_NAME_TESTDB));
    assertTrue(userTO.getResources().contains(RESOURCE_NAME_TESTDB2));
    String pwdOnSyncope = userTO.getPassword();
    ConnObjectTO userOnDb = resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userTO.getKey());
    AttrTO pwdOnTestDbAttr = userOnDb.getAttr(OperationalAttributes.PASSWORD_NAME).get();
    assertNotNull(pwdOnTestDbAttr);
    assertNotNull(pwdOnTestDbAttr.getValues());
    assertFalse(pwdOnTestDbAttr.getValues().isEmpty());
    String pwdOnTestDb = pwdOnTestDbAttr.getValues().iterator().next();
    ConnObjectTO userOnDb2 = resourceService.readConnObject(RESOURCE_NAME_TESTDB2, AnyTypeKind.USER.name(), userTO.getKey());
    AttrTO pwdOnTestDb2Attr = userOnDb2.getAttr(OperationalAttributes.PASSWORD_NAME).get();
    assertNotNull(pwdOnTestDb2Attr);
    assertNotNull(pwdOnTestDb2Attr.getValues());
    assertFalse(pwdOnTestDb2Attr.getValues().isEmpty());
    String pwdOnTestDb2 = pwdOnTestDb2Attr.getValues().iterator().next();
    // 2. request to change password only on testdb (no Syncope, no testdb2)
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().value(getUUIDString()).onSyncope(false).resource(RESOURCE_NAME_TESTDB).build());
    ProvisioningResult<UserTO> result = updateUser(userPatch);
    userTO = result.getEntity();
    // 3a. Chech that only a single propagation took place
    assertNotNull(result.getPropagationStatuses());
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(RESOURCE_NAME_TESTDB, result.getPropagationStatuses().iterator().next().getResource());
    // 3b. verify that password hasn't changed on Syncope
    assertEquals(pwdOnSyncope, userTO.getPassword());
    // 3c. verify that password *has* changed on testdb
    userOnDb = resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userTO.getKey());
    AttrTO pwdOnTestDbAttrAfter = userOnDb.getAttr(OperationalAttributes.PASSWORD_NAME).get();
    assertNotNull(pwdOnTestDbAttrAfter);
    assertNotNull(pwdOnTestDbAttrAfter.getValues());
    assertFalse(pwdOnTestDbAttrAfter.getValues().isEmpty());
    assertNotEquals(pwdOnTestDb, pwdOnTestDbAttrAfter.getValues().iterator().next());
    // 3d. verify that password hasn't changed on testdb2
    userOnDb2 = resourceService.readConnObject(RESOURCE_NAME_TESTDB2, AnyTypeKind.USER.name(), userTO.getKey());
    AttrTO pwdOnTestDb2AttrAfter = userOnDb2.getAttr(OperationalAttributes.PASSWORD_NAME).get();
    assertNotNull(pwdOnTestDb2AttrAfter);
    assertNotNull(pwdOnTestDb2AttrAfter.getValues());
    assertFalse(pwdOnTestDb2AttrAfter.getValues().isEmpty());
    assertEquals(pwdOnTestDb2, pwdOnTestDb2AttrAfter.getValues().iterator().next());
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 4 with ConnObjectTO

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

the class UserIssuesITCase method issueSYNCOPE357.

@Test
public void issueSYNCOPE357() throws IOException {
    // 1. create group with LDAP resource
    GroupTO groupTO = new GroupTO();
    groupTO.setName("SYNCOPE357-" + getUUIDString());
    groupTO.setRealm("/");
    groupTO.getResources().add(RESOURCE_NAME_LDAP);
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    // 2. create user with membership of the above group
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope357@syncope.apache.org");
    userTO.getPlainAttrs().add(attrTO("obscure", "valueToBeObscured"));
    userTO.getPlainAttrs().add(attrTO("photo", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/favicon.jpg")))));
    userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
    userTO = createUser(userTO).getEntity();
    assertTrue(userTO.getResources().contains(RESOURCE_NAME_LDAP));
    assertNotNull(userTO.getPlainAttr("obscure"));
    assertNotNull(userTO.getPlainAttr("photo"));
    // 3. read user on resource
    ConnObjectTO connObj = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObj);
    AttrTO registeredAddress = connObj.getAttr("registeredAddress").get();
    assertNotNull(registeredAddress);
    assertEquals(userTO.getPlainAttr("obscure").get().getValues(), registeredAddress.getValues());
    Optional<AttrTO> jpegPhoto = connObj.getAttr("jpegPhoto");
    assertTrue(jpegPhoto.isPresent());
    assertEquals(userTO.getPlainAttr("photo").get().getValues().get(0), jpegPhoto.get().getValues().get(0));
    // 4. remove group
    groupService.delete(groupTO.getKey());
    // 5. try to read user on resource: fail
    try {
        resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 5 with ConnObjectTO

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

the class UserIssuesITCase method issueSYNCOPE354.

@Test
public void issueSYNCOPE354() {
    // change resource-ldap group mapping for including uniqueMember (need for assertions below)
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    ldap.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getItems().stream().filter(item -> ("description".equals(item.getExtAttrName()))).forEachOrdered(item -> {
        item.setExtAttrName("uniqueMember");
    });
    resourceService.update(ldap);
    // 1. create group with LDAP resource
    GroupTO groupTO = new GroupTO();
    groupTO.setName("SYNCOPE354-" + getUUIDString());
    groupTO.setRealm("/");
    groupTO.getResources().add(RESOURCE_NAME_LDAP);
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    // 2. create user with LDAP resource and membership of the above group
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope354@syncope.apache.org");
    userTO.getResources().add(RESOURCE_NAME_LDAP);
    userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
    userTO = createUser(userTO).getEntity();
    assertTrue(userTO.getResources().contains(RESOURCE_NAME_LDAP));
    assertNotNull(resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey()));
    // 3. read group on resource, check that user DN is included in uniqueMember
    ConnObjectTO connObj = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
    assertNotNull(connObj);
    assertTrue(connObj.getAttr("uniqueMember").get().getValues().contains("uid=" + userTO.getUsername() + ",ou=people,o=isp"));
    // 4. remove membership
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.DELETE).group(userTO.getMemberships().get(0).getGroupKey()).build());
    userTO = updateUser(userPatch).getEntity();
    assertTrue(userTO.getResources().contains(RESOURCE_NAME_LDAP));
    // 5. read group on resource, check that user DN was removed from uniqueMember
    connObj = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
    assertNotNull(connObj);
    assertFalse(connObj.getAttr("uniqueMember").get().getValues().contains("uid=" + userTO.getUsername() + ",ou=people,o=isp"));
    // 6. user has still the LDAP resource assigned - SYNCOPE-1222
    userTO = userService.read(userTO.getKey());
    assertTrue(userTO.getResources().contains(RESOURCE_NAME_LDAP));
    assertNotNull(resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey()));
    // 7. restore original resource-ldap group mapping
    ldap.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getItems().stream().filter(item -> ("uniqueMember".equals(item.getExtAttrName()))).forEachOrdered(item -> {
        item.setExtAttrName("description");
    });
    resourceService.update(ldap);
}
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) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)31 Test (org.junit.jupiter.api.Test)24 UserTO (org.apache.syncope.common.lib.to.UserTO)20 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)11 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)9 GroupTO (org.apache.syncope.common.lib.to.GroupTO)9 ArrayList (java.util.ArrayList)8 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)8 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)7 Response (javax.ws.rs.core.Response)6 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)5 List (java.util.List)4 Optional (java.util.Optional)4 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)4 IOException (java.io.IOException)3 Map (java.util.Map)3 Set (java.util.Set)3