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()));
}
}
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;
}
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;
}
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;
}
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());
}
Aggregations