Search in sources :

Example 31 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class AnyTypeTest method saveInvalidName.

@Test
public void saveInvalidName() {
    assertThrows(InvalidEntityException.class, () -> {
        AnyType newType = entityFactory.newEntity(AnyType.class);
        newType.setKey("group");
        newType.setKind(AnyTypeKind.ANY_OBJECT);
        anyTypeDAO.save(newType);
    });
}
Also used : AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 32 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class AnyTypeTest method delete.

@Test
public void delete() {
    AnyType otherType = anyTypeDAO.find("PRINTER");
    assertNotNull(otherType);
    anyTypeDAO.delete(otherType.getKey());
    assertNull(anyTypeDAO.find("PRINTER"));
}
Also used : AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 33 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class AnyTypeTest method saveInvalidKind.

@Test
public void saveInvalidKind() {
    assertThrows(InvalidEntityException.class, () -> {
        AnyType newType = entityFactory.newEntity(AnyType.class);
        newType.setKey("new type");
        newType.setKind(AnyTypeKind.USER);
        anyTypeDAO.save(newType);
    });
}
Also used : AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 34 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class AnyTypeTest method save.

@Test
public void save() {
    AnyType newType = entityFactory.newEntity(AnyType.class);
    newType.setKey("new type");
    newType.setKind(AnyTypeKind.ANY_OBJECT);
    newType.add(anyTypeClassDAO.find("generic membership"));
    newType.add(anyTypeClassDAO.find("csv"));
    newType = anyTypeDAO.save(newType);
    assertNotNull(newType);
    assertFalse(newType.getClasses().isEmpty());
}
Also used : AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 35 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class GroupValidator method isValid.

@Override
public boolean isValid(final Group group, final ConstraintValidatorContext context) {
    context.disableDefaultConstraintViolation();
    boolean isValid = true;
    if (group.getUserOwner() != null && group.getGroupOwner() != null) {
        isValid = false;
        context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidGroupOwner, "A group must either be owned by an user or a group, not both")).addPropertyNode("owner").addConstraintViolation();
    }
    if (isValid && (group.getName() == null || !KEY_PATTERN.matcher(group.getName()).matches())) {
        isValid = false;
        context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidName, "Invalid group name")).addPropertyNode("name").addConstraintViolation();
    }
    if (isValid) {
        Set<AnyType> anyTypes = new HashSet<>();
        for (ADynGroupMembership memb : group.getADynMemberships()) {
            anyTypes.add(memb.getAnyType());
            if (memb.getAnyType().getKind() != AnyTypeKind.ANY_OBJECT) {
                isValid = false;
                context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidADynMemberships, "No user or group dynamic membership condition are allowed here")).addPropertyNode("aDynMemberships").addConstraintViolation();
            }
        }
        if (isValid && anyTypes.size() < group.getADynMemberships().size()) {
            context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidADynMemberships, "Each dynamic membership condition requires a different " + AnyType.class.getSimpleName())).addPropertyNode("aDynMemberships").addConstraintViolation();
            return false;
        }
    }
    return isValid;
}
Also used : ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) HashSet(java.util.HashSet)

Aggregations

AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)35 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)13 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)9 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Collectors (java.util.stream.Collectors)6 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)6 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Component (org.springframework.stereotype.Component)6 ArrayList (java.util.ArrayList)5 StringUtils (org.apache.commons.lang3.StringUtils)5 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)5 Realm (org.apache.syncope.core.persistence.api.entity.Realm)5 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)5 Group (org.apache.syncope.core.persistence.api.entity.group.Group)5 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)5 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)5 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)4