Search in sources :

Example 1 with DBPasswordPropagationActions

use of org.apache.syncope.core.provisioning.java.propagation.DBPasswordPropagationActions 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)

Aggregations

Response (javax.ws.rs.core.Response)1 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)1 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)1 UserTO (org.apache.syncope.common.lib.to.UserTO)1 DBPasswordPropagationActions (org.apache.syncope.core.provisioning.java.propagation.DBPasswordPropagationActions)1 Test (org.junit.jupiter.api.Test)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1