Search in sources :

Example 21 with VirSchema

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

the class UserDataBinderImpl method getUserTO.

@Transactional(readOnly = true)
@Override
public UserTO getUserTO(final User user, final boolean details) {
    UserTO userTO = new UserTO();
    BeanUtils.copyProperties(user, userTO, IGNORE_PROPERTIES);
    userTO.setSuspended(BooleanUtils.isTrue(user.isSuspended()));
    if (user.getSecurityQuestion() != null) {
        userTO.setSecurityQuestion(user.getSecurityQuestion().getKey());
    }
    Map<VirSchema, List<String>> virAttrValues = details ? virAttrHandler.getValues(user) : Collections.<VirSchema, List<String>>emptyMap();
    fillTO(userTO, user.getRealm().getFullPath(), user.getAuxClasses(), user.getPlainAttrs(), derAttrHandler.getValues(user), virAttrValues, userDAO.findAllResources(user), details);
    if (details) {
        // dynamic realms
        userTO.getDynRealms().addAll(userDAO.findDynRealms(user.getKey()));
        // roles
        userTO.getRoles().addAll(user.getRoles().stream().map(Entity::getKey).collect(Collectors.toList()));
        // dynamic roles
        userTO.getDynRoles().addAll(userDAO.findDynRoles(user.getKey()).stream().map(Entity::getKey).collect(Collectors.toList()));
        // privileges
        userTO.getPrivileges().addAll(userDAO.findAllRoles(user).stream().flatMap(role -> role.getPrivileges().stream()).map(Entity::getKey).collect(Collectors.toSet()));
        // relationships
        userTO.getRelationships().addAll(user.getRelationships().stream().map(relationship -> getRelationshipTO(relationship.getType().getKey(), relationship.getRightEnd())).collect(Collectors.toList()));
        // memberships
        userTO.getMemberships().addAll(user.getMemberships().stream().map(membership -> {
            return getMembershipTO(user.getPlainAttrs(membership), derAttrHandler.getValues(user, membership), virAttrHandler.getValues(user, membership), membership);
        }).collect(Collectors.toList()));
        // dynamic memberships
        userTO.getDynMemberships().addAll(userDAO.findDynGroups(user.getKey()).stream().map(group -> {
            return new MembershipTO.Builder().group(group.getKey(), group.getName()).build();
        }).collect(Collectors.toList()));
    }
    return userTO;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SecurityQuestionDAO(org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO) Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Entity(org.apache.syncope.core.persistence.api.entity.Entity) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) UserDataBinder(org.apache.syncope.core.provisioning.api.data.UserDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Role(org.apache.syncope.core.persistence.api.entity.Role) Collection(java.util.Collection) Resource(javax.annotation.Resource) Set(java.util.Set) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Group(org.apache.syncope.core.persistence.api.entity.group.Group) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) BeanUtils(org.apache.syncope.core.spring.BeanUtils) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) HashSet(java.util.HashSet) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) Encryptor(org.apache.syncope.core.spring.security.Encryptor) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) AccessTokenDAO(org.apache.syncope.core.persistence.api.dao.AccessTokenDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) Transactional(org.springframework.transaction.annotation.Transactional) Entity(org.apache.syncope.core.persistence.api.entity.Entity) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) UserTO(org.apache.syncope.common.lib.to.UserTO) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with VirSchema

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

the class SchemaLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_CREATE + "')")
@SuppressWarnings("unchecked")
public <T extends SchemaTO> T create(final SchemaType schemaType, final T schemaTO) {
    if (StringUtils.isBlank(schemaTO.getKey())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
        sce.getElements().add("Schema key");
        throw sce;
    }
    if (doesSchemaExist(schemaType, schemaTO.getKey())) {
        throw new DuplicateException(schemaType + "/" + schemaTO.getKey());
    }
    T created;
    switch(schemaType) {
        case VIRTUAL:
            VirSchema virSchema = virSchemaDAO.save(binder.create((VirSchemaTO) schemaTO));
            created = (T) binder.getVirSchemaTO(virSchema);
            break;
        case DERIVED:
            DerSchema derSchema = derSchemaDAO.save(binder.create((DerSchemaTO) schemaTO));
            created = (T) binder.getDerSchemaTO(derSchema);
            break;
        case PLAIN:
        default:
            PlainSchema plainSchema = plainSchemaDAO.save(binder.create((PlainSchemaTO) schemaTO));
            created = (T) binder.getPlainSchemaTO(plainSchema);
    }
    return created;
}
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) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) 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 23 with VirSchema

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

the class SchemaLogic method search.

@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public <T extends SchemaTO> List<T> search(final SchemaType schemaType, final List<String> anyTypeClasses, final String keyword) {
    List<AnyTypeClass> classes = new ArrayList<>(anyTypeClasses == null ? 0 : anyTypeClasses.size());
    if (anyTypeClasses != null) {
        anyTypeClasses.remove(AnyTypeKind.USER.name());
        anyTypeClasses.remove(AnyTypeKind.GROUP.name());
        anyTypeClasses.forEach(anyTypeClass -> {
            AnyTypeClass clazz = anyTypeClassDAO.find(anyTypeClass);
            if (clazz == null) {
                LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), anyTypeClass);
            } else {
                classes.add(clazz);
            }
        });
    }
    List<T> result;
    switch(schemaType) {
        case VIRTUAL:
            result = (classes.isEmpty() ? keyword == null ? virSchemaDAO.findAll() : virSchemaDAO.findByKeyword(keyword) : virSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<VirSchema, T>() {

                @Override
                public T apply(final VirSchema schema) {
                    return (T) binder.getVirSchemaTO(schema);
                }
            }).collect(Collectors.toList());
            break;
        case DERIVED:
            result = (classes.isEmpty() ? keyword == null ? derSchemaDAO.findAll() : derSchemaDAO.findByKeyword(keyword) : derSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<DerSchema, T>() {

                @Override
                public T apply(final DerSchema schema) {
                    return (T) binder.getDerSchemaTO(schema);
                }
            }).collect(Collectors.toList());
            break;
        case PLAIN:
        default:
            result = (classes.isEmpty() ? keyword == null ? plainSchemaDAO.findAll() : plainSchemaDAO.findByKeyword(keyword) : plainSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<PlainSchema, T>() {

                @Override
                public T apply(final PlainSchema schema) {
                    return (T) binder.getPlainSchemaTO(schema);
                }
            }).collect(Collectors.toList());
    }
    return result;
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ArrayList(java.util.ArrayList) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with VirSchema

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

the class JPAAnyTypeClassDAO method delete.

@Override
public void delete(final String key) {
    AnyTypeClass anyTypeClass = find(key);
    if (anyTypeClass == null) {
        return;
    }
    for (PlainSchema schema : plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (DerSchema schema : derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (VirSchema schema : virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (AnyType type : anyTypeDAO.findByTypeClass(anyTypeClass)) {
        type.getClasses().remove(anyTypeClass);
    }
    for (TypeExtension typeExt : groupDAO.findTypeExtensions(anyTypeClass)) {
        typeExt.getAuxClasses().remove(anyTypeClass);
        if (typeExt.getAuxClasses().isEmpty()) {
            typeExt.getGroup().getTypeExtensions().remove(typeExt);
            typeExt.setGroup(null);
        }
    }
    for (Provision provision : resourceDAO.findProvisionsByAuxClass(anyTypeClass)) {
        provision.getAuxClasses().remove(anyTypeClass);
    }
    entityManager().remove(anyTypeClass);
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) JPAAnyTypeClass(org.apache.syncope.core.persistence.jpa.entity.JPAAnyTypeClass) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Example 25 with VirSchema

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

the class VirSchemaTest method deal.

@Test
public void deal() {
    Provision provision = resourceDAO.find("ws-target-resource-1").getProvision(anyTypeDAO.findUser()).get();
    assertNotNull(provision);
    assertTrue(virSchemaDAO.findByProvision(provision).isEmpty());
    VirSchema virSchema = entityFactory.newEntity(VirSchema.class);
    virSchema.setKey("vSchema");
    virSchema.setReadonly(true);
    virSchema.setExtAttrName("EXT_ATTR");
    virSchema.setProvision(provision);
    virSchemaDAO.save(virSchema);
    virSchemaDAO.flush();
    virSchema = virSchemaDAO.find("vSchema");
    assertNotNull(virSchema);
    assertTrue(virSchema.isReadonly());
    assertEquals("EXT_ATTR", virSchema.getExtAttrName());
    provision = resourceDAO.find("ws-target-resource-1").getProvision(anyTypeDAO.findUser()).get();
    assertNotNull(provision);
    assertFalse(virSchemaDAO.findByProvision(provision).isEmpty());
    assertTrue(virSchemaDAO.findByProvision(provision).contains(virSchema));
    MappingItem item = virSchema.asLinkingMappingItem();
    assertNotNull(item);
    assertEquals(virSchema.getKey(), item.getIntAttrName());
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)26 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)10 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)10 List (java.util.List)9 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)9 HashSet (java.util.HashSet)6 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)6 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)6 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 Date (java.util.Date)5 OrgUnit (org.apache.syncope.core.persistence.api.entity.resource.OrgUnit)5 ParseException (java.text.ParseException)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)4 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)3 VirSchemaDAO (org.apache.syncope.core.persistence.api.dao.VirSchemaDAO)3 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)3