Search in sources :

Example 11 with IdmFormAttributeDto

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

the class BasicVirtualConnector method generateSchema.

/**
 * Generate schema from connector configuration and form definition
 *
 * @return
 */
private IcSchemaImpl generateSchema() {
    IcSchemaImpl schema = new IcSchemaImpl();
    List<IcObjectClassInfo> objectClasses = schema.getDeclaredObjectClasses();
    IcObjectClassInfoImpl objectClass = new IcObjectClassInfoImpl();
    objectClass.setType(IcObjectClassInfo.ACCOUNT);
    List<IcAttributeInfo> attributes = objectClass.getAttributeInfos();
    // Create UID schema attribute
    IcAttributeInfoImpl attributeUid = new IcAttributeInfoImpl();
    attributeUid.setClassType(String.class.getName());
    attributeUid.setCreateable(true);
    attributeUid.setMultivalued(false);
    attributeUid.setName(IcAttributeInfo.NAME);
    attributeUid.setNativeName(VsAccount_.uid.getName());
    attributeUid.setReadable(true);
    attributeUid.setRequired(true);
    attributeUid.setReturnedByDefault(true);
    attributeUid.setUpdateable(true);
    attributes.add(attributeUid);
    // Create ENABLE schema attribute
    if (this.virtualConfiguration.isDisableSupported()) {
        IcAttributeInfoImpl attributeDisabled = new IcAttributeInfoImpl();
        attributeDisabled.setClassType(Boolean.class.getName());
        attributeDisabled.setCreateable(true);
        attributeDisabled.setMultivalued(false);
        attributeDisabled.setName(IcAttributeInfo.ENABLE);
        attributeDisabled.setNativeName(VsAccount_.enable.getName());
        attributeDisabled.setReadable(true);
        attributeDisabled.setRequired(false);
        attributeDisabled.setReturnedByDefault(true);
        attributeDisabled.setUpdateable(true);
        attributes.add(attributeDisabled);
    }
    // Attributes from definition and configuration
    Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
        IdmFormAttributeDto formAttribute = formAttributeService.findAttribute(VsAccount.class.getName(), formDefinition.getCode(), virtualAttirbute);
        if (formAttribute == null) {
            return;
        }
        IcAttributeInfoImpl attribute = new IcAttributeInfoImpl();
        String classType = this.convertToSchemaClassType(formAttribute.getPersistentType());
        attribute.setClassType(classType);
        attribute.setCreateable(!formAttribute.isReadonly());
        attribute.setMultivalued(formAttribute.isMultiple());
        attribute.setName(virtualAttirbute);
        attribute.setNativeName(virtualAttirbute);
        attribute.setReadable(true);
        attribute.setRequired(formAttribute.isRequired());
        attribute.setReturnedByDefault(true);
        attribute.setUpdateable(!formAttribute.isReadonly());
        attributes.add(attribute);
    });
    objectClasses.add(objectClass);
    return schema;
}
Also used : IcObjectClassInfoImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassInfoImpl) VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) IcSchemaImpl(eu.bcvsolutions.idm.ic.impl.IcSchemaImpl) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IcAttributeInfoImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeInfoImpl)

Example 12 with IdmFormAttributeDto

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

the class DefaultVsSystemService method create.

@Override
public SysSystemDto create(VsSystemDto vsSystem) {
    Assert.notNull(vsSystem, "Vs system dto cannot be null (for create new virtual system)");
    Assert.notNull(vsSystem.getName(), "Vs system name cannot be null (for create new virtual system)");
    LOG.info("Create new virtual system with name [{}].", vsSystem.getName());
    SysSystemDto system = new SysSystemDto();
    // Find connector for VS
    Class<? extends VsVirtualConnector> defaultVirtualConnector = BasicVirtualConnector.class;
    IcConnectorClass connectorAnnotation = defaultVirtualConnector.getAnnotation(IcConnectorClass.class);
    IcConnectorInfo info = CzechIdMIcConvertUtil.convertConnectorClass(connectorAnnotation, (Class<? extends IcConnector>) defaultVirtualConnector);
    // Set connector key for VS
    system.setConnectorKey(new SysConnectorKeyDto(info.getConnectorKey()));
    system.setName(vsSystem.getName());
    // Create system
    system = this.systemService.save(system, IdmBasePermission.CREATE);
    // Find and update attributes for implementers
    IdmFormDefinitionDto connectorFormDef = this.systemService.getConnectorFormDefinition(system.getConnectorInstance());
    IdmFormAttributeDto implementersFormAttr = connectorFormDef.getMappedAttributeByCode(IMPLEMENTERS_PROPERTY);
    formService.saveValues(system, implementersFormAttr, new ArrayList<>(vsSystem.getImplementers()));
    IdmFormAttributeDto implementerRolesFormAttr = connectorFormDef.getMappedAttributeByCode(IMPLEMENTER_ROLES_PROPERTY);
    formService.saveValues(system, implementerRolesFormAttr, new ArrayList<>(vsSystem.getImplementerRoles()));
    IdmFormAttributeDto attributesFormAttr = connectorFormDef.getMappedAttributeByCode(ATTRIBUTES_PROPERTY);
    if (!vsSystem.getAttributes().isEmpty()) {
        formService.saveValues(system, attributesFormAttr, new ArrayList<>(vsSystem.getAttributes()));
    } else {
        List<Serializable> defaultAttributes = Lists.newArrayList((Serializable[]) BasicVirtualConfiguration.DEFAULT_ATTRIBUTES);
        defaultAttributes.add(RIGHTS_ATTRIBUTE);
        formService.saveValues(system, attributesFormAttr, defaultAttributes);
    }
    this.systemService.checkSystem(system);
    // Search attribute definition for rights and set him to multivalue
    String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId().toString());
    String type = VsAccount.class.getName();
    IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
    IdmFormAttributeDto rightsFormAttr = formAttributeService.findAttribute(type, definition.getCode(), RIGHTS_ATTRIBUTE);
    if (rightsFormAttr != null) {
        rightsFormAttr.setMultiple(true);
        formService.saveAttribute(rightsFormAttr);
    }
    // Generate schema
    List<SysSchemaObjectClassDto> schemas = this.systemService.generateSchema(system);
    SysSchemaObjectClassDto schemaAccount = schemas.stream().filter(schema -> IcObjectClassInfo.ACCOUNT.equals(schema.getObjectClassName())).findFirst().orElse(null);
    Assert.notNull(schemaAccount, "We cannot found schema for ACCOUNT!");
    // Create mapping by default attributes
    this.createDefaultMapping(system, schemaAccount, vsSystem);
    return this.systemService.get(system.getId());
}
Also used : Serializable(java.io.Serializable) BasicVirtualConnector(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConnector) SysConnectorKeyDto(eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 13 with IdmFormAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testRemoveLastRuleWithoutCheck.

@Test
public void testRemoveLastRuleWithoutCheck() {
    String eavCode = "testingEav";
    Long testEavIdentityValue = System.currentTimeMillis();
    UUID testEavContractValue = UUID.randomUUID();
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmRoleDto role = testHelper.createRole();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    // create two eav attributes (for identity and contract)
    IdmFormAttributeDto eavAttributeIdentity = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.LONG);
    testHelper.setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.LONG);
    IdmFormAttributeDto eavAttributeContract = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.UUID);
    testHelper.setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.UUID);
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    IdmAutomaticRoleAttributeRuleDto rule1 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttributeIdentity.getId(), testEavIdentityValue.toString());
    IdmAutomaticRoleAttributeRuleDto rule2 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract.getId(), testEavContractValue.toString());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    automaticRoleAttributeRuleService.delete(rule1);
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    automaticRoleAttributeRuleService.delete(rule2);
    // in this case we not able remove the last automatic role from identity
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 14 with IdmFormAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testTwoAutomaticRoleMoreRules.

@Test
public void testTwoAutomaticRoleMoreRules() {
    String testEmail = "testing-email-" + System.currentTimeMillis() + "@example.tld";
    String testEavContractValue = "testing-eav-value-" + System.currentTimeMillis();
    String testEavIdentityValue = "testing-eav-value-" + System.currentTimeMillis();
    String testPositionName = "testing-position-name-" + System.currentTimeMillis();
    // 
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmRoleDto role = testHelper.createRole();
    IdmRoleDto role2 = testHelper.createRole();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    // 
    // create two eav attributes (for identity and contract)
    IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.SHORTTEXT);
    testHelper.setEavValue(primeContract, createEavAttribute, IdmIdentityContract.class, testEavContractValue + "-not-passed", PersistentType.SHORTTEXT);
    IdmFormAttributeDto createEavAttribute2 = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.SHORTTEXT);
    testHelper.setEavValue(identity, createEavAttribute2, IdmIdentity.class, testEavIdentityValue + "-not-passed", PersistentType.SHORTTEXT);
    // 
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    IdmAutomaticRoleAttributeDto automaticRole2 = testHelper.createAutomaticRole(role2.getId());
    // 
    // rules for first automatic role
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.email.getName(), null, testEmail);
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, createEavAttribute.getId(), testEavContractValue);
    // 
    // rules for second automatic role
    testHelper.createAutomaticRoleRule(automaticRole2.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, testPositionName);
    testHelper.createAutomaticRoleRule(automaticRole2.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute2.getId(), testEavIdentityValue);
    // 
    // rules are not passed
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    // set attribute for only one part from each rules
    primeContract.setPosition(testPositionName);
    primeContract = identityContractService.save(primeContract);
    identity.setEmail(testEmail);
    identity = identityService.save(identity);
    // 
    // still zero, only one part of rules are passed
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    testHelper.setEavValue(primeContract, createEavAttribute, IdmIdentityContract.class, testEavContractValue, PersistentType.SHORTTEXT);
    // 
    // one automatic roles has passed all rules
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    IdmIdentityRoleDto identityRole = identityRoles.get(0);
    assertEquals(automaticRole.getRole(), identityRole.getRole());
    assertEquals(automaticRole.getId(), identityRole.getRoleTreeNode());
    // 
    identity.setEmail(testEmail + "-not-passed");
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    testHelper.setEavValue(identity, createEavAttribute2, IdmIdentity.class, testEavIdentityValue, PersistentType.SHORTTEXT);
    // passed second automatic role
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRole = identityRoles.get(0);
    assertEquals(automaticRole2.getRole(), identityRole.getRole());
    assertEquals(automaticRole2.getId(), identityRole.getRoleTreeNode());
    // 
    identity.setEmail(testEmail);
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    for (IdmIdentityRoleDto identityRol : identityRoles) {
        if (identityRol.getRole().equals(role.getId())) {
            assertEquals(automaticRole.getRole(), identityRol.getRole());
            assertEquals(automaticRole.getId(), identityRol.getRoleTreeNode());
        } else {
            assertEquals(automaticRole2.getRole(), identityRol.getRole());
            assertEquals(automaticRole2.getId(), identityRol.getRoleTreeNode());
        }
    }
    // 
    // try delete
    automaticRoleAttributeService.delete(automaticRole2);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    identityRole = identityRoles.get(0);
    assertEquals(automaticRole.getRole(), identityRole.getRole());
    assertEquals(automaticRole.getId(), identityRole.getRoleTreeNode());
    // 
    automaticRoleAttributeService.delete(automaticRole);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with IdmFormAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleLongEav.

@Test
public void testAutomaticRoleLongEav() {
    Long testValue = 123456l;
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.LONG);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute.getId(), testValue.toString());
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    // change eav value
    testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue, PersistentType.LONG);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)67 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)40 Test (org.junit.Test)40 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)22 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)15 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)15 Transactional (org.springframework.transaction.annotation.Transactional)12 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)11 FormableEntity (eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)10 ArrayList (java.util.ArrayList)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)7 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)7 UUID (java.util.UUID)7 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 Serializable (java.io.Serializable)5 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)4 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)4