Search in sources :

Example 1 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class CamelRouteLogic method update.

@PreAuthorize("hasRole('" + CamelEntitlement.ROUTE_UPDATE + "')")
public void update(final AnyTypeKind anyTypeKind, final CamelRouteTO routeTO) {
    CamelRoute route = routeDAO.find(routeTO.getKey());
    if (route == null) {
        throw new NotFoundException("CamelRoute with key=" + routeTO.getKey());
    }
    if (route.getAnyTypeKind() != anyTypeKind) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + anyTypeKind + ", expected " + route.getAnyTypeKind());
        throw sce;
    }
    String originalContent = route.getContent();
    LOG.debug("Updating route {} with content {}", routeTO.getKey(), routeTO.getContent());
    binder.update(route, routeTO);
    try {
        context.updateContext(routeTO.getKey());
    } catch (CamelException e) {
        // if an exception was thrown while updating the context, restore the former route definition
        LOG.debug("Update of route {} failed, reverting", routeTO.getKey());
        context.restoreRoute(routeTO.getKey(), originalContent);
        throw e;
    }
}
Also used : CamelException(org.apache.syncope.core.provisioning.camel.CamelException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) CamelRoute(org.apache.syncope.core.persistence.api.entity.CamelRoute) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class CamelRouteLogic method read.

@PreAuthorize("hasRole('" + CamelEntitlement.ROUTE_READ + "')")
@Transactional(readOnly = true)
public CamelRouteTO read(final AnyTypeKind anyTypeKind, final String key) {
    CamelRoute route = routeDAO.find(key);
    if (route == null) {
        throw new NotFoundException("CamelRoute with key=" + key);
    }
    if (route.getAnyTypeKind() != anyTypeKind) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + anyTypeKind + ", expected " + route.getAnyTypeKind());
        throw sce;
    }
    return binder.getRouteTO(route);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) CamelRoute(org.apache.syncope.core.persistence.api.entity.CamelRoute) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class UserITCase method enforceMandatoryCondition.

@Test
public void enforceMandatoryCondition() {
    UserTO userTO = getUniqueSampleTO("enforce@apache.org");
    userTO.getResources().add(RESOURCE_NAME_WS2);
    userTO.setPassword("newPassword12");
    AttrTO type = null;
    for (AttrTO attr : userTO.getPlainAttrs()) {
        if ("ctype".equals(attr.getSchema())) {
            type = attr;
        }
    }
    assertNotNull(type);
    userTO.getPlainAttrs().remove(type);
    try {
        userTO = createUser(userTO).getEntity();
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
    userTO.getPlainAttrs().add(type);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 4 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class UserITCase method enforceMandatoryConditionOnDerived.

@Test
public void enforceMandatoryConditionOnDerived() {
    ResourceTO resourceTO = resourceService.read(RESOURCE_NAME_CSV);
    assertNotNull(resourceTO);
    resourceTO.setKey("resource-csv-enforcing");
    resourceTO.setEnforceMandatoryCondition(true);
    Response response = resourceService.create(resourceTO);
    resourceTO = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
    assertNotNull(resourceTO);
    try {
        UserTO userTO = getUniqueSampleTO("syncope222@apache.org");
        userTO.getResources().add(resourceTO.getKey());
        userTO.setPassword("newPassword12");
        try {
            userTO = createUser(userTO).getEntity();
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
        }
        userTO.getAuxClasses().add("csv");
        userTO = createUser(userTO).getEntity();
        assertNotNull(userTO);
        assertEquals(Collections.singleton(resourceTO.getKey()), userTO.getResources());
    } finally {
        resourceService.delete(resourceTO.getKey());
    }
}
Also used : Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 5 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class UserITCase method delete.

@Test
public void delete() {
    try {
        userService.delete(UUID.randomUUID().toString());
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
    UserTO userTO = getSampleTO("qqgf.z@nn.com");
    // specify a propagation
    userTO.getResources().add(RESOURCE_NAME_TESTDB);
    userTO = createUser(userTO).getEntity();
    String key = userTO.getKey();
    ProvisioningResult<UserTO> result = deleteUser(key);
    assertNotNull(result);
    userTO = result.getEntity();
    assertEquals(key, userTO.getKey());
    assertTrue(userTO.getPlainAttrs().isEmpty());
    // check for propagation result
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    try {
        userService.delete(userTO.getKey());
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)240 Test (org.junit.jupiter.api.Test)105 UserTO (org.apache.syncope.common.lib.to.UserTO)50 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)40 Response (javax.ws.rs.core.Response)34 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)20 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)19 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)18 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 GroupTO (org.apache.syncope.common.lib.to.GroupTO)17 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)16 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 Map (java.util.Map)14 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ItemTO (org.apache.syncope.common.lib.to.ItemTO)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)11