use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class PlainSchemaTest method issueSYNCOPE418.
@Test
public void issueSYNCOPE418() {
PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
try {
plainSchemaDAO.save(schema);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertTrue(e.hasViolation(EntityViolationType.InvalidKey));
}
}
use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class RemediationTest method create.
@Test
public void create() {
Remediation remediation = entityFactory.newEntity(Remediation.class);
remediation.setAnyType(anyTypeDAO.find("PRINTER"));
remediation.setOperation(ResourceOperation.CREATE);
remediation.setError("Error");
remediation.setInstant(new Date());
remediation.setRemoteName("remote");
remediation.setPullTask(taskDAO.find("38abbf9e-a1a3-40a1-a15f-7d0ac02f47f1"));
// missing payload
try {
remediationDAO.save(remediation);
fail("This should not happen");
} catch (InvalidEntityException e) {
Set<EntityViolationType> violations = e.getViolations().values().iterator().next();
assertEquals(2, violations.size());
assertTrue(violations.stream().allMatch(violation -> violation.getPropertyPath().equals("payload")));
}
remediation.setPayload(UUID.randomUUID().toString());
// wrong payload for operation
try {
remediationDAO.save(remediation);
fail("This should not happen");
} catch (InvalidEntityException e) {
Set<EntityViolationType> violations = e.getViolations().values().iterator().next();
assertEquals(1, violations.size());
assertTrue(violations.stream().anyMatch(violation -> violation.getPropertyPath().equals("payload")));
}
remediation.setOperation(ResourceOperation.DELETE);
remediation = remediationDAO.save(remediation);
assertNotNull(remediation.getKey());
assertNotNull(remediation.getPullTask());
taskDAO.delete(remediation.getPullTask());
remediationDAO.flush();
remediation = remediationDAO.find(remediation.getKey());
assertNull(remediation.getPullTask());
}
use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class UserTest method save.
@Test
public void save() {
User user = entityFactory.newEntity(User.class);
user.setUsername("username");
user.setRealm(realmDAO.findByFullPath("/even/two"));
user.setCreator("admin");
user.setCreationDate(new Date());
user.setPassword("pass", CipherAlgorithm.SHA256);
try {
userDAO.save(user);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertNotNull(e);
}
user.setPassword("password123", CipherAlgorithm.SHA256);
user.setUsername("username!");
try {
userDAO.save(user);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertNotNull(e);
}
user.setUsername("username");
User actual = userDAO.save(user);
assertNotNull(actual);
assertEquals(1, actual.getPasswordHistory().size());
assertNotNull(userDAO.findLastChange(actual.getKey()));
assertEquals(actual.getLastChangeDate(), userDAO.findLastChange(actual.getKey()));
}
use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class VirSchemaTest method issueSYNCOPE418.
@Test
public void issueSYNCOPE418() {
VirSchema schema = entityFactory.newEntity(VirSchema.class);
schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
try {
virSchemaDAO.save(schema);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertTrue(e.hasViolation(EntityViolationType.InvalidKey));
}
}
use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class SCIMExceptionMapper method processInvalidEntityExceptions.
private ResponseBuilder processInvalidEntityExceptions(final Exception ex) {
InvalidEntityException iee = null;
if (ex instanceof InvalidEntityException) {
iee = (InvalidEntityException) ex;
}
if (ex instanceof TransactionSystemException && ROLLBACK_EXCLASS.isAssignableFrom(ex.getCause().getClass()) && ex.getCause().getCause() instanceof InvalidEntityException) {
iee = (InvalidEntityException) ex.getCause().getCause();
}
if (iee != null) {
ClientExceptionType exType;
if (iee.getEntityClassSimpleName().endsWith("Policy")) {
exType = ClientExceptionType.InvalidPolicy;
} else if (iee.getEntityClassSimpleName().equals(PlainAttr.class.getSimpleName())) {
exType = ClientExceptionType.InvalidValues;
} else {
try {
exType = ClientExceptionType.valueOf("Invalid" + iee.getEntityClassSimpleName());
} catch (IllegalArgumentException e) {
// ignore
exType = ClientExceptionType.InvalidEntity;
}
}
StringBuilder msg = new StringBuilder();
for (Map.Entry<Class<?>, Set<EntityViolationType>> violation : iee.getViolations().entrySet()) {
for (EntityViolationType violationType : violation.getValue()) {
msg.append(violationType.name()).append(": ").append(violationType.getMessage()).append('\n');
}
}
return builder(exType, msg.toString());
}
return null;
}
Aggregations