use of eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountServiceTest method getConnectorObjectNotFullForbiddenTest.
/**
* We do not create relation Identity account ... we must not have the
* permissions on the account
*/
@Test(expected = ForbiddenEntityException.class)
public void getConnectorObjectNotFullForbiddenTest() {
String userOneName = "UserOne";
String eavAttributeName = "EAV_ATTRIBUTE";
SysSystemDto system = initData();
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
// Find and delete EAV schema attribute.
SysSchemaAttributeDto eavAttribute = schemaAttributeService.find(schemaAttributeFilter, null).getContent().stream().filter(attribute -> attribute.getName().equalsIgnoreCase(eavAttributeName)).findFirst().orElse(null);
Assert.assertNotNull(eavAttribute);
schemaAttributeService.delete(eavAttribute);
Assert.assertNotNull(system);
// Change resources (set state on exclude) .. must be call in transaction
this.getBean().persistResource(createResource(userOneName, new LocalDateTime()));
AccAccountDto account = new AccAccountDto();
account.setEntityType(SystemEntityType.IDENTITY);
account.setSystem(system.getId());
account.setAccountType(AccountType.PERSONAL);
account.setUid(userOneName);
account = accountService.save(account);
IdmIdentityDto identity = helper.createIdentity();
// Create role with evaluator
IdmRoleDto role = helper.createRole();
IdmAuthorizationPolicyDto policyAccount = new IdmAuthorizationPolicyDto();
policyAccount.setRole(role.getId());
policyAccount.setGroupPermission(AccGroupPermission.ACCOUNT.getName());
policyAccount.setAuthorizableType(AccAccount.class.getCanonicalName());
policyAccount.setEvaluator(ReadAccountByIdentityEvaluator.class);
authorizationPolicyService.save(policyAccount);
// Assign role with evaluator
helper.createIdentityRole(identity, role);
logout();
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
IcConnectorObject connectorObject = accountService.getConnectorObject(account, IdmBasePermission.READ);
Assert.assertNotNull(connectorObject);
Assert.assertEquals(userOneName, connectorObject.getUidValue());
// EAV attribute must be null, because we deleted the schema definition
Assert.assertNull(connectorObject.getAttributeByName(eavAttributeName));
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountServiceTest method getConnectorObjectNotFullTest.
@Test
public void getConnectorObjectNotFullTest() {
String userOneName = "UserOne";
String eavAttributeName = "EAV_ATTRIBUTE";
SysSystemDto system = initData();
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
// Find and delete EAV schema attribute.
SysSchemaAttributeDto eavAttribute = schemaAttributeService.find(schemaAttributeFilter, null).getContent().stream().filter(attribute -> attribute.getName().equalsIgnoreCase(eavAttributeName)).findFirst().orElse(null);
Assert.assertNotNull(eavAttribute);
schemaAttributeService.delete(eavAttribute);
Assert.assertNotNull(system);
// Change resources (set state on exclude) .. must be call in transaction
this.getBean().persistResource(createResource(userOneName, new LocalDateTime()));
AccAccountDto account = new AccAccountDto();
account.setEntityType(SystemEntityType.IDENTITY);
account.setSystem(system.getId());
account.setAccountType(AccountType.PERSONAL);
account.setUid(userOneName);
account = accountService.save(account);
IdmIdentityDto identity = helper.createIdentity();
AccIdentityAccountDto accountIdentityOne = new AccIdentityAccountDto();
accountIdentityOne.setIdentity(identity.getId());
accountIdentityOne.setOwnership(true);
accountIdentityOne.setAccount(account.getId());
accountIdentityOne = identityAccountService.save(accountIdentityOne);
// Create role with evaluator
IdmRoleDto role = helper.createRole();
IdmAuthorizationPolicyDto policyAccount = new IdmAuthorizationPolicyDto();
policyAccount.setRole(role.getId());
policyAccount.setGroupPermission(AccGroupPermission.ACCOUNT.getName());
policyAccount.setAuthorizableType(AccAccount.class.getCanonicalName());
policyAccount.setEvaluator(ReadAccountByIdentityEvaluator.class);
authorizationPolicyService.save(policyAccount);
// Assign role with evaluator
helper.createIdentityRole(identity, role);
logout();
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
IcConnectorObject connectorObject = accountService.getConnectorObject(account, IdmBasePermission.READ);
Assert.assertNotNull(connectorObject);
Assert.assertEquals(userOneName, connectorObject.getUidValue());
// EAV attribute must be null, because we deleted the schema definition
Assert.assertNull(connectorObject.getAttributeByName(eavAttributeName));
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSchemaObjectClassService method delete.
@Override
@Transactional
public void delete(SysSchemaObjectClassDto schemaObjectClass, BasePermission... permission) {
Assert.notNull(schemaObjectClass);
//
// remove all schema attributes for
SysSchemaAttributeFilter filter = new SysSchemaAttributeFilter();
filter.setObjectClassId(schemaObjectClass.getId());
sysSchemaAttributeService.find(filter, null).forEach(schemaAttribute -> {
sysSchemaAttributeService.delete(schemaAttribute);
});
// delete all mappings
systemMappingService.findByObjectClass(schemaObjectClass, null, null).forEach(systemMapping -> {
systemMappingService.delete(systemMapping);
});
//
super.delete(schemaObjectClass, permission);
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method generateSchema.
@Override
@Transactional
public List<SysSchemaObjectClassDto> generateSchema(SysSystemDto system) {
Assert.notNull(system);
Assert.notNull(system.getId());
// Find connector identification persisted in system
IcConnectorKey connectorKey = system.getConnectorKey();
if (connectorKey == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Find connector configuration persisted in system
IcConnectorConfiguration connectorConfig = getConnectorConfiguration(system);
if (connectorConfig == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Call IC module and find schema for given connector key and
// configuration
IcSchema icSchema = icConfigurationFacade.getSchema(system.getConnectorInstance(), connectorConfig);
if (icSchema == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_SCHEMA_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Load existing object class from system
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(system.getId());
List<SysSchemaObjectClassDto> sysObjectClassesInSystem = null;
Page<SysSchemaObjectClassDto> page = objectClassService.find(objectClassFilter, null);
sysObjectClassesInSystem = page.getContent();
// Convert IC schema to ACC entities
List<SysSchemaObjectClassDto> sysObjectClasses = new ArrayList<SysSchemaObjectClassDto>();
List<SysSchemaAttributeDto> sysAttributes = new ArrayList<SysSchemaAttributeDto>();
for (IcObjectClassInfo objectClass : icSchema.getDeclaredObjectClasses()) {
// __ACCOUNT__ and __GROUP__
if (!(objectClass.getType().startsWith("__") && objectClass.getType().endsWith("__"))) {
continue;
}
SysSchemaObjectClassDto sysObjectClass = null;
// values from resource
if (sysObjectClassesInSystem != null) {
Optional<SysSchemaObjectClassDto> objectClassSame = sysObjectClassesInSystem.stream().filter(objectClassInSystem -> {
//
return objectClassInSystem.getObjectClassName().equals(objectClass.getType());
}).findFirst();
if (objectClassSame.isPresent()) {
sysObjectClass = objectClassSame.get();
}
}
// Convert IC object class to ACC (if is null, then will be created
// new instance)
sysObjectClass = convertIcObjectClassInfo(objectClass, sysObjectClass);
sysObjectClass.setSystem(system.getId());
// object class may not exist
sysObjectClass = schemaObjectClassService.save(sysObjectClass);
sysObjectClasses.add(sysObjectClass);
List<SysSchemaAttributeDto> attributesInSystem = null;
// Load existing attributes for existing object class in system
if (sysObjectClass.getId() != null) {
SysSchemaAttributeFilter attFilter = new SysSchemaAttributeFilter();
attFilter.setSystemId(system.getId());
attFilter.setObjectClassId(sysObjectClass.getId());
Page<SysSchemaAttributeDto> attributesInSystemPage = attributeService.find(attFilter, null);
attributesInSystem = attributesInSystemPage.getContent();
}
for (IcAttributeInfo attribute : objectClass.getAttributeInfos()) {
// If will be IC and ACC attribute same (same name), then we
// will do only refresh object values from resource
SysSchemaAttributeDto sysAttribute = null;
if (attributesInSystem != null) {
Optional<SysSchemaAttributeDto> sysAttributeOptional = attributesInSystem.stream().filter(a -> {
return a.getName().equals(attribute.getName());
}).findFirst();
if (sysAttributeOptional.isPresent()) {
sysAttribute = sysAttributeOptional.get();
}
}
sysAttribute = convertIcAttributeInfo(attribute, sysAttribute);
sysAttribute.setObjectClass(sysObjectClass.getId());
sysAttributes.add(sysAttribute);
}
}
// Persist generated schema to system
sysObjectClasses = (List<SysSchemaObjectClassDto>) objectClassService.saveAll(sysObjectClasses);
attributeService.saveAll(sysAttributes);
return sysObjectClasses;
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method duplicateSchema.
/**
* Duplication of schema attributes. Is not in attribute schema service, because we need use IDs cache (Old vs New IDs)
* @param id
* @param system
* @param schemaAttributesIds
* @return
*/
private SysSchemaObjectClassDto duplicateSchema(UUID id, SysSystemDto system, Map<UUID, UUID> schemaAttributesIds) {
Assert.notNull(id, "Id of duplication schema, must be filled!");
Assert.notNull(system, "Parent system must be filled!");
SysSchemaObjectClassDto clonedSchema = objectClassService.clone(id);
clonedSchema.setSystem(system.getId());
SysSchemaObjectClassDto schema = objectClassService.save(clonedSchema);
SysSchemaAttributeFilter schemaAttributesFilter = new SysSchemaAttributeFilter();
schemaAttributesFilter.setObjectClassId(id);
attributeService.find(schemaAttributesFilter, null).forEach(schemaAttribute -> {
UUID originalSchemaAttributId = schemaAttribute.getId();
SysSchemaAttributeDto clonedAttribut = attributeService.clone(originalSchemaAttributId);
clonedAttribut.setObjectClass(schema.getId());
clonedAttribut = attributeService.save(clonedAttribut);
// Put original and new id to cache
schemaAttributesIds.put(originalSchemaAttributId, clonedAttribut.getId());
});
return schema;
}
Aggregations