Search in sources :

Example 6 with InvalidEntityException

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));
    }
}
Also used : PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 7 with InvalidEntityException

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());
}
Also used : Set(java.util.Set) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation) Date(java.util.Date) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 8 with InvalidEntityException

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()));
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) Date(java.util.Date) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 9 with InvalidEntityException

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));
    }
}
Also used : VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 10 with InvalidEntityException

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;
}
Also used : Set(java.util.Set) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) TransactionSystemException(org.springframework.transaction.TransactionSystemException) Map(java.util.Map) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType)

Aggregations

InvalidEntityException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException)18 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)13 Test (org.junit.jupiter.api.Test)13 User (org.apache.syncope.core.persistence.api.entity.user.User)6 Set (java.util.Set)4 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)4 Date (java.util.Date)3 Map (java.util.Map)2 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)2 EntityViolationType (org.apache.syncope.common.lib.types.EntityViolationType)2 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)2 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)2 Realm (org.apache.syncope.core.persistence.api.entity.Realm)2 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)2 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)2 JPAUser (org.apache.syncope.core.persistence.jpa.entity.user.JPAUser)2 Transactional (org.springframework.transaction.annotation.Transactional)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1