Search in sources :

Example 56 with AttrTO

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

the class ConfigurationITCase method delete.

@Test
public void delete() throws UnsupportedEncodingException {
    try {
        configurationService.delete("nonExistent");
        fail("The delete operation should throw an exception because of nonExistent schema");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
    AttrTO tokenLength = configurationService.get("token.length");
    configurationService.delete("token.length");
    AttrTO actual = configurationService.get(tokenLength.getSchema());
    assertNotEquals(actual, tokenLength);
    configurationService.set(tokenLength);
    actual = configurationService.get(tokenLength.getSchema());
    assertEquals(actual, tokenLength);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Test(org.junit.jupiter.api.Test)

Example 57 with AttrTO

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

the class ConfigurationITCase method update.

@Test
public void update() {
    AttrTO expireTime = configurationService.get("token.expireTime");
    int value = Integer.parseInt(expireTime.getValues().get(0));
    value++;
    expireTime.getValues().set(0, value + "");
    configurationService.set(expireTime);
    AttrTO newConfigurationTO = configurationService.get(expireTime.getSchema());
    assertEquals(expireTime, newConfigurationTO);
}
Also used : AttrTO(org.apache.syncope.common.lib.to.AttrTO) Test(org.junit.jupiter.api.Test)

Example 58 with AttrTO

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

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

the class DefaultGroupProvisioningManager method create.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public Pair<String, List<PropagationStatus>> create(final GroupTO groupTO, final Map<String, String> groupOwnerMap, final Set<String> excludedResources, final boolean nullPriorityAsync) {
    WorkflowResult<String> created = gwfAdapter.create(groupTO);
    // see ConnObjectUtils#getAnyTOFromConnObject for GroupOwnerSchema
    Optional<AttrTO> groupOwner = groupTO.getPlainAttr(StringUtils.EMPTY);
    if (groupOwner.isPresent()) {
        groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
    }
    List<PropagationTaskTO> tasks = propagationManager.getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), groupTO.getVirAttrs(), excludedResources);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
    return Pair.of(created.getResult(), propagationReporter.getStatuses());
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with AttrTO

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

the class AbstractAnyDataBinder method fill.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void fill(final Any any, final AnyTO anyTO, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
    // 0. aux classes
    any.getAuxClasses().clear();
    anyTO.getAuxClasses().stream().map(className -> anyTypeClassDAO.find(className)).forEachOrdered(auxClass -> {
        if (auxClass == null) {
            LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", auxClass);
        } else {
            any.add(auxClass);
        }
    });
    // 1. attributes
    SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
    anyTO.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty()).forEach(attrTO -> {
        PlainSchema schema = getPlainSchema(attrTO.getSchema());
        if (schema != null) {
            PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
            if (attr == null) {
                attr = anyUtils.newPlainAttr();
                ((PlainAttr) attr).setOwner(any);
                attr.setSchema(schema);
            }
            fillAttr(attrTO.getValues(), anyUtils, schema, attr, invalidValues);
            if (attr.getValuesAsStrings().isEmpty()) {
                attr.setOwner(null);
            } else {
                any.add(attr);
            }
        }
    });
    if (!invalidValues.isEmpty()) {
        scce.addException(invalidValues);
    }
    SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
    // 2. resources
    anyTO.getResources().forEach(resourceKey -> {
        ExternalResource resource = resourceDAO.find(resourceKey);
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
        } else {
            any.add(resource);
        }
    });
    requiredValuesMissing = checkMandatoryOnResources(any, anyUtils.getAllResources(any));
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) AllowedSchemas(org.apache.syncope.core.persistence.api.dao.AllowedSchemas) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) SchemaDataBinder(org.apache.syncope.core.provisioning.api.data.SchemaDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ParseException(java.text.ParseException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) RelationshipTypeDAO(org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) DerAttrHandler(org.apache.syncope.core.provisioning.api.DerAttrHandler) Set(java.util.Set) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) GroupableRelatable(org.apache.syncope.core.persistence.api.entity.GroupableRelatable) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) Logger(org.slf4j.Logger) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) VirAttrHandler(org.apache.syncope.core.provisioning.api.VirAttrHandler) Membership(org.apache.syncope.core.persistence.api.entity.Membership) PlainAttrValueDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) Any(org.apache.syncope.core.persistence.api.entity.Any) PlainAttrDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrDAO) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)

Aggregations

AttrTO (org.apache.syncope.common.lib.to.AttrTO)70 Test (org.junit.jupiter.api.Test)31 UserTO (org.apache.syncope.common.lib.to.UserTO)30 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)19 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)17 Map (java.util.Map)15 GroupTO (org.apache.syncope.common.lib.to.GroupTO)15 ArrayList (java.util.ArrayList)14 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)14 List (java.util.List)13 Collections (java.util.Collections)11 StringUtils (org.apache.commons.lang3.StringUtils)11 AnyTO (org.apache.syncope.common.lib.to.AnyTO)10 Optional (java.util.Optional)9 Set (java.util.Set)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 EntityTOUtils (org.apache.syncope.common.lib.EntityTOUtils)8 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)8