use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class ImplementationITCase method delete.
@Test
public void delete() {
ImplementationTO implementationTO = new ImplementationTO();
implementationTO.setKey(UUID.randomUUID().toString());
implementationTO.setEngine(ImplementationEngine.JAVA);
implementationTO.setType(ImplementationType.PULL_ACTIONS);
implementationTO.setBody(TestPullActions.class.getName());
implementationService.create(implementationTO);
PullTaskTO pullTask = taskService.read(TaskType.PULL, AbstractTaskITCase.PULL_TASK_KEY, false);
assertNotNull(pullTask);
int before = pullTask.getActions().size();
pullTask.getActions().add(implementationTO.getKey());
taskService.update(TaskType.PULL, pullTask);
pullTask = taskService.read(TaskType.PULL, AbstractTaskITCase.PULL_TASK_KEY, false);
assertNotNull(pullTask);
int after = pullTask.getActions().size();
assertEquals(before + 1, after);
// fails because the implementation is used
try {
implementationService.delete(implementationTO.getType(), implementationTO.getKey());
fail("Unexpected");
} catch (SyncopeClientException e) {
assertEquals(e.getType(), ClientExceptionType.InUse);
}
pullTask.getActions().remove(implementationTO.getKey());
taskService.update(TaskType.PULL, pullTask);
implementationService.delete(implementationTO.getType(), implementationTO.getKey());
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class ImplementationITCase method create.
@Test
public void create() {
ImplementationTO implementationTO = new ImplementationTO();
implementationTO.setKey(UUID.randomUUID().toString());
implementationTO.setEngine(ImplementationEngine.JAVA);
implementationTO.setType(ImplementationType.PUSH_ACTIONS);
implementationTO.setBody(TestPullActions.class.getName());
// fail because type is wrong
try {
implementationService.create(implementationTO);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidImplementation, e.getType());
}
implementationTO.setType(ImplementationType.PULL_ACTIONS);
Response response = implementationService.create(implementationTO);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
if (ex != null) {
throw (RuntimeException) ex;
}
}
ImplementationTO actual = implementationService.read(implementationTO.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(actual);
assertEquals(actual, implementationTO);
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class ImplementationServiceImpl method create.
@Override
public Response create(final ImplementationTO implementationTO) {
ImplementationTO created = logic.create(implementationTO);
URI location = uriInfo.getAbsolutePathBuilder().path(String.valueOf(created.getKey())).build();
return Response.created(location).header(RESTHeaders.RESOURCE_KEY, created.getKey()).build();
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class UserIssuesITCase method issueSYNCOPE420.
@Test
public void issueSYNCOPE420() throws IOException {
ImplementationTO logicActions = new ImplementationTO();
logicActions.setKey("DoubleValueLogicActions");
logicActions.setEngine(ImplementationEngine.GROOVY);
logicActions.setType(ImplementationType.LOGIC_ACTIONS);
logicActions.setBody(org.apache.commons.io.IOUtils.toString(getClass().getResourceAsStream("/DoubleValueLogicActions.groovy"), StandardCharsets.UTF_8));
Response response = implementationService.create(logicActions);
logicActions = implementationService.read(logicActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(logicActions);
RealmTO realm = realmService.list("/even/two").iterator().next();
assertNotNull(realm);
realm.getActions().add(logicActions.getKey());
realmService.update(realm);
UserTO userTO = UserITCase.getUniqueSampleTO("syncope420@syncope.apache.org");
userTO.setRealm(realm.getFullPath());
userTO.getPlainAttrs().add(attrTO("makeItDouble", "3"));
userTO = createUser(userTO).getEntity();
assertEquals("6", userTO.getPlainAttr("makeItDouble").get().getValues().get(0));
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(attrAddReplacePatch("makeItDouble", "7"));
userTO = updateUser(userPatch).getEntity();
assertEquals("14", userTO.getPlainAttr("makeItDouble").get().getValues().get(0));
}
use of org.apache.syncope.common.lib.to.ImplementationTO 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);
}
Aggregations