use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class SysSystemMappingServiceValidationTest method testSystemMappingValidationSynchronizationMissingOwner.
@Test(expected = ResultCodeException.class)
public void testSystemMappingValidationSynchronizationMissingOwner() {
SysSystemDto system = createSystem();
SysSchemaObjectClassDto schema = createSchema(system.getId());
SysSystemMappingDto mapping = createMapping(schema.getId(), SystemOperationType.SYNCHRONIZATION);
mapping.setEntityType(SystemEntityType.CONTRACT);
mapping = mappingService.save(mapping);
SysSchemaAttributeDto schemaAttribute = createSchemaAttribute(schema.getId());
createAttributeMapping(mapping.getId(), schemaAttribute.getId(), true, "");
mappingService.validate(mapping.getId());
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method initData.
private SysSystemDto initData() {
// create test system
SysSystemDto system = helper.createSystem(TestContractResource.TABLE_NAME, null, null, "ID");
Assert.assertNotNull(system);
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// Create synchronization mapping
SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
syncSystemMapping.setName("default_" + System.currentTimeMillis());
syncSystemMapping.setEntityType(SystemEntityType.CONTRACT);
syncSystemMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto syncMapping = systemMappingService.save(syncSystemMapping);
createMapping(system, syncMapping);
this.getBean().initContractData();
return system;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class SystemMappingSaveProcessor method process.
@Override
public EventResult<SysSystemMappingDto> process(EntityEvent<SysSystemMappingDto> event) {
SysSystemMappingDto dto = event.getContent();
// it is not possible get schema from embedded - new entity
SysSchemaObjectClassDto schema = schemaObjectClassService.get(dto.getObjectClass());
SysSystemDto system = DtoUtils.getEmbedded(schema, SysSchemaObjectClass_.system, SysSystemDto.class);
// for tree type is possible has more than one provisioning, both only for one tree type
if (dto.getOperationType() == SystemOperationType.PROVISIONING) {
// check if exists mapping
List<SysSystemMappingDto> anotherMapping = getMapping(dto.getEntityType(), schema.getSystem(), dto.getTreeType());
// if list not empty throw error with duplicate mapping
if (anotherMapping.stream().filter(mapping -> {
return !mapping.getId().equals(dto.getId());
}).findFirst().isPresent()) {
throw new ResultCodeException(AccResultCode.SYSTEM_MAPPING_FOR_ENTITY_EXISTS, ImmutableMap.of("system", system.getName(), "entityType", dto.getEntityType()));
}
}
//
SysSystemMappingDto result = systemMappingService.saveInternal(dto);
// update content
event.setContent(result);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAuthenticator method authenticate.
@Override
public LoginDto authenticate(LoginDto loginDto) {
// temporary solution for get system id, this is not nice.
String systemCodeable = configurationService.getValue(PROPERTY_AUTH_SYSTEM_ID);
if (StringUtils.isEmpty(systemCodeable)) {
// without system can't check
return null;
}
//
SysSystemDto system = (SysSystemDto) lookupService.lookupDto(SysSystemDto.class, systemCodeable);
//
if (system == null) {
LOG.warn("System by codeable identifier [{}] not found. Check configuration property [{}]", systemCodeable, PROPERTY_AUTH_SYSTEM_ID);
// system doesn't exist
return null;
}
IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, loginDto.getUsername());
if (identity == null) {
throw new IdmAuthenticationException(MessageFormat.format("Check identity can login: The identity [{0}] either doesn't exist or is deleted.", loginDto.getUsername()));
}
//
// search authentication attribute for system with provisioning mapping, only for identity
SysSystemAttributeMappingDto attribute = systemAttributeMappingService.getAuthenticationAttribute(system.getId(), SystemEntityType.IDENTITY);
//
if (attribute == null) {
// attribute MUST exist
throw new ResultCodeException(AccResultCode.AUTHENTICATION_AUTHENTICATION_ATTRIBUTE_DONT_SET, ImmutableMap.of("name", system.getName()));
}
//
// find if identity has account on system
List<AccAccountDto> accounts = accountService.getAccounts(system.getId(), identity.getId());
if (accounts.isEmpty()) {
// user hasn't account on system, continue
return null;
}
//
ResultCodeException authFailedException = null;
IcUidAttribute auth = null;
for (AccAccountDto account : accounts) {
SysSchemaAttributeDto schemaAttribute = schemaAttributeService.get(attribute.getSchemaAttribute());
SysSchemaObjectClassDto schemaObjectClassDto = DtoUtils.getEmbedded(schemaAttribute, SysSchemaAttribute_.objectClass, SysSchemaObjectClassDto.class);
SysSystemEntityDto systemEntityDto = systemEntityService.get(account.getSystemEntity());
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
IcConnectorObject connectorObject = systemService.readConnectorObject(system.getId(), systemEntityDto.getUid(), objectClass);
//
if (connectorObject == null) {
continue;
}
//
String transformUsername = null;
// iterate over all attributes to find authentication attribute
for (IcAttribute icAttribute : connectorObject.getAttributes()) {
if (icAttribute.getName().equals(schemaAttributeService.get(attribute.getSchemaAttribute()).getName())) {
transformUsername = String.valueOf(icAttribute.getValue());
break;
}
}
if (transformUsername == null) {
throw new ResultCodeException(AccResultCode.AUTHENTICATION_USERNAME_DONT_EXISTS, ImmutableMap.of("username", loginDto.getUsername(), "name", system.getName()));
}
// authentication over system, when password or username not exist or bad credentials - throw error
try {
// authentication against system
auth = provisioningService.authenticate(transformUsername, loginDto.getPassword(), system, SystemEntityType.IDENTITY);
authFailedException = null;
// check auth
if (auth == null || auth.getValue() == null) {
authFailedException = new ResultCodeException(AccResultCode.AUTHENTICATION_AGAINST_SYSTEM_FAILED, ImmutableMap.of("name", system.getName(), "username", loginDto.getUsername()));
// failed, continue to another
break;
}
// everything success break
break;
} catch (ResultCodeException e) {
// failed, continue to another
authFailedException = new ResultCodeException(CoreResultCode.AUTH_FAILED, "Invalid login or password.", e);
}
}
if (auth == null || auth.getValue() == null) {
authFailedException = new ResultCodeException(AccResultCode.AUTHENTICATION_AGAINST_SYSTEM_FAILED, ImmutableMap.of("name", system.getName(), "username", loginDto.getUsername()));
}
//
if (authFailedException != null) {
throw authFailedException;
}
String module = this.getModule();
loginDto = jwtAuthenticationService.createJwtAuthenticationAndAuthenticate(loginDto, identity, module);
LOG.info("Identity with username [{}] is authenticated by system [{}]", loginDto.getUsername(), system.getName());
return loginDto;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method prepareProvisioningForAttribute.
private SysProvisioningOperationDto prepareProvisioningForAttribute(SysSystemEntityDto systemEntity, AttributeMapping attributeMapping, Object value, ProvisioningOperationType operationType, DTO dto) {
Assert.notNull(systemEntity);
Assert.notNull(systemEntity.getSystem());
Assert.notNull(systemEntity.getEntityType());
Assert.notNull(systemEntity.getUid());
Assert.notNull(attributeMapping);
SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attributeMapping);
if (!schemaAttributeDto.isUpdateable()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_SCHEMA_ATTRIBUTE_IS_NOT_UPDATEABLE, ImmutableMap.of("property", attributeMapping.getIdmPropertyName(), "uid", systemEntity.getUid()));
}
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(schemaAttributeDto.getObjectClass());
String objectClassName = schemaObjectClassDto.getObjectClassName();
// We do transformation to system if is attribute only constant
Object valueTransformed = value;
if (!attributeMapping.isEntityAttribute() && !attributeMapping.isExtendedAttribute()) {
// If is attribute handling resolve as constant, then we don't want
// do transformation again (was did in getAttributeValue)
} else {
valueTransformed = attributeMappingService.transformValueToResource(systemEntity.getUid(), value, attributeMapping, dto);
}
IcAttribute icAttributeForCreate = attributeMappingService.createIcAttribute(schemaAttributeDto, valueTransformed);
//
// Call ic modul for update single attribute
IcConnectorObject connectorObject = new IcConnectorObjectImpl(systemEntity.getUid(), new IcObjectClassImpl(objectClassName), ImmutableList.of(icAttributeForCreate));
SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(ProvisioningEventType.UPDATE).setSystemEntity(systemEntity).setEntityIdentifier(dto == null ? null : dto.getId()).setProvisioningContext(new ProvisioningContext(connectorObject));
//
return operationBuilder.build();
}
Aggregations