Search in sources :

Example 36 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class SAML2UserManager method findMatchingUser.

@Transactional(readOnly = true)
public List<String> findMatchingUser(final String keyValue, final String idpKey) {
    List<String> result = new ArrayList<>();
    SAML2IdP idp = idpDAO.find(idpKey);
    if (idp == null) {
        LOG.warn("Invalid IdP: {}", idpKey);
        return result;
    }
    String transformed = keyValue;
    for (ItemTransformer transformer : MappingUtils.getItemTransformers(idp.getConnObjectKeyItem().get())) {
        List<Object> output = transformer.beforePull(null, null, Collections.<Object>singletonList(transformed));
        if (output != null && !output.isEmpty()) {
            transformed = output.get(0).toString();
        }
    }
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(idp.getConnObjectKeyItem().get().getIntAttrName(), AnyTypeKind.USER);
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified, ignoring", idp.getConnObjectKeyItem().get().getIntAttrName(), e);
        return result;
    }
    if (intAttrName.getField() != null) {
        switch(intAttrName.getField()) {
            case "key":
                User byKey = userDAO.find(transformed);
                if (byKey != null) {
                    result.add(byKey.getUsername());
                }
                break;
            case "username":
                User byUsername = userDAO.findByUsername(transformed);
                if (byUsername != null) {
                    result.add(byUsername.getUsername());
                }
                break;
            default:
        }
    } else if (intAttrName.getSchemaType() != null) {
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                PlainAttrValue value = entityFactory.newEntity(UPlainAttrValue.class);
                PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName());
                if (schema == null) {
                    value.setStringValue(transformed);
                } else {
                    try {
                        value.parseValue(schema, transformed);
                    } catch (ParsingValidationException e) {
                        LOG.error("While parsing provided key value {}", transformed, e);
                        value.setStringValue(transformed);
                    }
                }
                result.addAll(userDAO.findByPlainAttrValue(intAttrName.getSchemaName(), value).stream().map(user -> user.getUsername()).collect(Collectors.toList()));
                break;
            case DERIVED:
                result.addAll(userDAO.findByDerAttrValue(intAttrName.getSchemaName(), transformed).stream().map(user -> user.getUsername()).collect(Collectors.toList()));
                break;
            default:
        }
    }
    return result;
}
Also used : ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) AttrTO(org.apache.syncope.common.lib.to.AttrTO) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SerializationUtils(org.apache.commons.lang3.SerializationUtils) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SAML2IdP(org.apache.syncope.core.persistence.api.entity.SAML2IdP) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) UPlainAttrValue(org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue) Pair(org.apache.commons.lang3.tuple.Pair) Propagation(org.springframework.transaction.annotation.Propagation) UserDataBinder(org.apache.syncope.core.provisioning.api.data.UserDataBinder) SAML2LoginResponseTO(org.apache.syncope.common.lib.to.SAML2LoginResponseTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) SAML2IdPDAO(org.apache.syncope.core.persistence.api.dao.SAML2IdPDAO) ParseException(java.text.ParseException) TemplateUtils(org.apache.syncope.core.provisioning.java.utils.TemplateUtils) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Logger(org.slf4j.Logger) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) User(org.apache.syncope.core.persistence.api.entity.user.User) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) Collectors(java.util.stream.Collectors) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) Component(org.springframework.stereotype.Component) SAML2IdPActions(org.apache.syncope.core.provisioning.api.SAML2IdPActions) UserProvisioningManager(org.apache.syncope.core.provisioning.api.UserProvisioningManager) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) UserTO(org.apache.syncope.common.lib.to.UserTO) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Collections(java.util.Collections) AnyOperations(org.apache.syncope.common.lib.AnyOperations) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) Transactional(org.springframework.transaction.annotation.Transactional) UPlainAttrValue(org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue) User(org.apache.syncope.core.persistence.api.entity.user.User) ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) ArrayList(java.util.ArrayList) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) SAML2IdP(org.apache.syncope.core.persistence.api.entity.SAML2IdP) UPlainAttrValue(org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) ParseException(java.text.ParseException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class ElasticsearchAnySearchDAO method addSort.

private void addSort(final SearchRequestBuilder builder, final AnyTypeKind kind, final List<OrderByClause> orderBy) {
    AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
    orderBy.forEach(clause -> {
        String sortName = null;
        // Manage difference among external key attribute and internal JPA @Id
        String fieldName = "key".equals(clause.getField()) ? "id" : clause.getField();
        Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), fieldName);
        if (anyField == null) {
            PlainSchema schema = schemaDAO.find(fieldName);
            if (schema != null) {
                sortName = fieldName;
            }
        } else {
            sortName = fieldName;
        }
        if (sortName == null) {
            LOG.warn("Cannot build any valid clause from {}", clause);
        } else {
            builder.addSort(sortName, SortOrder.valueOf(clause.getDirection().name()));
        }
    });
}
Also used : Field(java.lang.reflect.Field) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 38 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class GoogleAppsPropagationActions method after.

@Transactional
@Override
public void after(final PropagationTask task, final TaskExec execution, final ConnectorObject afterObj) {
    if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
        return;
    }
    if (AnyTypeKind.USER != task.getAnyTypeKind()) {
        return;
    }
    User user = userDAO.find(task.getEntityKey());
    if (user == null) {
        LOG.error("Could not find user {}, skipping", task.getEntityKey());
    } else {
        boolean modified = false;
        AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
        PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
        if (googleAppsId == null) {
            LOG.error("Could not find schema {}, skipping", getGoogleAppsIdSchema());
        } else {
            // set back the __UID__ received by Google
            UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
            if (attr == null) {
                attr = entityFactory.newEntity(UPlainAttr.class);
                attr.setSchema(googleAppsId);
                attr.setOwner(user);
                user.add(attr);
                try {
                    attr.add(afterObj.getUid().getUidValue(), anyUtils);
                    modified = true;
                } catch (InvalidPlainAttrValueException e) {
                    LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), afterObj.getUid().getUidValue(), e);
                }
            } else {
                LOG.debug("User {} has already {} assigned: {}", user, googleAppsId.getKey(), attr.getValuesAsStrings());
            }
        }
        if (modified) {
            userDAO.save(user);
        }
    }
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class ConfigurationDataBinderImpl method getAttr.

@Override
public CPlainAttr getAttr(final AttrTO attrTO) {
    PlainSchema schema = getPlainSchema(attrTO.getSchema());
    if (schema == null) {
        throw new NotFoundException("Conf schema " + attrTO.getSchema());
    } else {
        SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
        CPlainAttr attr = entityFactory.newEntity(CPlainAttr.class);
        attr.setSchema(schema);
        fillAttr(attrTO.getValues(), schema, attr, invalidValues);
        if (!invalidValues.isEmpty()) {
            throw invalidValues;
        }
        return attr;
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) CPlainAttr(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttr) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Example 40 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class AnyTypeClassDataBinderImpl method update.

@Override
public void update(final AnyTypeClass anyTypeClass, final AnyTypeClassTO anyTypeClassTO) {
    if (anyTypeClass.getKey() == null) {
        anyTypeClass.setKey(anyTypeClassTO.getKey());
    }
    plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getPlainSchemas().clear();
    anyTypeClassTO.getPlainSchemas().forEach(schemaName -> {
        PlainSchema schema = plainSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + PlainSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
    derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach((schema) -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getDerSchemas().clear();
    anyTypeClassTO.getDerSchemas().forEach(schemaName -> {
        DerSchema schema = derSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + DerSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
    virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getVirSchemas().clear();
    anyTypeClassTO.getVirSchemas().forEach(schemaName -> {
        VirSchema schema = virSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + VirSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Aggregations

PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)55 Test (org.junit.jupiter.api.Test)22 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)21 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)15 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)14 User (org.apache.syncope.core.persistence.api.entity.user.User)13 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)12 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)11 ArrayList (java.util.ArrayList)10 PlainAttrValue (org.apache.syncope.core.persistence.api.entity.PlainAttrValue)10 Transactional (org.springframework.transaction.annotation.Transactional)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)9 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)9 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Optional (java.util.Optional)8 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)8 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)8