Search in sources :

Example 36 with ProvisioningResult

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

the class RealmLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_DELETE + "')")
public ProvisioningResult<RealmTO> delete(final String fullPath) {
    Realm realm = realmDAO.findByFullPath(fullPath);
    if (realm == null) {
        LOG.error("Could not find realm '" + fullPath + "'");
        throw new NotFoundException(fullPath);
    }
    if (!realmDAO.findChildren(realm).isEmpty()) {
        throw SyncopeClientException.build(ClientExceptionType.HasChildren);
    }
    Set<String> adminRealms = Collections.singleton(realm.getFullPath());
    AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
    keyCond.setSchema("key");
    SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
    int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
    int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
    int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
    if (users + groups + anyObjects > 0) {
        SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
        containedAnys.getElements().add(users + " user(s)");
        containedAnys.getElements().add(groups + " group(s)");
        containedAnys.getElements().add(anyObjects + " anyObject(s)");
        throw containedAnys;
    }
    PropagationByResource propByRes = new PropagationByResource();
    realm.getResourceKeys().forEach(resource -> {
        propByRes.add(ResourceOperation.DELETE, resource);
    });
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    realmDAO.delete(realm);
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 37 with ProvisioningResult

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

the class AbstractAnyLogic method afterCreate.

protected ProvisioningResult<TO> afterCreate(final TO input, final List<PropagationStatus> statuses, final List<LogicActions> actions) {
    TO any = input;
    for (LogicActions action : actions) {
        any = action.afterCreate(any);
    }
    ProvisioningResult<TO> result = new ProvisioningResult<>();
    result.setEntity(any);
    result.getPropagationStatuses().addAll(statuses);
    return result;
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) AnyTO(org.apache.syncope.common.lib.to.AnyTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) UserTO(org.apache.syncope.common.lib.to.UserTO) LogicActions(org.apache.syncope.core.provisioning.api.LogicActions)

Example 38 with ProvisioningResult

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

the class JAXBTest method provisioningResult.

@Test
public void provisioningResult() throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(ProvisioningResult.class);
    Marshaller marshaller = context.createMarshaller();
    Unmarshaller unmarshaller = context.createUnmarshaller();
    GroupTO group = new GroupTO();
    group.setName(UUID.randomUUID().toString());
    group.setRealm(SyncopeConstants.ROOT_REALM);
    group.getVirAttrs().add(new AttrTO.Builder().schema("rvirtualdata").value("rvirtualvalue").build());
    group.getADynMembershipConds().put("USER", "username==a*");
    ProvisioningResult<GroupTO> original = new ProvisioningResult<>();
    original.setEntity(group);
    PropagationStatus status = new PropagationStatus();
    status.setFailureReason("failed");
    status.setBeforeObj(new ConnObjectTO());
    original.getPropagationStatuses().add(status);
    StringWriter writer = new StringWriter();
    marshaller.marshal(original, writer);
    Object actual = unmarshaller.unmarshal(new StringReader(writer.toString()));
    assertEquals(original, actual);
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) StringReader(java.io.StringReader) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) JAXBContext(javax.xml.bind.JAXBContext) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Unmarshaller(javax.xml.bind.Unmarshaller) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 39 with ProvisioningResult

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

the class JSONTest method provisioningResult.

@Test
public void provisioningResult() throws IOException {
    GroupTO group = new GroupTO();
    group.setName(UUID.randomUUID().toString());
    group.setRealm(SyncopeConstants.ROOT_REALM);
    group.getVirAttrs().add(new AttrTO.Builder().schema("rvirtualdata").value("rvirtualvalue").build());
    group.getADynMembershipConds().put("USER", "username==a*");
    ProvisioningResult<GroupTO> original = new ProvisioningResult<>();
    original.setEntity(group);
    PropagationStatus status = new PropagationStatus();
    status.setFailureReason("failed");
    status.setBeforeObj(new ConnObjectTO());
    original.getPropagationStatuses().add(status);
    ObjectMapper mapper = new ObjectMapper();
    StringWriter writer = new StringWriter();
    mapper.writeValue(writer, original);
    ProvisioningResult<GroupTO> actual = mapper.readValue(writer.toString(), new TypeReference<ProvisioningResult<GroupTO>>() {
    });
    assertEquals(original, actual);
}
Also used : StringWriter(java.io.StringWriter) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)39 UserTO (org.apache.syncope.common.lib.to.UserTO)24 Test (org.junit.jupiter.api.Test)21 GroupTO (org.apache.syncope.common.lib.to.GroupTO)14 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 Response (javax.ws.rs.core.Response)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)8 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)8 UserService (org.apache.syncope.common.rest.api.service.UserService)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 GenericType (javax.ws.rs.core.GenericType)6 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)6 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)5 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)4 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)4