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;
}
}
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);
}
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);
}
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());
}
}
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());
}
}
Aggregations