Search in sources :

Example 16 with ProvisioningResult

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

the class RESTITCase method ifMatch.

@Test
public void ifMatch() {
    UserTO userTO = userService.create(UserITCase.getUniqueSampleTO("ifmatch@syncope.apache.org"), true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertNotNull(userTO.getKey());
    EntityTag etag = adminClient.getLatestEntityTag(userService);
    assertNotNull(etag);
    assertTrue(StringUtils.isNotBlank(etag.getValue()));
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setUsername(new StringReplacePatchItem.Builder().value(userTO.getUsername() + "XX").build());
    userTO = userService.update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertTrue(userTO.getUsername().endsWith("XX"));
    EntityTag etag1 = adminClient.getLatestEntityTag(userService);
    assertFalse(etag.getValue().equals(etag1.getValue()));
    UserService ifMatchService = adminClient.ifMatch(adminClient.getService(UserService.class), etag);
    userPatch.setUsername(new StringReplacePatchItem.Builder().value(userTO.getUsername() + "YY").build());
    try {
        ifMatchService.update(userPatch);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.ConcurrentModification, e.getType());
    }
    userTO = userService.read(userTO.getKey());
    assertTrue(userTO.getUsername().endsWith("XX"));
}
Also used : GenericType(javax.ws.rs.core.GenericType) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserService(org.apache.syncope.common.rest.api.service.UserService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) EntityTag(javax.ws.rs.core.EntityTag) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 17 with ProvisioningResult

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

the class RealmITCase method propagate.

@Test
public void propagate() {
    // 1. create realm and add the LDAP resource
    RealmTO realm = new RealmTO();
    realm.setName("test");
    realm.getResources().add(RESOURCE_NAME_LDAP_ORGUNIT);
    RealmTO childRealm = new RealmTO();
    childRealm.setName("child");
    childRealm.getResources().add(RESOURCE_NAME_LDAP_ORGUNIT);
    RealmTO descendantRealm = new RealmTO();
    descendantRealm.setName("test");
    descendantRealm.getResources().add(RESOURCE_NAME_LDAP_ORGUNIT);
    // 2. check propagation
    ProvisioningResult<RealmTO> result = realmService.create("/", realm).readEntity(new GenericType<ProvisioningResult<RealmTO>>() {
    });
    assertNotNull(result);
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(RESOURCE_NAME_LDAP_ORGUNIT, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    ProvisioningResult<RealmTO> resultChild = realmService.create("/test", childRealm).readEntity(new GenericType<ProvisioningResult<RealmTO>>() {
    });
    assertNotNull(resultChild);
    assertEquals(1, resultChild.getPropagationStatuses().size());
    assertEquals(RESOURCE_NAME_LDAP_ORGUNIT, resultChild.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, resultChild.getPropagationStatuses().get(0).getStatus());
    ProvisioningResult<RealmTO> resultDescendant = realmService.create("/test/child", descendantRealm).readEntity(new GenericType<ProvisioningResult<RealmTO>>() {
    });
    assertNotNull(resultDescendant);
    assertEquals(1, resultDescendant.getPropagationStatuses().size());
    assertEquals(RESOURCE_NAME_LDAP_ORGUNIT, resultDescendant.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, resultDescendant.getPropagationStatuses().get(0).getStatus());
    // 3. check on LDAP
    assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=test,o=isp"));
    assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=child,ou=test,o=isp"));
    assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=test,ou=child,ou=test,o=isp"));
    // 4. remove realms
    realmService.delete("/test/child/test");
    realmService.delete("/test/child");
    realmService.delete("/test");
    // 5. check on LDAP: both realms should be deleted
    assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=test,ou=child,ou=test,o=isp"));
    assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=child,ou=test,o=isp"));
    assertNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, "ou=test,o=isp"));
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) RealmTO(org.apache.syncope.common.lib.to.RealmTO) Test(org.junit.jupiter.api.Test)

Example 18 with ProvisioningResult

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

the class AuthenticationITCase method delegatedUserCRUD.

@Test
public void delegatedUserCRUD() {
    String roleKey = null;
    String delegatedAdminKey = null;
    try {
        // 1. create role for full user administration, under realm /even/two
        RoleTO role = new RoleTO();
        role.setKey("Delegated user admin");
        role.getEntitlements().add(StandardEntitlement.USER_CREATE);
        role.getEntitlements().add(StandardEntitlement.USER_UPDATE);
        role.getEntitlements().add(StandardEntitlement.USER_DELETE);
        role.getEntitlements().add(StandardEntitlement.USER_SEARCH);
        role.getEntitlements().add(StandardEntitlement.USER_READ);
        role.getRealms().add("/even/two");
        roleKey = roleService.create(role).getHeaderString(RESTHeaders.RESOURCE_KEY);
        assertNotNull(roleKey);
        // 2. as admin, create delegated admin user, and assign the role just created
        UserTO delegatedAdmin = UserITCase.getUniqueSampleTO("admin@syncope.apache.org");
        delegatedAdmin.getRoles().add(roleKey);
        delegatedAdmin = createUser(delegatedAdmin).getEntity();
        delegatedAdminKey = delegatedAdmin.getKey();
        // 3. instantiate a delegate user service client, for further operatins
        UserService delegatedUserService = clientFactory.create(delegatedAdmin.getUsername(), "password123").getService(UserService.class);
        // 4. as delegated, create user under realm / -> fail
        UserTO user = UserITCase.getUniqueSampleTO("delegated@syncope.apache.org");
        try {
            delegatedUserService.create(user, true);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
        }
        // 5. set realm to /even/two -> succeed
        user.setRealm("/even/two");
        Response response = delegatedUserService.create(user, true);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        user = response.readEntity(new GenericType<ProvisioningResult<UserTO>>() {
        }).getEntity();
        assertEquals("surname", user.getPlainAttr("surname").get().getValues().get(0));
        // 5. as delegated, update user attempting to move under realm / -> fail
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(user.getKey());
        userPatch.setRealm(new StringReplacePatchItem.Builder().value("/odd").build());
        userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "surname2"));
        try {
            delegatedUserService.update(userPatch);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
        }
        // 6. revert realm change -> succeed
        userPatch.setRealm(null);
        response = delegatedUserService.update(userPatch);
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
        user = response.readEntity(new GenericType<ProvisioningResult<UserTO>>() {
        }).getEntity();
        assertEquals("surname2", user.getPlainAttr("surname").get().getValues().get(0));
        // 7. as delegated, delete user
        delegatedUserService.delete(user.getKey());
        try {
            userService.read(user.getKey());
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.NotFound, e.getType());
        }
    } finally {
        if (roleKey != null) {
            roleService.delete(roleKey);
        }
        if (delegatedAdminKey != null) {
            userService.delete(delegatedAdminKey);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserService(org.apache.syncope.common.rest.api.service.UserService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RoleTO(org.apache.syncope.common.lib.to.RoleTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 19 with ProvisioningResult

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

the class AuthenticationITCase method checkUserSuspension.

@Test
public void checkUserSuspension() {
    UserTO userTO = UserITCase.getUniqueSampleTO("checkSuspension@syncope.apache.org");
    userTO.setRealm("/odd");
    userTO.getRoles().add("User manager");
    userTO = createUser(userTO).getEntity();
    String userKey = userTO.getKey();
    assertNotNull(userTO);
    assertEquals(0, getFailedLogins(userService, userKey));
    // authentications failed ...
    try {
        clientFactory.create(userTO.getUsername(), "wrongpwd1");
        fail("This should not happen");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    try {
        clientFactory.create(userTO.getUsername(), "wrongpwd1");
        fail("This should not happen");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    try {
        clientFactory.create(userTO.getUsername(), "wrongpwd1");
        fail("This should not happen");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    assertEquals(3, getFailedLogins(userService, userKey));
    // last authentication before suspension
    try {
        clientFactory.create(userTO.getUsername(), "wrongpwd1");
        fail("This should not happen");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    userTO = userService.read(userTO.getKey());
    assertNotNull(userTO);
    assertNotNull(userTO.getFailedLogins());
    assertEquals(3, userTO.getFailedLogins().intValue());
    assertEquals("suspended", userTO.getStatus());
    // Access with correct credentials should fail as user is suspended
    try {
        clientFactory.create(userTO.getUsername(), "password123");
        fail("This should not happen");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    StatusPatch reactivate = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
    userTO = userService.status(reactivate).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertEquals("active", userTO.getStatus());
    SyncopeClient goodPwdClient = clientFactory.create(userTO.getUsername(), "password123");
    assertEquals(0, goodPwdClient.self().getRight().getFailedLogins().intValue());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) AccessControlException(java.security.AccessControlException) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Test(org.junit.jupiter.api.Test)

Example 20 with ProvisioningResult

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

the class GroupITCase method updateAsGroupOwner.

@Test
public void updateAsGroupOwner() {
    // 1. read group as admin
    GroupTO groupTO = groupService.read("ebf97068-aa4b-4a85-9f01-680e8c4cf227");
    // issue SYNCOPE-15
    assertNotNull(groupTO.getCreationDate());
    assertNotNull(groupTO.getLastChangeDate());
    assertEquals("admin", groupTO.getCreator());
    assertEquals("admin", groupTO.getLastModifier());
    // 2. prepare update
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.setName(new StringReplacePatchItem.Builder().value("Director").build());
    // 3. try to update as verdi, not owner of group 6 - fail
    GroupService groupService2 = clientFactory.create("verdi", ADMIN_PWD).getService(GroupService.class);
    try {
        groupService2.update(groupPatch);
        fail("This should not happen");
    } catch (ForbiddenException e) {
        assertNotNull(e);
    }
    // 4. update as puccini, owner of group 6 - success
    GroupService groupService3 = clientFactory.create("puccini", ADMIN_PWD).getService(GroupService.class);
    groupTO = groupService3.update(groupPatch).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
    }).getEntity();
    assertEquals("Director", groupTO.getName());
    // issue SYNCOPE-15
    assertNotNull(groupTO.getCreationDate());
    assertNotNull(groupTO.getLastChangeDate());
    assertEquals("admin", groupTO.getCreator());
    assertEquals("puccini", groupTO.getLastModifier());
    assertTrue(groupTO.getCreationDate().before(groupTO.getLastChangeDate()));
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) GroupService(org.apache.syncope.common.rest.api.service.GroupService) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)39 UserTO (org.apache.syncope.common.lib.to.UserTO)24 Test (org.junit.jupiter.api.Test)21 GroupTO (org.apache.syncope.common.lib.to.GroupTO)14 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 Response (javax.ws.rs.core.Response)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)8 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)8 UserService (org.apache.syncope.common.rest.api.service.UserService)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 GenericType (javax.ws.rs.core.GenericType)6 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)6 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)5 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)4 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)4