Search in sources :

Example 26 with PlainSchemaTO

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);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ExecTO(org.apache.syncope.common.lib.to.ExecTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 27 with PlainSchemaTO

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()));
}
Also used : Response(javax.ws.rs.core.Response) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 28 with PlainSchemaTO

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);
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ResourceDeassociationAction(org.apache.syncope.common.lib.types.ResourceDeassociationAction) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Pair(org.apache.commons.lang3.tuple.Pair) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) Map(java.util.Map) RESTHeaders(org.apache.syncope.common.rest.api.RESTHeaders) PagedResult(org.apache.syncope.common.lib.to.PagedResult) FlowableDetector(org.apache.syncope.fit.FlowableDetector) BasicAuthenticationHandler(org.apache.syncope.client.lib.BasicAuthenticationHandler) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) SchemaService(org.apache.syncope.common.rest.api.service.SchemaService) Set(java.util.Set) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) Collectors(java.util.stream.Collectors) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) Response(javax.ws.rs.core.Response) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AccessControlException(java.security.AccessControlException) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) AnonymousAuthenticationHandler(org.apache.syncope.client.lib.AnonymousAuthenticationHandler) UserService(org.apache.syncope.common.rest.api.service.UserService) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) RoleTO(org.apache.syncope.common.lib.to.RoleTO) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) DataSource(javax.sql.DataSource) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) AnyObjectService(org.apache.syncope.common.rest.api.service.AnyObjectService) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Encryptor(org.apache.syncope.core.spring.security.Encryptor) ForbiddenException(javax.ws.rs.ForbiddenException) StatusPatchType(org.apache.syncope.common.lib.types.StatusPatchType) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) RoleTO(org.apache.syncope.common.lib.to.RoleTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectService(org.apache.syncope.common.rest.api.service.AnyObjectService) UserTO(org.apache.syncope.common.lib.to.UserTO) BasicAuthenticationHandler(org.apache.syncope.client.lib.BasicAuthenticationHandler) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 29 with PlainSchemaTO

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);
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 30 with PlainSchemaTO

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());
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) UserTO(org.apache.syncope.common.lib.to.UserTO) CamelRouteTO(org.apache.syncope.common.lib.to.CamelRouteTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Aggregations

PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)39 Test (org.junit.jupiter.api.Test)26 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)19 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)11 UserTO (org.apache.syncope.common.lib.to.UserTO)9 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6 Response (javax.ws.rs.core.Response)5 IOException (java.io.IOException)4 Set (java.util.Set)4 StandardCharsets (java.nio.charset.StandardCharsets)3 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)3 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)3 GroupTO (org.apache.syncope.common.lib.to.GroupTO)3 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)3 SchemaService (org.apache.syncope.common.rest.api.service.SchemaService)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 ListIterator (java.util.ListIterator)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2