use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class PushTaskITCase method issueSYNCOPE598.
@Test
public void issueSYNCOPE598() {
// create a new group schema
PlainSchemaTO schemaTO = new PlainSchemaTO();
schemaTO.setKey("LDAPGroupName" + getUUIDString());
schemaTO.setType(AttrSchemaType.String);
schemaTO.setMandatoryCondition("true");
schemaTO = createSchema(SchemaType.PLAIN, schemaTO);
assertNotNull(schemaTO);
AnyTypeClassTO typeClass = new AnyTypeClassTO();
typeClass.setKey("SYNCOPE-598" + getUUIDString());
typeClass.getPlainSchemas().add(schemaTO.getKey());
anyTypeClassService.create(typeClass);
// create a new sample group
GroupTO groupTO = new GroupTO();
groupTO.setName("all" + getUUIDString());
groupTO.setRealm("/even");
groupTO.getAuxClasses().add(typeClass.getKey());
groupTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "all"));
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
String resourceName = "resource-ldap-grouponly";
ResourceTO newResourceTO = null;
try {
// Create resource ad-hoc
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceName);
resourceTO.setConnector("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.GROUP.name());
provisionTO.setObjectClass(ObjectClass.GROUP_NAME);
provisionTO.getAuxClasses().add(typeClass.getKey());
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setExtAttrName("cn");
item.setIntAttrName(schemaTO.getKey());
item.setConnObjectKey(true);
item.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(item);
mapping.setConnObjectLink("'cn=' + " + schemaTO.getKey() + " + ',ou=groups,o=isp'");
Response response = resourceService.create(resourceTO);
newResourceTO = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
assertNotNull(newResourceTO);
assertFalse(newResourceTO.getProvision(AnyTypeKind.USER.name()).isPresent());
assertNotNull(newResourceTO.getProvision(AnyTypeKind.GROUP.name()).get().getMapping());
// create push task ad-hoc
PushTaskTO task = new PushTaskTO();
task.setName("issueSYNCOPE598");
task.setActive(true);
task.setResource(resourceName);
task.setSourceRealm(SyncopeConstants.ROOT_REALM);
task.setPerformCreate(true);
task.setPerformDelete(true);
task.setPerformUpdate(true);
task.setUnmatchingRule(UnmatchingRule.ASSIGN);
task.setMatchingRule(MatchingRule.UPDATE);
task.getFilters().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupTO.getName()).query());
response = taskService.create(TaskType.PUSH, task);
PushTaskTO push = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
assertNotNull(push);
// execute the new task
ExecTO exec = execProvisioningTask(taskService, TaskType.PUSH, push.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
} finally {
groupService.delete(groupTO.getKey());
if (newResourceTO != null) {
resourceService.delete(resourceName);
}
}
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class AnyTypeClassITCase method deleteSchema.
@Test
public void deleteSchema() {
PlainSchemaTO newSchema = new PlainSchemaTO();
newSchema.setKey("newSchema" + getUUIDString());
newSchema.setType(AttrSchemaType.Date);
createSchema(SchemaType.PLAIN, newSchema);
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("new class" + getUUIDString());
newClass.getPlainSchemas().add(newSchema.getKey());
Response response = anyTypeClassService.create(newClass);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
assertNotNull(newClass);
assertTrue(newClass.getPlainSchemas().contains(newSchema.getKey()));
schemaService.delete(SchemaType.PLAIN, newSchema.getKey());
newClass = anyTypeClassService.read(newClass.getKey());
assertNotNull(newClass);
assertFalse(newClass.getPlainSchemas().contains(newSchema.getKey()));
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class AuthenticationITCase method anyTypeEntitlement.
@Test
public void anyTypeEntitlement() {
final String anyTypeKey = "FOLDER " + getUUIDString();
// 1. no entitlement exists (yet) for the any type to be created
assertFalse(syncopeService.platform().getEntitlements().stream().anyMatch(entitlement -> entitlement.contains(anyTypeKey)));
// 2. create plain schema, any type class and any type
PlainSchemaTO path = new PlainSchemaTO();
path.setKey("path" + getUUIDString());
path.setType(AttrSchemaType.String);
path = createSchema(SchemaType.PLAIN, path);
AnyTypeClassTO anyTypeClass = new AnyTypeClassTO();
anyTypeClass.setKey("folder" + getUUIDString());
anyTypeClass.getPlainSchemas().add(path.getKey());
anyTypeClassService.create(anyTypeClass);
AnyTypeTO anyTypeTO = new AnyTypeTO();
anyTypeTO.setKey(anyTypeKey);
anyTypeTO.setKind(AnyTypeKind.ANY_OBJECT);
anyTypeTO.getClasses().add(anyTypeClass.getKey());
anyTypeService.create(anyTypeTO);
// 2. now entitlement exists for the any type just created
assertTrue(syncopeService.platform().getEntitlements().stream().anyMatch(entitlement -> entitlement.contains(anyTypeKey)));
// 3. attempt to create an instance of the type above: fail because no entitlement was assigned
AnyObjectTO folder = new AnyObjectTO();
folder.setName("home");
folder.setRealm(SyncopeConstants.ROOT_REALM);
folder.setType(anyTypeKey);
folder.getPlainAttrs().add(attrTO(path.getKey(), "/home"));
SyncopeClient belliniClient = clientFactory.create("bellini", ADMIN_PWD);
try {
belliniClient.getService(AnyObjectService.class).create(folder);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
}
// 4. give create entitlement for the any type just created
RoleTO role = new RoleTO();
role.setKey("role" + getUUIDString());
role.getRealms().add(SyncopeConstants.ROOT_REALM);
role.getEntitlements().add(anyTypeKey + "_READ");
role.getEntitlements().add(anyTypeKey + "_CREATE");
role = createRole(role);
UserTO bellini = userService.read("bellini");
UserPatch patch = new UserPatch();
patch.setKey(bellini.getKey());
patch.getRoles().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(role.getKey()).build());
bellini = updateUser(patch).getEntity();
assertTrue(bellini.getRoles().contains(role.getKey()));
// 5. now the instance of the type above can be created successfully
belliniClient.logout();
belliniClient.login(new BasicAuthenticationHandler("bellini", ADMIN_PWD));
belliniClient.getService(AnyObjectService.class).create(folder);
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class ConfigurationITCase method createRequired.
@Test
public void createRequired() {
PlainSchemaTO testKey = new PlainSchemaTO();
testKey.setKey("testKey" + getUUIDString());
testKey.setType(AttrSchemaType.String);
testKey.setMandatoryCondition("true");
createSchema(SchemaType.PLAIN, testKey);
AttrTO conf = new AttrTO.Builder().schema(testKey.getKey()).build();
try {
configurationService.set(conf);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
}
conf.getValues().add("testValue");
configurationService.set(conf);
AttrTO actual = configurationService.get(conf.getSchema());
actual.setSchemaInfo(null);
assertEquals(actual, conf);
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class CamelRouteITCase method scriptingUpdate.
@Test
public void scriptingUpdate() {
assumeTrue(CamelDetector.isCamelEnabledForUsers(syncopeService));
CamelRouteTO oldRoute = camelRouteService.read(AnyTypeKind.USER, "createUser");
// updating route content including new attribute management
String routeContent = "" + " <route id=\"createUser\">\n" + " <from uri=\"direct:createUser\"/>\n" + " <setProperty propertyName=\"actual\">\n" + " <simple>${body}</simple>\n" + " </setProperty>\n" + " <setBody>\n" + " <groovy>\n" + "request.body.getPlainAttr(\"camelAttribute\").get().getValues().set(0,\"true\")\n" + " return request.body\n" + " </groovy>\n" + " </setBody>\n" + " <doTry>\n" + " <bean ref=\"uwfAdapter\" method=\"create(${body},${property.disablePwdPolicyCheck},\n" + " ${property.enabled},${property.storePassword})\"/>\n" + " <to uri=\"propagate:create?anyTypeKind=USER\"/>\n" + " <to uri=\"direct:createPort\"/>\n" + " <doCatch> \n" + " <exception>java.lang.RuntimeException</exception>\n" + " <handled>\n" + " <constant>false</constant>\n" + " </handled>\n" + " <to uri=\"direct:createPort\"/>\n" + " </doCatch>\n" + " </doTry>\n" + " </route> ";
try {
doUpdate(AnyTypeKind.USER, "createUser", routeContent);
// creating new schema attribute for user
PlainSchemaTO schemaTO = new PlainSchemaTO();
schemaTO.setKey("camelAttribute");
schemaTO.setType(AttrSchemaType.String);
createSchema(SchemaType.PLAIN, schemaTO);
AnyTypeClassTO typeClass = new AnyTypeClassTO();
typeClass.setKey("camelAttribute");
typeClass.getPlainSchemas().add(schemaTO.getKey());
anyTypeClassService.create(typeClass);
UserTO userTO = new UserTO();
userTO.setRealm(SyncopeConstants.ROOT_REALM);
userTO.getAuxClasses().add(typeClass.getKey());
String userId = getUUIDString() + "camelUser@syncope.apache.org";
userTO.setUsername(userId);
userTO.setPassword("password123");
userTO.getPlainAttrs().add(attrTO("userId", userId));
userTO.getPlainAttrs().add(attrTO("fullname", userId));
userTO.getPlainAttrs().add(attrTO("surname", userId));
userTO.getPlainAttrs().add(attrTO("camelAttribute", "false"));
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
assertEquals("true", userTO.getPlainAttr("camelAttribute").get().getValues().get(0));
} finally {
doUpdate(AnyTypeKind.USER, oldRoute.getKey(), oldRoute.getContent());
}
}
Aggregations