Search in sources :

Example 11 with AnyTypeTO

use of org.apache.syncope.common.lib.to.AnyTypeTO in project syncope by apache.

the class AnyTypeITCase method deleteTypeClass.

@Test
public void deleteTypeClass() {
    AnyTypeClassTO newClass = new AnyTypeClassTO();
    newClass.setKey("new class" + getUUIDString());
    newClass.getDerSchemas().add("cn");
    Response response = anyTypeClassService.create(newClass);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
    newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
    assertNotNull(newClass);
    AnyTypeTO other = anyTypeService.read("PRINTER");
    assertNotNull(other);
    other.getClasses().add(newClass.getKey());
    anyTypeService.update(other);
    other = anyTypeService.read(other.getKey());
    assertNotNull(other);
    assertTrue(other.getClasses().contains(newClass.getKey()));
    anyTypeClassService.delete(newClass.getKey());
    other = anyTypeService.read(other.getKey());
    assertNotNull(other);
    assertFalse(other.getClasses().contains(newClass.getKey()));
}
Also used : Response(javax.ws.rs.core.Response) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 12 with AnyTypeTO

use of org.apache.syncope.common.lib.to.AnyTypeTO in project syncope by apache.

the class AnyTypeITCase method createInvalidName.

@Test
public void createInvalidName() {
    AnyTypeTO newType = new AnyTypeTO();
    newType.setKey("GROUP");
    newType.setKind(AnyTypeKind.GROUP);
    try {
        anyTypeService.create(newType);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.EntityExists, e.getType());
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) Test(org.junit.jupiter.api.Test)

Example 13 with AnyTypeTO

use of org.apache.syncope.common.lib.to.AnyTypeTO in project syncope by apache.

the class AnyTypeITCase method crud.

@Test
public void crud() {
    AnyTypeTO newType = new AnyTypeTO();
    newType.setKey("new type");
    newType.setKind(AnyTypeKind.ANY_OBJECT);
    newType.getClasses().add("generic membership");
    newType.getClasses().add("csv");
    Response response = anyTypeService.create(newType);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
    newType = getObject(response.getLocation(), AnyTypeService.class, AnyTypeTO.class);
    assertNotNull(newType);
    assertEquals(2, newType.getClasses().size());
    assertTrue(newType.getClasses().contains("generic membership"));
    assertTrue(newType.getClasses().contains("csv"));
    newType.getClasses().remove("generic membership");
    anyTypeService.update(newType);
    newType = anyTypeService.read(newType.getKey());
    assertNotNull(newType);
    assertEquals(1, newType.getClasses().size());
    assertTrue(newType.getClasses().contains("csv"));
    anyTypeService.delete(newType.getKey());
    try {
        anyTypeService.read(newType.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
}
Also used : Response(javax.ws.rs.core.Response) AnyTypeService(org.apache.syncope.common.rest.api.service.AnyTypeService) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) Test(org.junit.jupiter.api.Test)

Example 14 with AnyTypeTO

use of org.apache.syncope.common.lib.to.AnyTypeTO 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 15 with AnyTypeTO

use of org.apache.syncope.common.lib.to.AnyTypeTO in project syncope by apache.

the class GroupITCase method createWithMandatorySchema.

@Test
public void createWithMandatorySchema() {
    // 1. create a mandatory schema
    PlainSchemaTO badge = new PlainSchemaTO();
    badge.setKey("badge" + getUUIDString());
    badge.setMandatoryCondition("true");
    schemaService.create(SchemaType.PLAIN, badge);
    // 2. create a group *without* an attribute for that schema: it works
    GroupTO groupTO = getSampleTO("lastGroup");
    assertFalse(groupTO.getPlainAttr(badge.getKey()).isPresent());
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertFalse(groupTO.getPlainAttr(badge.getKey()).isPresent());
    // 3. add the new mandatory schema to the default group type
    AnyTypeTO type = anyTypeService.read(AnyTypeKind.GROUP.name());
    String typeClassName = type.getClasses().get(0);
    AnyTypeClassTO typeClass = anyTypeClassService.read(typeClassName);
    typeClass.getPlainSchemas().add(badge.getKey());
    anyTypeClassService.update(typeClass);
    typeClass = anyTypeClassService.read(typeClassName);
    assertTrue(typeClass.getPlainSchemas().contains(badge.getKey()));
    try {
        // 4. update group: failure since no values are provided and it is mandatory
        GroupPatch groupPatch = new GroupPatch();
        groupPatch.setKey(groupTO.getKey());
        try {
            updateGroup(groupPatch);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
        }
        // 5. also add an actual attribute for badge - it will work
        groupPatch.getPlainAttrs().add(attrAddReplacePatch(badge.getKey(), "xxxxxxxxxx"));
        groupTO = updateGroup(groupPatch).getEntity();
        assertNotNull(groupTO);
        assertNotNull(groupTO.getPlainAttr(badge.getKey()));
    } finally {
        // restore the original group class
        typeClass.getPlainSchemas().remove(badge.getKey());
        anyTypeClassService.update(typeClass);
        typeClass = anyTypeClassService.read(typeClassName);
        assertFalse(typeClass.getPlainSchemas().contains(badge.getKey()));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)18 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 Test (org.junit.jupiter.api.Test)9 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)6 ArrayList (java.util.ArrayList)5 Response (javax.ws.rs.core.Response)4 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)4 EntityTO (org.apache.syncope.common.lib.to.EntityTO)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 AnyTypeClassRestClient (org.apache.syncope.client.console.rest.AnyTypeClassRestClient)2 AnyTypeRestClient (org.apache.syncope.client.console.rest.AnyTypeRestClient)2 ActionsPanel (org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel)2 WizardMgtPanel (org.apache.syncope.client.console.wizards.WizardMgtPanel)2 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)2 RoleTO (org.apache.syncope.common.lib.to.RoleTO)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 VirSchemaTO (org.apache.syncope.common.lib.to.VirSchemaTO)2