Search in sources :

Example 6 with IdmCodeListDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto in project CzechIdMng by bcvsolutions.

the class DefaultCodeListManager method create.

@Override
@Transactional
public IdmCodeListDto create(String code, BasePermission... permission) {
    IdmCodeListDto codeList = new IdmCodeListDto();
    codeList.setCode(code);
    codeList.setName(code);
    // 
    return save(codeList, permission);
}
Also used : IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with IdmCodeListDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto in project CzechIdMng by bcvsolutions.

the class DefaultCodeListManager method get.

@Override
public IdmCodeListDto get(Serializable codeListIdentifier, BasePermission... permission) {
    Assert.notNull(codeListIdentifier, "CodeList identifier is required.");
    // 
    IdmCodeListDto codeList = (IdmCodeListDto) lookupService.lookupDto(IdmCodeListDto.class, codeListIdentifier);
    if (codeList == null) {
        return null;
    }
    if (ObjectUtils.isEmpty(PermissionUtils.trimNull(permission))) {
        return codeList;
    }
    // 
    return codeListService.get(codeList, permission);
}
Also used : IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto)

Example 8 with IdmCodeListDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto in project CzechIdMng by bcvsolutions.

the class CodeListItemByCodeEvaluatorIntegrationTest method testPermissions.

@Test
public void testPermissions() {
    // create codelist and items
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmCodeListDto codeListOne = codeListManager.create(getHelper().createName());
    IdmCodeListItemDto itemOne = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
    IdmCodeListItemDto itemTwo = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
    IdmCodeListDto codeListTwo = codeListManager.create(getHelper().createName());
    // other
    codeListManager.createItem(codeListTwo.getId(), getHelper().createName(), getHelper().createName());
    // 
    List<IdmCodeListItemDto> items = null;
    IdmRoleDto roleOne = getHelper().createRole();
    // 
    getHelper().createIdentityRole(identity, roleOne);
    // check - read without policy
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
        Assert.assertTrue(items.isEmpty());
    } finally {
        logout();
    }
    // 
    // without login
    items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
    Assert.assertTrue(items.isEmpty());
    // 
    // create authorization policies - assign to role
    getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.AUTOCOMPLETE);
    ConfigurationMap properties = new ConfigurationMap();
    properties.put(CodeListItemByCodeEvaluator.PARAMETER_CODELIST, codeListOne.getId());
    properties.put(CodeListItemByCodeEvaluator.PARAMETER_ITEM_CODES, itemOne.getCode());
    getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeEvaluator.class, properties, IdmBasePermission.AUTOCOMPLETE);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        // without read permission
        items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(items.isEmpty());
        // 
        // evaluate	access
        items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
        Assert.assertEquals(1, items.size());
        Assert.assertEquals(itemOne.getId(), items.get(0).getId());
        // 
        Set<String> permissions = codeListItemService.getPermissions(itemOne);
        Assert.assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.AUTOCOMPLETE.name())));
    } finally {
        logout();
    }
    // all items by default
    properties = new ConfigurationMap();
    properties.put(CodeListItemByCodeEvaluator.PARAMETER_CODELIST, codeListOne.getId());
    getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeEvaluator.class, properties, IdmBasePermission.AUTOCOMPLETE);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
        Assert.assertEquals(2, items.size());
        Assert.assertTrue(items.stream().anyMatch(i -> i.getId().equals(itemOne.getId())));
        Assert.assertTrue(items.stream().anyMatch(i -> i.getId().equals(itemTwo.getId())));
    } finally {
        logout();
    }
}
Also used : IdmCodeListItemService(eu.bcvsolutions.idm.core.eav.api.service.IdmCodeListItemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) CodeListManager(eu.bcvsolutions.idm.core.eav.api.service.CodeListManager) IdmCodeListItem(eu.bcvsolutions.idm.core.eav.entity.IdmCodeListItem) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 9 with IdmCodeListDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto in project CzechIdMng by bcvsolutions.

the class FormAttributteByCodeListEvaluatorIntegrationTest method testPermissions.

@Test
public void testPermissions() {
    // create codelist and items
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmCodeListDto codeListOne = codeListManager.create(getHelper().createName());
    IdmFormAttributeDto attributeOne = new IdmFormAttributeDto();
    attributeOne.setCode(getHelper().createName());
    attributeOne.setName(attributeOne.getCode());
    attributeOne.setPersistentType(PersistentType.SHORTTEXT);
    attributeOne.setFormDefinition(codeListOne.getFormDefinition().getId());
    attributeOne = formService.saveAttribute(attributeOne);
    IdmCodeListDto codeListTwo = codeListManager.create(getHelper().createName());
    IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto();
    attributeTwo.setCode(getHelper().createName());
    attributeTwo.setName(attributeTwo.getCode());
    attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
    attributeTwo.setFormDefinition(codeListTwo.getFormDefinition().getId());
    formService.saveAttribute(attributeTwo);
    // 
    List<IdmFormAttributeDto> attributes = null;
    IdmRoleDto roleOne = getHelper().createRole();
    // 
    getHelper().createIdentityRole(identity, roleOne);
    // check - read without policy
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        attributes = formAttributeService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(attributes.isEmpty());
    } finally {
        logout();
    }
    // 
    // without login
    attributes = formAttributeService.find(null, IdmBasePermission.READ).getContent();
    Assert.assertTrue(attributes.isEmpty());
    // 
    // create authorization policies - assign to role
    getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.READ);
    getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.FORMATTRIBUTE, IdmFormAttribute.class, FormAttributteByCodeListEvaluator.class);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        // without update permission
        attributes = formAttributeService.find(null, IdmBasePermission.UPDATE).getContent();
        Assert.assertTrue(attributes.isEmpty());
        // 
        // evaluate	access
        attributes = formAttributeService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, attributes.size());
        Assert.assertEquals(attributeOne.getId(), attributes.get(0).getId());
        // 
        Set<String> permissions = formAttributeService.getPermissions(attributeOne);
        Assert.assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
    } finally {
        logout();
    }
    // 
    getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.UPDATE);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        Set<String> permissions = formAttributeService.getPermissions(attributeOne);
        Assert.assertEquals(2, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
    } finally {
        logout();
    }
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmFormAttribute(eu.bcvsolutions.idm.core.eav.entity.IdmFormAttribute) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) CodeListManager(eu.bcvsolutions.idm.core.eav.api.service.CodeListManager) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 10 with IdmCodeListDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto in project CzechIdMng by bcvsolutions.

the class CodeListItemByCodeListEvaluatorIntegrationTest method testPermissions.

@Test
public void testPermissions() {
    // create codelist and items
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmCodeListDto codeListOne = codeListManager.create(getHelper().createName());
    IdmCodeListItemDto itemOne = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
    IdmCodeListDto codeListTwo = codeListManager.create(getHelper().createName());
    // other
    codeListManager.createItem(codeListTwo.getId(), getHelper().createName(), getHelper().createName());
    // 
    List<IdmCodeListItemDto> items = null;
    IdmRoleDto roleOne = getHelper().createRole();
    // 
    getHelper().createIdentityRole(identity, roleOne);
    // check - read without policy
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(items.isEmpty());
    } finally {
        logout();
    }
    // 
    // without login
    items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
    Assert.assertTrue(items.isEmpty());
    // 
    // create authorization policies - assign to role
    getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.READ);
    getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeListEvaluator.class);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        // without update permission
        items = codeListItemService.find(null, IdmBasePermission.UPDATE).getContent();
        Assert.assertTrue(items.isEmpty());
        // 
        // evaluate	access
        items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, items.size());
        Assert.assertEquals(itemOne.getId(), items.get(0).getId());
        // 
        Set<String> permissions = codeListItemService.getPermissions(itemOne);
        Assert.assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
    } finally {
        logout();
    }
    // 
    getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.UPDATE);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        Set<String> permissions = codeListItemService.getPermissions(itemOne);
        Assert.assertEquals(2, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
    } finally {
        logout();
    }
}
Also used : IdmCodeListItemService(eu.bcvsolutions.idm.core.eav.api.service.IdmCodeListItemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) CodeListManager(eu.bcvsolutions.idm.core.eav.api.service.CodeListManager) IdmCodeListItem(eu.bcvsolutions.idm.core.eav.entity.IdmCodeListItem) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Aggregations

IdmCodeListDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto)20 IdmCodeListItemDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto)9 Test (org.junit.Test)8 Transactional (org.springframework.transaction.annotation.Transactional)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 List (java.util.List)4 Assert (org.junit.Assert)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 CodeListManager (eu.bcvsolutions.idm.core.eav.api.service.CodeListManager)3 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)3 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)3 AbstractEvaluatorIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)3 Set (java.util.Set)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)2 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)2 IdmCodeListItemService (eu.bcvsolutions.idm.core.eav.api.service.IdmCodeListItemService)2