Search in sources :

Example 1 with DerSchemaTO

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

the class DerAttrs method setAttrs.

@Override
protected void setAttrs(final MembershipTO membershipTO) {
    List<AttrTO> attrs = new ArrayList<>();
    Map<String, AttrTO> attrMap = EntityTOUtils.buildAttrMap(anyTO.getDerAttrs());
    for (DerSchemaTO schema : membershipSchemas.get(membershipTO.getGroupKey()).values()) {
        AttrTO attrTO = new AttrTO();
        attrTO.setSchema(schema.getKey());
        if (attrMap.containsKey(schema.getKey())) {
            attrTO.getValues().addAll(attrMap.get(schema.getKey()).getValues());
        }
        attrs.add(attrTO);
    }
    membershipTO.getDerAttrs().clear();
    membershipTO.getDerAttrs().addAll(attrs);
}
Also used : AttrTO(org.apache.syncope.common.lib.to.AttrTO) ArrayList(java.util.ArrayList) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO)

Example 2 with DerSchemaTO

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

the class DerSchemaITCase method issueSYNCOPE418.

@Test
public void issueSYNCOPE418() {
    DerSchemaTO schema = new DerSchemaTO();
    schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
    schema.setExpression("derived_sx + '_' + derived_dx");
    try {
        createSchema(SchemaType.DERIVED, schema);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidDerSchema, e.getType());
        assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidKey.name()));
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) Test(org.junit.jupiter.api.Test)

Example 3 with DerSchemaTO

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

the class NotificationWizardBuilder method getSchemas.

private List<String> getSchemas() {
    AnyTypeTO type = null;
    try {
        type = anyTypeRestClient.read(AnyTypeKind.USER.name());
    } catch (SyncopeClientException e) {
        LOG.error("While reading all any types", e);
    }
    String[] anyTypeClasses = type == null ? new String[0] : type.getClasses().toArray(new String[] {});
    List<String> result = new ArrayList<>();
    result.add("username");
    result.addAll(schemaRestClient.<PlainSchemaTO>getSchemas(SchemaType.PLAIN, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
    result.addAll(schemaRestClient.<DerSchemaTO>getSchemas(SchemaType.DERIVED, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
    result.addAll(schemaRestClient.<VirSchemaTO>getSchemas(SchemaType.VIRTUAL, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
    Collections.sort(result);
    return result;
}
Also used : EntityTO(org.apache.syncope.common.lib.to.EntityTO) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ArrayList(java.util.ArrayList) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO)

Example 4 with DerSchemaTO

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

the class SchemaLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_UPDATE + "')")
public <T extends SchemaTO> void update(final SchemaType schemaType, final T schemaTO) {
    if (!doesSchemaExist(schemaType, schemaTO.getKey())) {
        throw new NotFoundException(schemaType + "/" + schemaTO.getKey());
    }
    switch(schemaType) {
        case VIRTUAL:
            VirSchema virSchema = virSchemaDAO.find(schemaTO.getKey());
            if (virSchema == null) {
                throw new NotFoundException("Virtual Schema '" + schemaTO.getKey() + "'");
            }
            virSchemaDAO.save(binder.update((VirSchemaTO) schemaTO, virSchema));
            break;
        case DERIVED:
            DerSchema derSchema = derSchemaDAO.find(schemaTO.getKey());
            if (derSchema == null) {
                throw new NotFoundException("Derived schema '" + schemaTO.getKey() + "'");
            }
            derSchemaDAO.save(binder.update((DerSchemaTO) schemaTO, derSchema));
            break;
        case PLAIN:
        default:
            PlainSchema plainSchema = plainSchemaDAO.find(schemaTO.getKey());
            if (plainSchema == null) {
                throw new NotFoundException("Schema '" + schemaTO.getKey() + "'");
            }
            plainSchemaDAO.save(binder.update((PlainSchemaTO) schemaTO, plainSchema));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with DerSchemaTO

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

the class AnyTypeClassITCase method crud.

@Test
public void crud() {
    // 1. create sample schemas
    PlainSchemaTO plainSchema = new PlainSchemaTO();
    plainSchema.setKey("new_plain_schema" + getUUIDString());
    plainSchema.setType(AttrSchemaType.String);
    plainSchema = createSchema(SchemaType.PLAIN, plainSchema);
    DerSchemaTO derSchema = new DerSchemaTO();
    derSchema.setKey("new_der_schema" + getUUIDString());
    derSchema.setExpression(plainSchema.getKey() + " + '_' + derived_dx");
    derSchema = createSchema(SchemaType.DERIVED, derSchema);
    // 2. actual CRUD
    AnyTypeClassTO newClass = new AnyTypeClassTO();
    newClass.setKey("new class" + getUUIDString());
    newClass.getPlainSchemas().add(plainSchema.getKey());
    Response response = anyTypeClassService.create(newClass);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
    newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
    assertNotNull(newClass);
    assertFalse(newClass.getPlainSchemas().isEmpty());
    assertTrue(newClass.getDerSchemas().isEmpty());
    assertTrue(newClass.getVirSchemas().isEmpty());
    newClass.getDerSchemas().add(derSchema.getKey());
    anyTypeClassService.update(newClass);
    newClass = anyTypeClassService.read(newClass.getKey());
    assertNotNull(newClass);
    assertFalse(newClass.getPlainSchemas().isEmpty());
    assertFalse(newClass.getDerSchemas().isEmpty());
    assertTrue(newClass.getVirSchemas().isEmpty());
    assertEquals(newClass.getKey(), schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
    assertEquals(newClass.getKey(), schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
    anyTypeClassService.delete(newClass.getKey());
    try {
        anyTypeClassService.read(newClass.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    assertNull(schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
    assertNull(schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
}
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) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Aggregations

DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)14 Test (org.junit.jupiter.api.Test)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)4 VirSchemaTO (org.apache.syncope.common.lib.to.VirSchemaTO)3 ArrayList (java.util.ArrayList)2 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)2 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)2 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 AccessControlException (java.security.AccessControlException)1 NamingException (javax.naming.NamingException)1 DirContext (javax.naming.directory.DirContext)1 SearchControls (javax.naming.directory.SearchControls)1 SearchResult (javax.naming.directory.SearchResult)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 Response (javax.ws.rs.core.Response)1 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)1 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)1 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)1