Search in sources :

Example 1 with StatusPatch

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

the class StatusProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if (getAnyTypeKind() == AnyTypeKind.USER && isPull()) {
        WorkflowResult<Map.Entry<UserPatch, Boolean>> updated = (WorkflowResult<Entry<UserPatch, Boolean>>) exchange.getIn().getBody();
        Boolean enabled = exchange.getProperty("enabled", Boolean.class);
        String key = exchange.getProperty("key", String.class);
        if (enabled != null) {
            User user = userDAO.find(key);
            WorkflowResult<String> enableUpdate = null;
            if (user.isSuspended() == null) {
                enableUpdate = uwfAdapter.activate(key, null);
            } else if (enabled && user.isSuspended()) {
                enableUpdate = uwfAdapter.reactivate(key);
            } else if (!enabled && !user.isSuspended()) {
                enableUpdate = uwfAdapter.suspend(key);
            }
            if (enableUpdate != null) {
                if (enableUpdate.getPropByRes() != null) {
                    updated.getPropByRes().merge(enableUpdate.getPropByRes());
                    updated.getPropByRes().purge();
                }
                updated.getPerformedTasks().addAll(enableUpdate.getPerformedTasks());
            }
        }
    } else if (getAnyTypeKind() == AnyTypeKind.USER) {
        WorkflowResult<Long> updated = (WorkflowResult<Long>) exchange.getIn().getBody();
        StatusPatch statusPatch = exchange.getProperty("statusPatch", StatusPatch.class);
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, statusPatch.getResources());
        List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(AnyTypeKind.USER, statusPatch.getKey(), false, statusPatch.getType() != StatusPatchType.SUSPEND, propByRes, null, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Entry(java.util.Map.Entry) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) List(java.util.List)

Example 2 with StatusPatch

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

the class AbstractAnyRestClient method provision.

public BulkActionResult provision(final String etag, final String key, final List<StatusBean> statuses) {
    BulkActionResult result;
    synchronized (this) {
        AnyService<?> service = getService(etag, getAnyServiceClass());
        StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses);
        AssociationPatch associationPatch = new AssociationPatch.Builder().key(key).action(ResourceAssociationAction.PROVISION).onSyncope(statusPatch.isOnSyncope()).resources(statusPatch.getResources()).build();
        result = service.associate(associationPatch).readEntity(BulkActionResult.class);
        resetClient(getAnyServiceClass());
    }
    return result;
}
Also used : StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch)

Example 3 with StatusPatch

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

the class AbstractAnyRestClient method assign.

public BulkActionResult assign(final String etag, final String key, final List<StatusBean> statuses) {
    BulkActionResult result;
    synchronized (this) {
        AnyService<?> service = getService(etag, getAnyServiceClass());
        StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses);
        AssociationPatch associationPatch = new AssociationPatch.Builder().key(key).action(ResourceAssociationAction.ASSIGN).onSyncope(statusPatch.isOnSyncope()).resources(statusPatch.getResources()).build();
        result = service.associate(associationPatch).readEntity(BulkActionResult.class);
        resetClient(getAnyServiceClass());
    }
    return result;
}
Also used : StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch)

Example 4 with StatusPatch

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

the class UserRestClient method suspend.

public BulkActionResult suspend(final String etag, final String userKey, final List<StatusBean> statuses) {
    StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses, false);
    statusPatch.setKey(userKey);
    statusPatch.setType(StatusPatchType.SUSPEND);
    BulkActionResult result;
    synchronized (this) {
        result = new BulkActionResult();
        Map<String, BulkActionResult.Status> res = result.getResults();
        UserService service = getService(etag, UserService.class);
        @SuppressWarnings("unchecked") ProvisioningResult<UserTO> provisions = (ProvisioningResult<UserTO>) service.status(statusPatch).readEntity(ProvisioningResult.class);
        if (statusPatch.isOnSyncope()) {
            res.put(StringUtils.capitalize(Constants.SYNCOPE), "suspended".equalsIgnoreCase(provisions.getEntity().getStatus()) ? BulkActionResult.Status.SUCCESS : BulkActionResult.Status.FAILURE);
        }
        for (PropagationStatus status : provisions.getPropagationStatuses()) {
            res.put(status.getResource(), BulkActionResult.Status.valueOf(status.getStatus().name()));
        }
        resetClient(UserService.class);
    }
    return result;
}
Also used : PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) 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) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult)

Example 5 with StatusPatch

use of org.apache.syncope.common.lib.patch.StatusPatch 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)

Aggregations

StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)12 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)7 UserTO (org.apache.syncope.common.lib.to.UserTO)7 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)6 Test (org.junit.jupiter.api.Test)5 AssociationPatch (org.apache.syncope.common.lib.patch.AssociationPatch)3 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)3 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)2 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)2 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)2 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)2 UserService (org.apache.syncope.common.rest.api.service.UserService)2 AccessControlException (java.security.AccessControlException)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 BadRequestException (javax.ws.rs.BadRequestException)1 Response (javax.ws.rs.core.Response)1 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)1 BooleanReplacePatchItem (org.apache.syncope.common.lib.patch.BooleanReplacePatchItem)1 AnyTO (org.apache.syncope.common.lib.to.AnyTO)1