use of eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl in project CzechIdMng by bcvsolutions.
the class VsReqeustServiceTest method systemAccountFilterTest.
@Test
public void systemAccountFilterTest() {
SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
this.assignRoleSystem(system, helper.createIdentity(USER_ONE_NAME), ROLE_ONE_NAME);
// Find created requests
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setUid(USER_ONE_NAME);
List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
VsRequestDto request = requests.get(0);
Assert.assertEquals(USER_ONE_NAME, request.getUid());
Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
Assert.assertNull("Account must be null, because request was not realized yet!", account);
// We try realize the request
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
request = requestService.realize(request);
Assert.assertEquals(VsRequestState.REALIZED, request.getState());
account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
Assert.assertNotNull("Account cannot be null, because request was realized!", account);
IcConnectorConfiguration configuration = systemService.getConnectorConfiguration(system);
IcObjectClass objectClass = new IcObjectClassImpl("__ACCOUNT__");
List<String> uids = new ArrayList<>();
connectorFacade.search(system.getConnectorInstance(), configuration, objectClass, null, new IcResultsHandler() {
@Override
public boolean handle(IcConnectorObject connectorObject) {
uids.add(connectorObject.getUidValue());
return true;
}
});
Assert.assertEquals(1, uids.size());
Assert.assertEquals(USER_ONE_NAME, uids.get(0));
}
use of eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method process.
@Override
public AbstractSysSyncConfigDto process(UUID synchronizationConfigId) {
// Clear cache
idmCacheManager.evictCache(CACHE_NAME);
SysSyncLogDto log = new SysSyncLogDto();
// Create basic synchronization log
log.setSynchronizationConfig(synchronizationConfigId);
log.setStarted(ZonedDateTime.now());
try {
// Validate and create basic context
SynchronizationContext context = this.validate(synchronizationConfigId);
AbstractSysSyncConfigDto config = context.getConfig();
SystemEntityType entityType = context.getEntityType();
SysSystemDto system = context.getSystem();
IcConnectorConfiguration connectorConfig = context.getConnectorConfig();
SysSystemMappingDto systemMapping = systemMappingService.get(config.getSystemMapping());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
// Load last token
String lastToken = config.isReconciliation() ? null : config.getToken();
IcSyncToken lastIcToken = Strings.isNullOrEmpty(lastToken) ? null : new IcSyncTokenImpl(lastToken);
log.setToken(lastToken != null ? lastToken : null);
log.setRunning(true);
log = syncStarted(log, context);
// List of all accounts keys (used in reconciliation)
Set<String> systemAccountsList = new HashSet<>();
longRunningTaskExecutor.setCounter(0L);
log = synchronizationLogService.save(log);
List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
// add logs to context
context.addLog(log).addActionLogs(actionsLog);
// Is differential sync enabled?
if (config.isDifferentialSync()) {
log.addToLog("Synchronization is running as differential (entities will be updated only if least one attribute was changed).");
}
if (config.isCustomFilter() || config.isReconciliation()) {
// Custom filter Sync
log.addToLog("Synchronization will use custom filter (not synchronization implemented in connector).");
AttributeMapping tokenAttribute = null;
if (config.getTokenAttribute() != null) {
tokenAttribute = systemAttributeMappingService.get(config.getTokenAttribute());
}
if (tokenAttribute == null && !config.isReconciliation()) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TOKEN_ATTRIBUTE_NOT_FOUND);
}
context.addTokenAttribute(tokenAttribute);
// Resolve filter for custom search
IcFilter filter = resolveSynchronizationFilter(config);
log.addToLog(MessageFormat.format("Start search with filter [{0}].", filter != null ? filter : "NONE"));
connectorFacade.search(systemService.getConnectorInstance(system), connectorConfig, objectClass, filter, new DefaultResultHandler(context, systemAccountsList));
} else {
// Inner Sync
log.addToLog("Synchronization will use inner connector synchronization implementation.");
DefalutSyncResultHandler syncResultsHandler = new DefalutSyncResultHandler(context, systemAccountsList);
connectorFacade.synchronization(systemService.getConnectorInstance(system), connectorConfig, objectClass, lastIcToken, syncResultsHandler);
}
// We do reconciliation (find missing account)
if (config.isReconciliation() && log.isRunning()) {
startReconciliation(entityType, systemAccountsList, config, system, log, actionsLog);
}
// Sync is correctly ends if wasn't cancelled
if (log.isRunning()) {
log = syncCorrectlyEnded(log, context);
}
return synchronizationConfigService.save(config);
} catch (Exception e) {
String message = "Error during synchronization";
log.addToLog(message);
log.setContainsError(true);
log.addToLog(Throwables.getStackTraceAsString(e));
throw e;
} finally {
syncEnd(log, syncContext);
log.setRunning(false);
log.setEnded(ZonedDateTime.now());
synchronizationLogService.save(log);
//
longRunningTaskExecutor.setCount(longRunningTaskExecutor.getCounter());
longRunningTaskExecutor.updateState();
// Clear cache
idmCacheManager.evictCache(CACHE_NAME);
}
}
use of eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl in project CzechIdMng by bcvsolutions.
the class DefaultSysSchemaObjectClassService method findByAccount.
@Override
public IcObjectClass findByAccount(UUID systemId, SystemEntityType entityType) {
Assert.notNull(systemId, "System ID cannot be null!");
Assert.notNull(entityType, "Entity type cannot be null!");
// Find first mapping with for entity type and system from the account.
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setEntityType(entityType);
mappingFilter.setSystemId(systemId);
SysSystemMappingDto systemMappingDto = systemMappingService.find(mappingFilter, null).getContent().stream().findFirst().orElse(null);
if (systemMappingDto == null) {
return null;
}
SysSchemaObjectClassDto objectClass = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
return new IcObjectClassImpl(objectClass.getObjectClassName());
}
use of eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl in project CzechIdMng by bcvsolutions.
the class CzechIdMIcConnectorService method updateObject.
@Override
public IcUidAttribute updateObject(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, IcUidAttribute uid, List<IcAttribute> replaceAttributes) {
Assert.notNull(connectorInstance, "Connector instance is required.");
Assert.notNull(connectorInstance.getConnectorKey(), "Connector key is required.");
Assert.notNull(connectorConfiguration, "Configuration is required.");
Assert.notNull(replaceAttributes, "Replace attributes are required.");
Assert.notNull(uid, "Uid is required.");
String key = connectorInstance.getConnectorKey().toString();
LOG.debug("Update object - CzechIdM (Uid= {} {} {})", uid, key, replaceAttributes.toString());
if (objectClass == null) {
objectClass = new IcObjectClassImpl(IcObjectClassInfo.ACCOUNT);
}
IcConnector connector = this.getConnectorInstance(connectorInstance, connectorConfiguration);
if (!(connector instanceof IcCanUpdate)) {
throw new IcException(MessageFormat.format("Connector [{0}] not supports update operation!", key));
}
IcUidAttribute updatedUid = ((IcCanUpdate) connector).update(uid, objectClass, replaceAttributes);
LOG.debug("Updated object - CzechIdM ({} {}) Uid= {})", connectorInstance.getConnectorKey().toString(), replaceAttributes.toString(), updatedUid);
return updatedUid;
}
use of eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl in project CzechIdMng by bcvsolutions.
the class AbstractAccAuthenticator method authenticateOverSystem.
/**
* Process authentication against given system with login and password.
*
* @param systemCodeable
* @param loginDto
* @param identity
* @return
*/
protected IcUidAttribute authenticateOverSystem(SysSystemDto system, LoginDto loginDto, IdmIdentityDto identity) {
// search authentication attribute for system with provisioning mapping, only for identity
SysSystemAttributeMappingDto attribute = systemAttributeMappingService.getAuthenticationAttribute(system.getId(), SystemEntityType.IDENTITY);
//
if (attribute == null) {
// attribute doesn't exists
LOG.error("System id [{}] is configured for authenticate, but for the system doesn't exist authentication attribute.", system.getId());
return null;
}
//
// find if identity has account on system
List<AccAccountDto> accounts = accountService.getAccounts(system.getId(), identity.getId());
if (accounts.isEmpty()) {
LOG.debug("Identity id [{}] hasn't account for system id [{}].", identity.getId(), system.getId());
// user hasn't account on system, continue
return null;
}
//
IcUidAttribute auth = null;
// authenticate over all accounts find first, or throw error
for (AccAccountDto account : accounts) {
SysSchemaAttributeDto schemaAttribute = schemaAttributeService.get(attribute.getSchemaAttribute());
SysSchemaObjectClassDto schemaObjectClassDto = DtoUtils.getEmbedded(schemaAttribute, SysSchemaAttribute_.objectClass);
SysSystemEntityDto systemEntityDto = systemEntityService.get(account.getSystemEntity());
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
String transformUsername = null;
if (!attribute.isUid()) {
IcConnectorObject connectorObject = systemService.readConnectorObject(system.getId(), systemEntityDto.getUid(), objectClass);
//
if (connectorObject == null) {
continue;
}
// 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) {
LOG.error("For system id [{}] cant be transformed username for identity id [{}]. The system will be skipped for autentication.", system.getId(), identity.getId());
return null;
}
} else {
transformUsername = systemEntityDto.getUid();
}
// 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);
// check auth
if (auth == null || auth.getValue() == null) {
// failed, continue to another account
continue;
}
// everything success break and the authentication will be returned
break;
} catch (ResultCodeException e) {
String message = StringUtils.trimToEmpty(e.getMessage());
LOG.error("Authentication trought system name [{}] for identity username [{}] failed! Error message: [{}]", system.getCode(), identity.getUsername(), message);
}
}
return auth;
}
Aggregations