Search in sources :

Example 16 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.

the class DefaultGroupPullResultHandler method newPatch.

@Override
protected AnyPatch newPatch(final String key) {
    GroupPatch patch = new GroupPatch();
    patch.setKey(key);
    return patch;
}
Also used : GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch)

Example 17 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.

the class CamelGroupProvisioningManager method unlink.

@Override
public String unlink(final GroupPatch groupPatch) {
    PollingConsumer pollingConsumer = getConsumer("direct:unlinkGroupPort");
    sendMessage("direct:unlinkGroup", groupPatch);
    Exchange exchange = pollingConsumer.receive();
    if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
        throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    }
    return exchange.getIn().getBody(GroupPatch.class).getKey();
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch)

Example 18 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch 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 19 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.

the class DefaultGroupPushResultHandler method newPatch.

@Override
protected AnyPatch newPatch(final String key) {
    GroupPatch patch = new GroupPatch();
    patch.setKey(key);
    return patch;
}
Also used : GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch)

Example 20 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch in project syncope by apache.

the class GroupITCase method updateAsGroupOwner.

@Test
public void updateAsGroupOwner() {
    // 1. read group as admin
    GroupTO groupTO = groupService.read("ebf97068-aa4b-4a85-9f01-680e8c4cf227");
    // issue SYNCOPE-15
    assertNotNull(groupTO.getCreationDate());
    assertNotNull(groupTO.getLastChangeDate());
    assertEquals("admin", groupTO.getCreator());
    assertEquals("admin", groupTO.getLastModifier());
    // 2. prepare update
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.setName(new StringReplacePatchItem.Builder().value("Director").build());
    // 3. try to update as verdi, not owner of group 6 - fail
    GroupService groupService2 = clientFactory.create("verdi", ADMIN_PWD).getService(GroupService.class);
    try {
        groupService2.update(groupPatch);
        fail("This should not happen");
    } catch (ForbiddenException e) {
        assertNotNull(e);
    }
    // 4. update as puccini, owner of group 6 - success
    GroupService groupService3 = clientFactory.create("puccini", ADMIN_PWD).getService(GroupService.class);
    groupTO = groupService3.update(groupPatch).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
    }).getEntity();
    assertEquals("Director", groupTO.getName());
    // issue SYNCOPE-15
    assertNotNull(groupTO.getCreationDate());
    assertNotNull(groupTO.getLastChangeDate());
    assertEquals("admin", groupTO.getCreator());
    assertEquals("puccini", groupTO.getLastModifier());
    assertTrue(groupTO.getCreationDate().before(groupTO.getLastChangeDate()));
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) GroupService(org.apache.syncope.common.rest.api.service.GroupService) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)33 GroupTO (org.apache.syncope.common.lib.to.GroupTO)23 Test (org.junit.jupiter.api.Test)15 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 List (java.util.List)5 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)5 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)5 GroupService (org.apache.syncope.common.rest.api.service.GroupService)5 ForbiddenException (javax.ws.rs.ForbiddenException)4 Response (javax.ws.rs.core.Response)4 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 StringPatchItem (org.apache.syncope.common.lib.patch.StringPatchItem)4 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)4 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 AccessControlException (java.security.AccessControlException)3 Collections (java.util.Collections)3 Map (java.util.Map)3 NamingException (javax.naming.NamingException)3