use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultAuthorizationManagerIntegrationTest method testDefaultRoleSubRoles.
@Test
@Transactional
public void testDefaultRoleSubRoles() {
IdmIdentityDto identity = getHelper().createIdentity();
// create new default role with two enabled sub roles + one disabled.
IdmRoleDto defaultRole = getHelper().createRole();
IdmRoleDto subRoleOne = getHelper().createRole();
IdmRoleDto subRoleTwo = getHelper().createRole();
IdmRoleDto role = getHelper().createRole();
role.setDisabled(true);
IdmRoleDto disabledSubRole = roleService.save(role);
getHelper().createRoleComposition(defaultRole, subRoleOne);
getHelper().createRoleComposition(subRoleOne, subRoleTwo);
getHelper().createRoleComposition(defaultRole, disabledSubRole);
//
// create distinct authorization policies
IdmAuthorizationPolicyDto policyDefault = getHelper().createBasePolicy(defaultRole.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.CREATE);
IdmAuthorizationPolicyDto policyOne = getHelper().createBasePolicy(subRoleOne.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.UPDATE);
IdmAuthorizationPolicyDto policyTwo = getHelper().createBasePolicy(subRoleTwo.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ);
IdmAuthorizationPolicyDto policyDisabled = getHelper().createBasePolicy(disabledSubRole.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.DELETE);
//
getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRole.getCode());
//
List<IdmAuthorizationPolicyDto> enabledDistinctPolicies = manager.getEnabledDistinctPolicies(identity.getId(), IdmIdentity.class);
Assert.assertEquals(3, enabledDistinctPolicies.size());
Assert.assertTrue(enabledDistinctPolicies.stream().anyMatch(p -> p.getId().equals(policyDefault.getId())));
Assert.assertTrue(enabledDistinctPolicies.stream().anyMatch(p -> p.getId().equals(policyOne.getId())));
Assert.assertTrue(enabledDistinctPolicies.stream().anyMatch(p -> p.getId().equals(policyTwo.getId())));
Assert.assertTrue(enabledDistinctPolicies.stream().allMatch(p -> !p.getId().equals(policyDisabled.getId())));
//
Set<String> authorities = manager.getAuthorities(identity.getId(), IdmIdentity.class);
Assert.assertEquals(3, authorities.size());
Assert.assertTrue(authorities.stream().anyMatch(a -> a.equals(IdmBasePermission.CREATE.getName())));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.equals(IdmBasePermission.UPDATE.getName())));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.equals(IdmBasePermission.READ.getName())));
Assert.assertTrue(authorities.stream().allMatch(a -> !a.equals(IdmBasePermission.DELETE.getName())));
//
try {
getHelper().login(identity);
Set<String> permissions = identityService.getPermissions(identity.getId());
Assert.assertEquals(3, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.CREATE.getName())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.getName())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.getName())));
Assert.assertTrue(permissions.stream().allMatch(p -> !p.equals(IdmBasePermission.DELETE.getName())));
} finally {
logout();
}
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testCreateIdentityWithAutomaticRoleByEavAttribute.
@Test
public void testCreateIdentityWithAutomaticRoleByEavAttribute() {
String username = getHelper().createName();
SysSystemDto system = initData(username, "mockIdentity@idm.eu");
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
config.setCreateDefaultContract(true);
config.setStartAutoRoleRec(true);
syncConfigService.save(config);
//
// create form definition, roles, automatic role etc.
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
// sync supports default definition only
IdmFormAttributeDto formAttribute = new IdmFormAttributeDto(getHelper().createName());
IdmFormAttributeDto formAttributeIdentity = formService.saveAttribute(IdmIdentityDto.class, formAttribute);
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeIdentity.getId(), "mockIdentity@idm.eu");
//
// create mapping to eav attribute - leader = eav
SysSystemMappingDto syncSystemMapping = systemMappingService.get(config.getSystemMapping());
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(syncSystemMapping.getId());
SysSystemAttributeMappingDto lastnameAttributeMapping = schemaAttributeMappingService.findBySystemMappingAndName(syncSystemMapping.getId(), ATTRIBUTE_EMAIL);
lastnameAttributeMapping.setEntityAttribute(false);
lastnameAttributeMapping.setExtendedAttribute(true);
lastnameAttributeMapping.setIdmPropertyName(formAttributeIdentity.getCode());
schemaAttributeMappingService.save(lastnameAttributeMapping);
//
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(username);
identityFilter.setAddEavMetadata(Boolean.TRUE);
List<IdmIdentityDto> identities = identityService.find(identityFilter, null).getContent();
Assert.assertEquals(1, identities.size());
Assert.assertEquals("mockIdentity@idm.eu", identities.get(0).getEavs().stream().filter(fi -> fi.getFormDefinition().isMain()).findFirst().get().getValues().stream().filter(v -> v.getFormAttribute().equals(formAttributeIdentity.getId())).findFirst().get().getShortTextValue());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identities.get(0).getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(role.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subRole.getId())));
// Delete log
syncLogService.delete(log);
syncConfigService.delete(config);
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testInvalidateAndCreateAnotherContractWithAutomaticRoles.
@Test
public void testInvalidateAndCreateAnotherContractWithAutomaticRoles() {
SysSystemDto system = initData();
SysSystemDto systemProvisioning = helper.createTestResourceSystem(true);
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
contractService.delete(getHelper().getPrimeContract(identity));
//
// create first contract with validity and automatic role
String positionCode = getHelper().createName();
IdmTreeNodeDto node = getHelper().createTreeNode();
IdmRoleDto role = getHelper().createRole();
helper.createRoleSystem(role, systemProvisioning);
getHelper().createAutomaticRole(role, node);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setValidFrom(LocalDate.now().minusMonths(1));
contract.setValidTill(LocalDate.now().plusMonths(1));
contract.setDescription(positionCode);
contract.setPosition(positionCode);
contract.setWorkPosition(node.getId());
contract = contractService.save(contract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(identity.getId());
Assert.assertEquals(1, contractService.find(contractFilter, null).getTotalElements());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertNotNull(assignedRoles.get(0).getValidFrom());
Assert.assertNotNull(assignedRoles.get(0).getValidTill());
Assert.assertEquals(contract.getValidFrom(), assignedRoles.get(0).getValidFrom());
Assert.assertEquals(contract.getValidTill(), assignedRoles.get(0).getValidTill());
// create target system entity - invalid
TestContractResource invalidContractResource = new TestContractResource();
invalidContractResource.setId(positionCode);
invalidContractResource.setName(positionCode);
invalidContractResource.setOwner(identity.getUsername());
invalidContractResource.setMain(Boolean.TRUE.toString());
invalidContractResource.setWorkposition(node.getId().toString());
invalidContractResource.setDescription(positionCode);
invalidContractResource.setValidTill(LocalDate.now().minusDays(1));
this.getBean().createContractData(invalidContractResource);
//
String validPositionCode = getHelper().createName();
TestContractResource validContractResource = new TestContractResource();
validContractResource.setId(validPositionCode);
validContractResource.setName(validPositionCode);
validContractResource.setOwner(identity.getUsername());
validContractResource.setMain(Boolean.FALSE.toString());
validContractResource.setWorkposition(node.getId().toString());
validContractResource.setDescription(validPositionCode);
this.getBean().createContractData(validContractResource);
//
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 1);
checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
UUID transactionId = log.getTransactionId();
Assert.assertFalse(log.isRunning());
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().allMatch(c -> c.getTransactionId().equals(transactionId)));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.isValid()));
Assert.assertTrue(contracts.stream().anyMatch(c -> !c.isValid()));
assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertNull(assignedRoles.get(0).getValidFrom());
Assert.assertNull(assignedRoles.get(0).getValidTill());
Assert.assertEquals(transactionId, assignedRoles.get(0).getTransactionId());
// find provisioning archive => prevent drop and create => update only in this transaction id
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(systemProvisioning.getId());
filter.setTransactionId(transactionId);
List<SysProvisioningArchiveDto> executedOperations = provisioningArchiveService.find(filter, null).getContent();
Assert.assertFalse(executedOperations.isEmpty());
Assert.assertTrue(executedOperations.stream().allMatch(o -> o.getOperationType() != ProvisioningEventType.DELETE));
Assert.assertTrue(executedOperations.stream().allMatch(o -> o.getResultState() == OperationState.EXECUTED));
// Delete log
syncLogService.delete(log);
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testRegexValidation.
@Test
public void testRegexValidation() {
// prepare form definition a test saving form values
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
String attributeName = getHelper().createName();
// ip address regex (copied from https://www.mkyong.com/regular-expressions/how-to-validate-ip-address-with-regular-expression/)
String ipRegex = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
attribute.setCode(attributeName);
attribute.setName(attributeName);
attribute.setPersistentType(PersistentType.SHORTTEXT);
attribute.setRegex(ipRegex);
String validationMessage = "invalid...";
attribute.setValidationMessage(validationMessage);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
//
IdmFormValueDto value = new IdmFormValueDto(attribute);
value.setValue("one");
//
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(formDefinitionOne);
formInstance.setValues(Lists.newArrayList(value));
//
List<InvalidFormAttributeDto> validationErrors = formService.validate(formInstance);
//
Assert.assertEquals(1, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getRegexValue().equals(ipRegex)));
//
value.setValue("125.123.255.111");
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
//
value.setValue("1.1.1.1");
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
//
value.setValue("1.1.1.1.");
validationErrors = formService.validate(formInstance);
Assert.assertEquals(1, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getRegexValue().equals(ipRegex)));
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMessage().equals(validationMessage)));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testDeleteValue.
@Test
public void testDeleteValue() {
Identifiable owner = getHelper().createIdentity((GuardedString) null);
//
// create definition with attribute
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
String attributeName = getHelper().createName();
attribute.setCode(attributeName);
attribute.setName(attribute.getCode());
attribute.setMultiple(true);
attribute.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
//
// fill values
formService.saveValues(owner, attribute, Lists.newArrayList(FORM_VALUE_ONE, FORM_VALUE_TWO));
Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
//
// check value and persistent type
Assert.assertEquals(2, m.get(attributeName).size());
Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_ONE)));
Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_TWO)));
//
// delete one value
formService.deleteValue(m.get(attributeName).stream().filter(v -> v.getValue().equals(FORM_VALUE_ONE)).findFirst().get());
m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
//
Assert.assertEquals(1, m.get(attributeName).size());
Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_TWO)));
}
Aggregations