Search in sources :

Example 1 with TypeExtensionTO

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

the class MembershipITCase method onGroupDelete.

@Test
public void onGroupDelete() {
    // pre: create group with type extension
    TypeExtensionTO typeExtension = new TypeExtensionTO();
    typeExtension.setAnyType(AnyTypeKind.USER.name());
    typeExtension.getAuxClasses().add("csv");
    typeExtension.getAuxClasses().add("other");
    GroupTO groupTO = GroupITCase.getBasicSampleTO("typeExt");
    groupTO.getTypeExtensions().add(typeExtension);
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    // pre: create user with membership to such group
    UserTO user = UserITCase.getUniqueSampleTO("typeExt@apache.org");
    MembershipTO membership = new MembershipTO.Builder().group(groupTO.getKey()).build();
    membership.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("1454").build());
    user.getMemberships().add(membership);
    user = createUser(user).getEntity();
    // verify that 'aLong' is correctly populated for user's membership
    assertEquals(1, user.getMemberships().size());
    membership = user.getMembership(groupTO.getKey()).get();
    assertNotNull(membership);
    assertEquals(1, membership.getPlainAttr("aLong").get().getValues().size());
    assertEquals("1454", membership.getPlainAttr("aLong").get().getValues().get(0));
    // verify that derived attrbutes from 'csv' and 'other' are also populated for user's membership
    assertFalse(membership.getDerAttr("csvuserid").get().getValues().isEmpty());
    assertFalse(membership.getDerAttr("noschema").get().getValues().isEmpty());
    // now remove the group -> all related memberships should have been removed as well
    groupService.delete(groupTO.getKey());
    // re-read user and verify that no memberships are available any more
    user = userService.read(user.getKey());
    assertTrue(user.getMemberships().isEmpty());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 2 with TypeExtensionTO

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

the class GroupDataBinderImpl method getTypeExtensionTO.

@Override
public TypeExtensionTO getTypeExtensionTO(final TypeExtension typeExt) {
    TypeExtensionTO typeExtTO = new TypeExtensionTO();
    typeExtTO.setAnyType(typeExt.getAnyType().getKey());
    typeExtTO.getAuxClasses().addAll(typeExt.getAuxClasses().stream().map(Entity::getKey).collect(Collectors.toList()));
    return typeExtTO;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO)

Example 3 with TypeExtensionTO

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

the class GroupDataBinderImpl method update.

@Override
public PropagationByResource update(final Group toBeUpdated, final GroupPatch groupPatch) {
    // Re-merge any pending change from workflow tasks
    Group group = groupDAO.save(toBeUpdated);
    PropagationByResource propByRes = new PropagationByResource();
    SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
    AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
    // fetch connObjectKeys before update
    Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
    // realm
    setRealm(group, groupPatch);
    // name
    if (groupPatch.getName() != null && StringUtils.isNotBlank(groupPatch.getName().getValue())) {
        propByRes.addAll(ResourceOperation.UPDATE, groupDAO.findAllResourceKeys(group.getKey()));
        group.setName(groupPatch.getName().getValue());
    }
    // owner
    if (groupPatch.getUserOwner() != null) {
        group.setUserOwner(groupPatch.getUserOwner().getValue() == null ? null : userDAO.find(groupPatch.getUserOwner().getValue()));
    }
    if (groupPatch.getGroupOwner() != null) {
        group.setGroupOwner(groupPatch.getGroupOwner().getValue() == null ? null : groupDAO.find(groupPatch.getGroupOwner().getValue()));
    }
    // attributes and resources
    propByRes.merge(fill(group, groupPatch, anyUtils, scce));
    // check if some connObjectKey was changed by the update above
    Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
    oldConnObjectKeys.entrySet().stream().filter(entry -> newConnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).forEach(entry -> {
        propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
        propByRes.add(ResourceOperation.UPDATE, entry.getKey());
    });
    group = groupDAO.save(group);
    // dynamic membership
    if (groupPatch.getUDynMembershipCond() == null) {
        if (group.getUDynMembership() != null) {
            group.getUDynMembership().setGroup(null);
            group.setUDynMembership(null);
            groupDAO.clearUDynMembers(group);
        }
    } else {
        setDynMembership(group, anyTypeDAO.findUser(), groupPatch.getUDynMembershipCond());
    }
    for (Iterator<? extends ADynGroupMembership> itor = group.getADynMemberships().iterator(); itor.hasNext(); ) {
        ADynGroupMembership memb = itor.next();
        memb.setGroup(null);
        itor.remove();
    }
    groupDAO.clearADynMembers(group);
    for (Map.Entry<String, String> entry : groupPatch.getADynMembershipConds().entrySet()) {
        AnyType anyType = anyTypeDAO.find(entry.getKey());
        if (anyType == null) {
            LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), entry.getKey());
        } else {
            setDynMembership(group, anyType, entry.getValue());
        }
    }
    // type extensions
    for (TypeExtensionTO typeExtTO : groupPatch.getTypeExtensions()) {
        AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
        if (anyType == null) {
            LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
        } else {
            TypeExtension typeExt = group.getTypeExtension(anyType).orElse(null);
            if (typeExt == null) {
                typeExt = entityFactory.newEntity(TypeExtension.class);
                typeExt.setAnyType(anyType);
                typeExt.setGroup(group);
                group.add(typeExt);
            }
            // add all classes contained in the TO
            for (String name : typeExtTO.getAuxClasses()) {
                AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
                if (anyTypeClass == null) {
                    LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
                } else {
                    typeExt.add(anyTypeClass);
                }
            }
            // remove all classes not contained in the TO
            typeExt.getAuxClasses().removeIf(anyTypeClass -> !typeExtTO.getAuxClasses().contains(anyTypeClass.getKey()));
            // only consider non-empty type extensions
            if (typeExt.getAuxClasses().isEmpty()) {
                group.getTypeExtensions().remove(typeExt);
                typeExt.setGroup(null);
            }
        }
    }
    // remove all type extensions not contained in the TO
    group.getTypeExtensions().removeIf(typeExt -> !groupPatch.getTypeExtension(typeExt.getAnyType().getKey()).isPresent());
    // Throw composite exception if there is at least one element set in the composing exceptions
    if (scce.hasExceptions()) {
        throw scce;
    }
    return propByRes;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) UDynGroupMembership(org.apache.syncope.core.persistence.api.entity.user.UDynGroupMembership) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Entity(org.apache.syncope.core.persistence.api.entity.Entity) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) GroupDataBinder(org.apache.syncope.core.provisioning.api.data.GroupDataBinder) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Map(java.util.Map) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) SearchCondConverter(org.apache.syncope.core.persistence.api.search.SearchCondConverter) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) Iterator(java.util.Iterator) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) User(org.apache.syncope.core.persistence.api.entity.user.User) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) DynGroupMembership(org.apache.syncope.core.persistence.api.entity.DynGroupMembership) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List) Component(org.springframework.stereotype.Component) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) HashMap(java.util.HashMap) Map(java.util.Map) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass)

Example 4 with TypeExtensionTO

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

the class GroupITCase method typeExtensions.

@Test
public void typeExtensions() {
    TypeExtensionTO typeExtension = new TypeExtensionTO();
    typeExtension.setAnyType(AnyTypeKind.USER.name());
    typeExtension.getAuxClasses().add("csv");
    GroupTO groupTO = getBasicSampleTO("typeExtensions");
    groupTO.getTypeExtensions().add(typeExtension);
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertEquals(1, groupTO.getTypeExtensions().size());
    assertEquals(1, groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().size());
    assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("csv"));
    typeExtension = new TypeExtensionTO();
    typeExtension.setAnyType(AnyTypeKind.USER.name());
    typeExtension.getAuxClasses().add("csv");
    typeExtension.getAuxClasses().add("other");
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.getTypeExtensions().add(typeExtension);
    groupTO = updateGroup(groupPatch).getEntity();
    assertNotNull(groupTO);
    assertEquals(1, groupTO.getTypeExtensions().size());
    assertEquals(2, groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().size());
    assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("csv"));
    assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("other"));
}
Also used : TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 5 with TypeExtensionTO

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

the class TypeExtensionDirectoryPanel method getActions.

@Override
public ActionsPanel<TypeExtensionTO> getActions(final IModel<TypeExtensionTO> model) {
    final ActionsPanel<TypeExtensionTO> panel = super.getActions(model);
    final TypeExtensionTO typeExtension = model.getObject();
    panel.add(new ActionLink<TypeExtensionTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final TypeExtensionTO ignore) {
            send(TypeExtensionDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(typeExtension, target));
        }
    }, ActionLink.ActionType.EDIT, StringUtils.EMPTY);
    panel.add(new ActionLink<TypeExtensionTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final TypeExtensionTO ignore) {
            Optional<TypeExtensionTO> typeExt = groupTO.getTypeExtension(typeExtension.getAnyType());
            if (typeExt.isPresent()) {
                groupTO.getTypeExtensions().remove(typeExt.get());
                target.add(container);
            }
        }
    }, ActionLink.ActionType.DELETE, StringUtils.EMPTY, true);
    return panel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Optional(java.util.Optional) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO)

Aggregations

TypeExtensionTO (org.apache.syncope.common.lib.to.TypeExtensionTO)6 GroupTO (org.apache.syncope.common.lib.to.GroupTO)3 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)2 Entity (org.apache.syncope.core.persistence.api.entity.Entity)2 IOException (java.io.IOException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CustomAttributesInfo (org.apache.syncope.client.enduser.model.CustomAttributesInfo)1 SchemaResponse (org.apache.syncope.client.enduser.model.SchemaResponse)1 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)1 SchemaTO (org.apache.syncope.common.lib.to.SchemaTO)1