Package org.apache.syncope.core.persistence.beans.membership

Examples of org.apache.syncope.core.persistence.beans.membership.Membership


    public void saveMVirAttribute() throws ClassNotFoundException {

        MVirSchema virtualSchema = new MVirSchema();
        virtualSchema.setName("mvirtualdata");

        Membership owner = membershipDAO.find(3L);
        assertNotNull("did not get expected membership", owner);

        MVirAttr virtualAttribute = new MVirAttr();
        virtualAttribute.setOwner(owner);
        virtualAttribute.setVirtualSchema(virtualSchema);
View Full Code Here


    @Test
    public void saveMDerAttribute() throws ClassNotFoundException {
        MDerSchema deriveddata = derSchemaDAO.find("mderiveddata", MDerSchema.class);
        assertNotNull(deriveddata);

        Membership owner = membershipDAO.find(1L);
        assertNotNull("did not get expected user", owner);

        MDerAttr derivedAttribute = new MDerAttr();
        derivedAttribute.setOwner(owner);
        derivedAttribute.setDerivedSchema(deriveddata);

        derivedAttribute = derAttrDAO.save(derivedAttribute);

        MDerAttr actual = derAttrDAO.find(derivedAttribute.getId(), MDerAttr.class);
        assertNotNull("expected save to work", actual);
        assertEquals(derivedAttribute, actual);

        MAttrValue sx = (MAttrValue) owner.getAttribute("mderived_sx").getValues().iterator().next();
        MAttrValue dx = (MAttrValue) owner.getAttribute("mderived_dx").getValues().iterator().next();

        assertEquals(sx.getValue() + "-" + dx.getValue(), derivedAttribute.getValue(owner.getAttributes()));
    }
View Full Code Here

        Query query = entityManager.createQuery("SELECT e FROM Membership e "
                + "WHERE e.syncopeUser = :user AND e.syncopeRole = :role");
        query.setParameter("user", user);
        query.setParameter("role", role);

        Membership result = null;

        try {
            result = (Membership) query.getSingleResult();
        } catch (NoResultException e) {
            if (LOG.isDebugEnabled()) {
View Full Code Here

        return entityManager.merge(membership);
    }

    @Override
    public void delete(final Long id) {
        Membership membership = find(id);
        if (membership == null) {
            return;
        }

        membership.getSyncopeUser().removeMembership(membership);
        userDAO.save(membership.getSyncopeUser());

        entityManager.remove(membership);
    }
View Full Code Here

    }

    @Test
    public void checkForEnumType() {
        SyncopeUser user = userDAO.find(1L);
        Membership membership = user.getMembership(1L);
        assertNotNull(membership);

        MSchema schema = new MSchema();
        schema.setType(AttributeSchemaType.Enum);
        schema.setName("color");
        schema.setEnumerationValues("red" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "yellow");

        MSchema actualSchema = schemaDAO.save(schema);
        assertNotNull(actualSchema);

        MAttrTemplate template = new MAttrTemplate();
        template.setSchema(actualSchema);
        membership.getSyncopeRole().getAttrTemplates(MAttrTemplate.class).add(template);

        MAttr attr = new MAttr();
        attr.setTemplate(template);
        attr.setOwner(membership);
        attr.addValue("yellow", AttributableUtil.getInstance(AttributableType.MEMBERSHIP));
        membership.addAttr(attr);

        MAttr actualAttribute = userDAO.save(user).getMembership(1L).getAttr("color");
        assertNotNull(actualAttribute);

        membership = membershipDAO.find(1L);
        assertNotNull(membership);
        assertNotNull(membership.getAttr(schema.getName()));
        assertNotNull(membership.getAttr(schema.getName()).getValues());

        assertEquals(membership.getAttr(schema.getName()).getValues().size(), 1);
    }
View Full Code Here

    public Membership getMembershipFromId(final Long membershipId) {
        if (membershipId == null) {
            throw new NotFoundException("Null membership id");
        }

        Membership membership = membershipDAO.find(membershipId);
        if (membership == null) {
            throw new NotFoundException("Membership " + membershipId);
        }

        return membership;
View Full Code Here

            if (role == null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Ignoring invalid role " + membershipTO.getRoleName());
                }
            } else {
                Membership membership = null;
                if (user.getId() != null) {
                    membership = user.getMembership(role.getId()) == null
                            ? membershipDAO.find(user, role)
                            : user.getMembership(role.getId());
                }
                if (membership == null) {
                    membership = new Membership();
                    membership.setSyncopeRole(role);
                    membership.setSyncopeUser(user);

                    user.addMembership(membership);
                }

                fill(membership, membershipTO, AttributableUtil.getInstance(AttributableType.MEMBERSHIP), scce);
View Full Code Here

        // memberships to be removed
        for (Long membershipId : userMod.getMembershipsToRemove()) {
            LOG.debug("Membership to be removed: {}", membershipId);

            Membership membership = membershipDAO.find(membershipId);
            if (membership == null) {
                LOG.debug("Invalid membership id specified to be removed: {}", membershipId);
            } else {
                if (!membershipToBeAddedRoleIds.contains(membership.getSyncopeRole().getId())) {
                    toBeDeprovisioned.addAll(membership.getSyncopeRole().getResourceNames());
                }

                // In order to make the removeMembership() below to work,
                // we need to be sure to take exactly the same membership
                // of the user object currently in memory (which has potentially
                // some modifications compared to the one stored in the DB
                membership = user.getMembership(membership.getSyncopeRole().getId());
                if (membershipToBeAddedRoleIds.contains(membership.getSyncopeRole().getId())) {
                    Set<Long> attributeIds = new HashSet<Long>(membership.getAttrs().size());
                    for (AbstractAttr attribute : membership.getAttrs()) {
                        attributeIds.add(attribute.getId());
                    }
                    for (Long attributeId : attributeIds) {
                        attrDAO.delete(attributeId, MAttr.class);
                    }
                    attributeIds.clear();

                    // remove derived attributes
                    for (AbstractDerAttr derAttr : membership.getDerAttrs()) {
                        attributeIds.add(derAttr.getId());
                    }
                    for (Long derAttrId : attributeIds) {
                        derAttrDAO.delete(derAttrId, MDerAttr.class);
                    }
                    attributeIds.clear();

                    // remove virtual attributes
                    for (AbstractVirAttr virAttr : membership.getVirAttrs()) {
                        attributeIds.add(virAttr.getId());
                    }
                    for (Long virAttrId : attributeIds) {
                        virAttrDAO.delete(virAttrId, MVirAttr.class);
                    }
                    attributeIds.clear();
                } else {
                    user.removeMembership(membership);

                    membershipDAO.delete(membershipId);
                }
            }
        }

        // memberships to be added
        for (MembershipMod membershipMod : userMod.getMembershipsToAdd()) {
            LOG.debug("Membership to be added: role({})", membershipMod.getRole());

            SyncopeRole role = roleDAO.find(membershipMod.getRole());
            if (role == null) {
                LOG.debug("Ignoring invalid role {}", membershipMod.getRole());
            } else {
                Membership membership = user.getMembership(role.getId());
                if (membership == null) {
                    membership = new Membership();
                    membership.setSyncopeRole(role);
                    membership.setSyncopeUser(user);

                    user.addMembership(membership);

                    toBeProvisioned.addAll(role.getResourceNames());
                }
View Full Code Here

     */
    public PropagationByResource fillMembershipVirtual(
            final Long userId, final Long roleId, final Long membershipId, final Set<String> vAttrsToBeRemoved,
            final Set<AttributeMod> vAttrsToBeUpdated, final boolean isRemoval) {

        final Membership membership = membershipId == null
                ? getUserFromId(userId).getMembership(roleId)
                : getMembershipFromId(membershipId);

        return membership == null ? new PropagationByResource() : isRemoval
                ? fillVirtual(
                        membership,
                        membership.getVirAttrs() == null
                        ? Collections.<String>emptySet()
                        : getAttributeNames(membership.getVirAttrs()),
                        vAttrsToBeUpdated,
                        AttributableUtil.getInstance(AttributableType.MEMBERSHIP))
                : fillVirtual(
                        membership,
                        vAttrsToBeRemoved,
View Full Code Here

        Query query = entityManager.createQuery("SELECT e FROM Membership e "
                + "WHERE e.syncopeUser = :user AND e.syncopeRole = :role");
        query.setParameter("user", user);
        query.setParameter("role", role);

        Membership result = null;

        try {
            result = (Membership) query.getSingleResult();
        } catch (NoResultException e) {
            LOG.debug("No membership was found for user {} and role {}", user, role, e);
View Full Code Here

TOP

Related Classes of org.apache.syncope.core.persistence.beans.membership.Membership

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.