Search in sources :

Example 11 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE266.

@Test
public void issueSYNCOPE266() {
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope266@apache.org");
    userTO.getResources().clear();
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    // this resource has not a mapping for Password
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_UPDATE).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 12 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE505DB.

@Test
public void issueSYNCOPE505DB() throws Exception {
    // 1. create user
    UserTO user = UserITCase.getUniqueSampleTO("syncope505-db@syncope.apache.org");
    user.setPassword("security123");
    user = createUser(user).getEntity();
    assertNotNull(user);
    assertTrue(user.getResources().isEmpty());
    // 2. Add DBPasswordPropagationActions
    ImplementationTO propagationActions = new ImplementationTO();
    propagationActions.setKey(DBPasswordPropagationActions.class.getSimpleName());
    propagationActions.setEngine(ImplementationEngine.JAVA);
    propagationActions.setType(ImplementationType.PROPAGATION_ACTIONS);
    propagationActions.setBody(DBPasswordPropagationActions.class.getName());
    Response response = implementationService.create(propagationActions);
    propagationActions = implementationService.read(propagationActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    assertNotNull(propagationActions);
    ResourceTO resourceTO = resourceService.read(RESOURCE_NAME_TESTDB);
    assertNotNull(resourceTO);
    resourceTO.getPropagationActions().add(propagationActions.getKey());
    resourceService.update(resourceTO);
    // 3. Add a db resource to the User
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(user.getKey());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_TESTDB).build());
    userPatch.setPassword(new PasswordPatch.Builder().onSyncope(false).resource(RESOURCE_NAME_TESTDB).build());
    user = updateUser(userPatch).getEntity();
    assertNotNull(user);
    assertEquals(1, user.getResources().size());
    // 4. Check that the DB resource has the correct password
    JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
    String value = jdbcTemplate.queryForObject("SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
    assertEquals(Encryptor.getInstance().encode("security123", CipherAlgorithm.SHA1), value.toUpperCase());
    // 5. Remove DBPasswordPropagationActions
    resourceTO = resourceService.read(RESOURCE_NAME_TESTDB);
    assertNotNull(resourceTO);
    resourceTO.getPropagationActions().remove(propagationActions.getKey());
    resourceService.update(resourceTO);
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) DBPasswordPropagationActions(org.apache.syncope.core.provisioning.java.propagation.DBPasswordPropagationActions) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 13 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issue213.

@Test
public void issue213() {
    UserTO userTO = UserITCase.getUniqueSampleTO("issue213@syncope.apache.org");
    userTO.getResources().add(RESOURCE_NAME_TESTDB);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertEquals(1, userTO.getResources().size());
    JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
    String username = queryForObject(jdbcTemplate, 50, "SELECT id FROM test WHERE id=?", String.class, userTO.getUsername());
    assertEquals(userTO.getUsername(), username);
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(RESOURCE_NAME_TESTDB).build());
    userTO = updateUser(userPatch).getEntity();
    assertTrue(userTO.getResources().isEmpty());
    Exception exception = null;
    try {
        jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", String.class, userTO.getUsername());
    } catch (EmptyResultDataAccessException e) {
        exception = e;
    }
    assertNotNull(exception);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 14 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch 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 15 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issue280.

@Test
public void issue280() {
    UserTO userTO = UserITCase.getUniqueSampleTO("issue280@syncope.apache.org");
    userTO.getResources().clear();
    userTO.getMemberships().clear();
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().onSyncope(false).resource(RESOURCE_NAME_TESTDB).value("123password").build());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_TESTDB).build());
    ProvisioningResult<UserTO> result = updateUser(userPatch);
    assertNotNull(result);
    List<PropagationStatus> propagations = result.getPropagationStatuses();
    assertNotNull(propagations);
    assertEquals(1, propagations.size());
    assertEquals(PropagationTaskExecStatus.SUCCESS, propagations.get(0).getStatus());
    String resource = propagations.get(0).getResource();
    assertEquals(RESOURCE_NAME_TESTDB, resource);
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Aggregations

UserPatch (org.apache.syncope.common.lib.patch.UserPatch)102 UserTO (org.apache.syncope.common.lib.to.UserTO)73 Test (org.junit.jupiter.api.Test)59 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)37 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)18 AttrTO (org.apache.syncope.common.lib.to.AttrTO)17 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 Response (javax.ws.rs.core.Response)16 Map (java.util.Map)12 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)12 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)11 GroupTO (org.apache.syncope.common.lib.to.GroupTO)11 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)11 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)11 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)11 GenericType (javax.ws.rs.core.GenericType)10 Pair (org.apache.commons.lang3.tuple.Pair)10 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)10 List (java.util.List)9 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)9