use of org.apache.syncope.common.lib.patch.StatusPatch in project syncope by apache.
the class AbstractAnyService method bulk.
@Override
public Response bulk(final BulkAction bulkAction) {
AbstractAnyLogic<TO, P> logic = getAnyLogic();
BulkActionResult result = new BulkActionResult();
switch(bulkAction.getType()) {
case MUSTCHANGEPASSWORD:
if (logic instanceof UserLogic) {
bulkAction.getTargets().forEach(key -> {
try {
final UserPatch userPatch = new UserPatch();
userPatch.setKey(key);
userPatch.setMustChangePassword(new BooleanReplacePatchItem.Builder().value(true).build());
result.getResults().put(((UserLogic) logic).update(userPatch, false).getEntity().getKey(), BulkActionResult.Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing delete for user {}", key, e);
result.getResults().put(key, BulkActionResult.Status.FAILURE);
}
});
} else {
throw new BadRequestException();
}
break;
case DELETE:
bulkAction.getTargets().forEach(key -> {
try {
result.getResults().put(logic.delete(key, isNullPriorityAsync()).getEntity().getKey(), BulkActionResult.Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing delete for user {}", key, e);
result.getResults().put(key, BulkActionResult.Status.FAILURE);
}
});
break;
case SUSPEND:
if (logic instanceof UserLogic) {
bulkAction.getTargets().forEach(key -> {
StatusPatch statusPatch = new StatusPatch.Builder().key(key).type(StatusPatchType.SUSPEND).onSyncope(true).build();
try {
result.getResults().put(((UserLogic) logic).status(statusPatch, isNullPriorityAsync()).getEntity().getKey(), BulkActionResult.Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing suspend for user {}", key, e);
result.getResults().put(key, BulkActionResult.Status.FAILURE);
}
});
} else {
throw new BadRequestException();
}
break;
case REACTIVATE:
if (logic instanceof UserLogic) {
bulkAction.getTargets().forEach(key -> {
StatusPatch statusPatch = new StatusPatch.Builder().key(key).type(StatusPatchType.REACTIVATE).onSyncope(true).build();
try {
result.getResults().put(((UserLogic) logic).status(statusPatch, isNullPriorityAsync()).getEntity().getKey(), BulkActionResult.Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing reactivate for user {}", key, e);
result.getResults().put(key, BulkActionResult.Status.FAILURE);
}
});
} else {
throw new BadRequestException();
}
break;
default:
}
return modificationResponse(result);
}
use of org.apache.syncope.common.lib.patch.StatusPatch in project syncope by apache.
the class UserITCase method createActivate.
@Test
public void createActivate() {
assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
UserTO userTO = getUniqueSampleTO("createActivate@syncope.apache.org");
userTO.getMemberships().add(new MembershipTO.Builder().group("268fed79-f440-4390-9435-b273768eb5d6").build());
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
assertNotNull(userTO.getToken());
assertNotNull(userTO.getTokenExpireTime());
assertEquals("created", userTO.getStatus());
StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.ACTIVATE).token(userTO.getToken()).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
assertNull(userTO.getToken());
assertNull(userTO.getTokenExpireTime());
assertEquals("active", userTO.getStatus());
}
use of org.apache.syncope.common.lib.patch.StatusPatch in project syncope by apache.
the class UserITCase method suspendReactivateOnResource.
@Test
public void suspendReactivateOnResource() {
// Assert resources are present
ResourceTO dbTable = resourceService.read(RESOURCE_NAME_TESTDB);
assertNotNull(dbTable);
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
assertNotNull(ldap);
// Create user with reference to resources
UserTO userTO = getUniqueSampleTO("suspreactonresource@syncope.apache.org");
userTO.getMemberships().clear();
userTO.getResources().clear();
userTO.getResources().add(RESOURCE_NAME_TESTDB);
userTO.getResources().add(RESOURCE_NAME_LDAP);
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
assertEquals(FlowableDetector.isFlowableEnabledForUsers(syncopeService) ? "active" : "created", userTO.getStatus());
String userKey = userTO.getKey();
// Suspend with effect on syncope, ldap and db => user should be suspended in syncope and all resources
StatusPatch statusPatch = new StatusPatch.Builder().key(userKey).type(StatusPatchType.SUSPEND).onSyncope(true).resources(RESOURCE_NAME_TESTDB, RESOURCE_NAME_LDAP).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
assertEquals("suspended", userTO.getStatus());
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userKey);
assertFalse(getBooleanAttribute(connObjectTO, OperationalAttributes.ENABLE_NAME));
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userKey);
assertNotNull(connObjectTO);
// Suspend and reactivate only on ldap => db and syncope should still show suspended
statusPatch = new StatusPatch.Builder().key(userKey).type(StatusPatchType.SUSPEND).onSyncope(false).resources(RESOURCE_NAME_LDAP).build();
userService.status(statusPatch);
statusPatch.setType(StatusPatchType.REACTIVATE);
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
assertEquals("suspended", userTO.getStatus());
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userKey);
assertFalse(getBooleanAttribute(connObjectTO, OperationalAttributes.ENABLE_NAME));
// Reactivate on syncope and db => syncope and db should show the user as active
statusPatch = new StatusPatch.Builder().key(userKey).type(StatusPatchType.REACTIVATE).onSyncope(true).resources(RESOURCE_NAME_TESTDB).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
assertEquals("active", userTO.getStatus());
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userKey);
assertTrue(getBooleanAttribute(connObjectTO, OperationalAttributes.ENABLE_NAME));
}
use of org.apache.syncope.common.lib.patch.StatusPatch in project syncope by apache.
the class UserITCase method suspendReactivate.
@Test
public void suspendReactivate() {
UserTO userTO = getUniqueSampleTO("suspendReactivate@syncope.apache.org");
userTO.getMemberships().add(new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
assertEquals(FlowableDetector.isFlowableEnabledForUsers(syncopeService) ? "active" : "created", userTO.getStatus());
StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.SUSPEND).token(userTO.getToken()).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
assertEquals("suspended", userTO.getStatus());
statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
assertEquals("active", userTO.getStatus());
}
use of org.apache.syncope.common.lib.patch.StatusPatch in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE260.
@Test
public void issueSYNCOPE260() {
// create new virtual schema for the resource below
ResourceTO ws2 = resourceService.read(RESOURCE_NAME_WS2);
ProvisionTO provision = ws2.getProvision(AnyTypeKind.USER.name()).get();
assertNotNull(provision);
VirSchemaTO virSchema = new VirSchemaTO();
virSchema.setKey("syncope260" + getUUIDString());
virSchema.setExtAttrName("companyName");
virSchema.setResource(RESOURCE_NAME_WS2);
virSchema.setAnyType(provision.getAnyType());
virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
assertNotNull(virSchema);
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("syncope260" + getUUIDString());
newClass.getVirSchemas().add(virSchema.getKey());
Response response = anyTypeClassService.create(newClass);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
// ----------------------------------
// create user and check virtual attribute value propagation
// ----------------------------------
UserTO userTO = UserITCase.getUniqueSampleTO("260@a.com");
userTO.getAuxClasses().add(newClass.getKey());
userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue"));
userTO.getResources().add(RESOURCE_NAME_WS2);
ProvisioningResult<UserTO> result = createUser(userTO);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// update user virtual attribute and check virtual attribute value update propagation
// ----------------------------------
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue2"));
result = updateUser(userPatch);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// suspend/reactivate user and check virtual attribute value (unchanged)
// ----------------------------------
StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.SUSPEND).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertEquals("suspended", userTO.getStatus());
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertEquals("active", userTO.getStatus());
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// update user attribute and check virtual attribute value (unchanged)
// ----------------------------------
userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "Surname2"));
result = updateUser(userPatch);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("Surname2", connObjectTO.getAttr("SURNAME").get().getValues().get(0));
// virtual attribute value did not change
assertFalse(connObjectTO.getAttr("COMPANYNAME").get().getValues().isEmpty());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
}
Aggregations