Search in sources :

Example 56 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class TemplateUtils method check.

public void check(final Map<String, AnyTO> templates, final ClientExceptionType clientExceptionType) {
    SyncopeClientException sce = SyncopeClientException.build(clientExceptionType);
    templates.values().forEach(value -> {
        value.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))).forEachOrdered(attrTO -> {
            sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0));
        });
        value.getVirAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))).forEachOrdered((attrTO) -> {
            sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0));
        });
        if (value instanceof UserTO) {
            UserTO template = (UserTO) value;
            if (StringUtils.isNotBlank(template.getUsername()) && !JexlUtils.isExpressionValid(template.getUsername())) {
                sce.getElements().add("Invalid JEXL: " + template.getUsername());
            }
            if (StringUtils.isNotBlank(template.getPassword()) && !JexlUtils.isExpressionValid(template.getPassword())) {
                sce.getElements().add("Invalid JEXL: " + template.getPassword());
            }
        } else if (value instanceof GroupTO) {
            GroupTO template = (GroupTO) value;
            if (StringUtils.isNotBlank(template.getName()) && !JexlUtils.isExpressionValid(template.getName())) {
                sce.getElements().add("Invalid JEXL: " + template.getName());
            }
        }
    });
    if (!sce.isEmpty()) {
        throw sce;
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) AnyTO(org.apache.syncope.common.lib.to.AnyTO) User(org.apache.syncope.core.persistence.api.entity.user.User) Autowired(org.springframework.beans.factory.annotation.Autowired) MapContext(org.apache.commons.jexl3.MapContext) GroupTO(org.apache.syncope.common.lib.to.GroupTO) StringUtils(org.apache.commons.lang3.StringUtils) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) Component(org.springframework.stereotype.Component) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Map(java.util.Map) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyTemplate(org.apache.syncope.core.persistence.api.entity.AnyTemplate) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) Transactional(org.springframework.transaction.annotation.Transactional) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 57 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class ExceptionMapperITCase method sameGroupName.

@Test
public void sameGroupName() {
    String groupUUID = getUUIDString();
    // Create the first group
    GroupTO groupTO1 = new GroupTO();
    groupTO1.setName("child1" + groupUUID);
    groupTO1.setRealm(SyncopeConstants.ROOT_REALM);
    createGroup(groupTO1);
    // Create the second group, with the same name of groupTO1
    GroupTO groupTO2 = new GroupTO();
    groupTO2.setName("child1" + groupUUID);
    groupTO2.setRealm(SyncopeConstants.ROOT_REALM);
    try {
        createGroup(groupTO2);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.EntityExists, e.getType());
        String message = ERROR_MESSAGES.getProperty("errMessage.UniqueConstraintViolation");
        assertEquals("EntityExists [" + message + "]", e.getMessage());
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 58 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupITCase method read.

@Test
public void read() {
    GroupTO groupTO = groupService.read("37d15e4c-cdc1-460b-a591-8505c8133806");
    assertNotNull(groupTO);
    assertNotNull(groupTO.getPlainAttrs());
    assertFalse(groupTO.getPlainAttrs().isEmpty());
    assertEquals(2, groupTO.getStaticUserMembershipCount());
}
Also used : GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 59 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupITCase method updateAsGroupOwner.

@Test
public void updateAsGroupOwner() {
    // 1. read group as admin
    GroupTO groupTO = groupService.read("ebf97068-aa4b-4a85-9f01-680e8c4cf227");
    // issue SYNCOPE-15
    assertNotNull(groupTO.getCreationDate());
    assertNotNull(groupTO.getLastChangeDate());
    assertEquals("admin", groupTO.getCreator());
    assertEquals("admin", groupTO.getLastModifier());
    // 2. prepare update
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.setName(new StringReplacePatchItem.Builder().value("Director").build());
    // 3. try to update as verdi, not owner of group 6 - fail
    GroupService groupService2 = clientFactory.create("verdi", ADMIN_PWD).getService(GroupService.class);
    try {
        groupService2.update(groupPatch);
        fail("This should not happen");
    } catch (ForbiddenException e) {
        assertNotNull(e);
    }
    // 4. update as puccini, owner of group 6 - success
    GroupService groupService3 = clientFactory.create("puccini", ADMIN_PWD).getService(GroupService.class);
    groupTO = groupService3.update(groupPatch).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
    }).getEntity();
    assertEquals("Director", groupTO.getName());
    // issue SYNCOPE-15
    assertNotNull(groupTO.getCreationDate());
    assertNotNull(groupTO.getLastChangeDate());
    assertEquals("admin", groupTO.getCreator());
    assertEquals("puccini", groupTO.getLastModifier());
    assertTrue(groupTO.getCreationDate().before(groupTO.getLastChangeDate()));
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) GroupService(org.apache.syncope.common.rest.api.service.GroupService) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 60 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupITCase method issue178.

@Test
public void issue178() {
    GroupTO groupTO = new GroupTO();
    String groupName = "torename" + getUUIDString();
    groupTO.setName(groupName);
    groupTO.setRealm("/");
    GroupTO actual = createGroup(groupTO).getEntity();
    assertNotNull(actual);
    assertEquals(groupName, actual.getName());
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(actual.getKey());
    String renamedGroup = "renamed" + getUUIDString();
    groupPatch.setName(new StringReplacePatchItem.Builder().value(renamedGroup).build());
    actual = updateGroup(groupPatch).getEntity();
    assertNotNull(actual);
    assertEquals(renamedGroup, actual.getName());
}
Also used : StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

GroupTO (org.apache.syncope.common.lib.to.GroupTO)90 Test (org.junit.jupiter.api.Test)47 UserTO (org.apache.syncope.common.lib.to.UserTO)34 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)23 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)16 List (java.util.List)15 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)14 Response (javax.ws.rs.core.Response)13 NamingException (javax.naming.NamingException)12 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 Map (java.util.Map)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 AccessControlException (java.security.AccessControlException)10 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Collections (java.util.Collections)9