Search in sources :

Example 1 with LDAPPasswordPropagationActions

use of org.apache.syncope.core.provisioning.java.propagation.LDAPPasswordPropagationActions in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE505LDAP.

@Test
public void issueSYNCOPE505LDAP() throws Exception {
    // 1. create user
    UserTO user = UserITCase.getUniqueSampleTO("syncope505-ldap@syncope.apache.org");
    user.setPassword("security123");
    user = createUser(user).getEntity();
    assertNotNull(user);
    assertTrue(user.getResources().isEmpty());
    // 2. Add LDAPPasswordPropagationActions
    ImplementationTO propagationActions = new ImplementationTO();
    propagationActions.setKey(LDAPPasswordPropagationActions.class.getSimpleName());
    propagationActions.setEngine(ImplementationEngine.JAVA);
    propagationActions.setType(ImplementationType.PROPAGATION_ACTIONS);
    propagationActions.setBody(LDAPPasswordPropagationActions.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_LDAP);
    assertNotNull(resourceTO);
    resourceTO.getPropagationActions().add(propagationActions.getKey());
    resourceTO.setRandomPwdIfNotProvided(false);
    resourceService.update(resourceTO);
    // 3. Add a 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_LDAP).build());
    userPatch.setPassword(new PasswordPatch.Builder().onSyncope(false).resource(RESOURCE_NAME_LDAP).build());
    user = updateUser(userPatch).getEntity();
    assertNotNull(user);
    assertEquals(1, user.getResources().size());
    // 4. Check that the LDAP resource has the correct password
    ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
    assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), "security123", connObject.getAttr(Name.NAME).get().getValues().get(0)));
    // 5. Remove LDAPPasswordPropagationActions
    resourceTO = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotNull(resourceTO);
    resourceTO.getPropagationActions().remove(propagationActions.getKey());
    resourceTO.setRandomPwdIfNotProvided(true);
    resourceService.update(resourceTO);
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) LDAPPasswordPropagationActions(org.apache.syncope.core.provisioning.java.propagation.LDAPPasswordPropagationActions) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) 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)

Aggregations

Response (javax.ws.rs.core.Response)1 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)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 LDAPPasswordPropagationActions (org.apache.syncope.core.provisioning.java.propagation.LDAPPasswordPropagationActions)1 Test (org.junit.jupiter.api.Test)1