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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations