Search in sources :

Example 86 with SysSchemaObjectClassDto

use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemMappingServiceTest method treeTypeIdFilterTest.

@Test
public void treeTypeIdFilterTest() {
    IdmBasePermission permission = IdmBasePermission.ADMIN;
    SystemEntityType entityType = SystemEntityType.IDENTITY;
    IdmTreeTypeDto treeType = new IdmTreeTypeDto();
    treeType.setName("SomeTreeTypeName");
    treeType.setCode("CodeCodeCodeCode");
    treeType = treeTypeService.save(treeType);
    IdmTreeTypeDto treeType2 = new IdmTreeTypeDto();
    treeType2.setName("SomeTreeTypeName2");
    treeType2.setCode("CodeCodeCodeCode2");
    treeType2 = treeTypeService.save(treeType2);
    SysSystemDto system = createSystem();
    SysSchemaObjectClassDto objectClass = createObjectClass(system);
    SysSystemMappingDto mappingSystem1 = testHelper.createMappingSystem(entityType, objectClass);
    mappingSystem1.setTreeType(treeType.getId());
    mappingSystem1 = mappingService.save(mappingSystem1);
    SysSystemMappingDto mappingSystem2 = testHelper.createMappingSystem(entityType, objectClass);
    mappingSystem2.setTreeType(treeType2.getId());
    mappingSystem2 = mappingService.save(mappingSystem2);
    SysSystemMappingFilter filter = new SysSystemMappingFilter();
    filter.setTreeTypeId(mappingSystem1.getTreeType());
    Page<SysSystemMappingDto> result = mappingService.find(filter, null, permission);
    assertEquals(1, result.getTotalElements());
    assertTrue(result.getContent().contains(mappingSystem1));
    assertFalse(result.getContent().contains(mappingSystem2));
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 87 with SysSchemaObjectClassDto

use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.

the class DefaultSynchronizationService method resolveUnlinkedSituation.

@Override
public SysSyncItemLogDto resolveUnlinkedSituation(String uid, SystemEntityType entityType, UUID entityId, UUID configId, String actionType) {
    Assert.notNull(uid);
    Assert.notNull(entityType);
    Assert.notNull(configId);
    Assert.notNull(actionType);
    Assert.notNull(entityId);
    AbstractSysSyncConfigDto config = synchronizationConfigService.get(configId);
    SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
    SysSchemaObjectClassDto sysSchemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
    SysSystemDto system = DtoUtils.getEmbedded(sysSchemaObjectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
    SysSystemEntityDto systemEntity = findSystemEntity(uid, system, entityType);
    SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
    SynchronizationContext context = new SynchronizationContext();
    context.addUid(uid).addSystem(system).addConfig(config).addEntityType(entityType).addEntityId(entityId).addSystemEntity(systemEntity);
    getSyncExecutor(entityType).resolveUnlinkedSituation(SynchronizationUnlinkedActionType.valueOf(actionType), context);
    return itemLog;
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 88 with SysSchemaObjectClassDto

use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.

the class VsReqeustServiceTest method checkMultivalueInWishObjectTest.

@Test
public void checkMultivalueInWishObjectTest() {
    String ldapGroupsName = "ldapGroups";
    String changed = "changed";
    List<String> attributes = new ArrayList<>(Lists.newArrayList(BasicVirtualConfiguration.DEFAULT_ATTRIBUTES));
    attributes.add(ldapGroupsName);
    // Create virtual system with extra attribute (ldapGroups)
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, attributes);
    // Search attribute definition for ldapGroups 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 ldapGroupsFormAttr = formAttributeService.findAttribute(VsAccount.class.getName(), definition.getCode(), ldapGroupsName);
    Assert.assertNotNull("Ldap attribute muste exist!", ldapGroupsFormAttr);
    ldapGroupsFormAttr.setMultiple(true);
    formService.saveAttribute(ldapGroupsFormAttr);
    // Generate schema for system (we need propagate multivalue setting)
    SysSchemaObjectClassDto schema = systemService.generateSchema(system).get(0);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(system.getId());
    List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
    SysSystemMappingFilter systemMappingFilter = new SysSystemMappingFilter();
    systemMappingFilter.setSystemId(system.getId());
    systemMappingFilter.setObjectClassId(schema.getId());
    SysSystemMappingDto mapping = systemMappingService.find(systemMappingFilter, null).getContent().get(0);
    for (SysSchemaAttributeDto schemaAttr : schemaAttributes) {
        if (ldapGroupsName.equals(schemaAttr.getName())) {
            SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
            attributeMapping.setUid(false);
            attributeMapping.setEntityAttribute(false);
            attributeMapping.setExtendedAttribute(true);
            attributeMapping.setIdmPropertyName(ldapGroupsName);
            attributeMapping.setName(schemaAttr.getName());
            attributeMapping.setSchemaAttribute(schemaAttr.getId());
            attributeMapping.setSystemMapping(mapping.getId());
            systemAttributeMappingService.save(attributeMapping);
        }
    }
    IdmIdentityDto userOne = helper.createIdentity(USER_ONE_NAME);
    List<Serializable> initList = ImmutableList.of("TEST1", "TEST2", "TEST3");
    formService.saveValues(userOne, ldapGroupsName, initList);
    this.assignRoleSystem(system, userOne, 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 createRequest = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, createRequest.getUid());
    Assert.assertEquals(VsOperationType.CREATE, createRequest.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, createRequest.getState());
    VsConnectorObjectDto wish = requestService.getWishConnectorObject(createRequest);
    boolean findAttributeWithouChange = wish.getAttributes().stream().filter(attribute -> !attribute.isChanged()).findFirst().isPresent();
    Assert.assertTrue(!findAttributeWithouChange);
    // Check on exist ldapGroups attribute with three values
    VsAttributeDto ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
    Assert.assertTrue(ldapGroupAttribute.isMultivalue());
    Assert.assertEquals(3, ldapGroupAttribute.getValues().size());
    // Change multivalue attribute
    List<Serializable> changeList = ImmutableList.of("TEST1", changed, "TEST3");
    formService.saveValues(userOne, ldapGroupsName, changeList);
    // Invoke provisioning
    identityService.save(userOne);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(2, requests.size());
    VsRequestDto changeRequest = requests.stream().filter(req -> VsOperationType.UPDATE == req.getOperationType()).findFirst().get();
    wish = requestService.getWishConnectorObject(changeRequest);
    ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
    Assert.assertTrue(ldapGroupAttribute.isMultivalue());
    // Wish must contains three values (all add) ... because previous create
    // request is not realize yet. Wish show changes versus reals state in
    // VsAccount.
    Assert.assertEquals(3, ldapGroupAttribute.getValues().size());
    // We realize the create request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    requestService.realize(createRequest);
    // Refresh wish
    wish = requestService.getWishConnectorObject(changeRequest);
    ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
    Assert.assertTrue(ldapGroupAttribute.isMultivalue());
    // Wish must contains four values ... two without change, one delete and
    // one add value
    Assert.assertEquals(4, ldapGroupAttribute.getValues().size());
    // Find unchanged value
    boolean findCorrectTest1Value = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(initList.get(0)) && value.getOldValue().equals(initList.get(0)) && value.getChange() == null).findFirst().isPresent();
    Assert.assertTrue(findCorrectTest1Value);
    // Find deleted value
    boolean findCorrectDeletedTest2Value = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(initList.get(1)) && value.getOldValue().equals(initList.get(1)) && VsValueChangeType.REMOVED == value.getChange()).findFirst().isPresent();
    Assert.assertTrue(findCorrectDeletedTest2Value);
    // Find added value
    boolean findCorrectCreatedChangedValue = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(changed) && value.getOldValue() == null && VsValueChangeType.ADDED == value.getChange()).findFirst().isPresent();
    Assert.assertTrue(findCorrectCreatedChangedValue);
}
Also used : SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) Date(java.util.Date) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) VsRequestByImplementerEvaluator(eu.bcvsolutions.idm.vs.evaluator.VsRequestByImplementerEvaluator) After(org.junit.After) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) VsOperationType(eu.bcvsolutions.idm.vs.domain.VsOperationType) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) TestHelper(eu.bcvsolutions.idm.vs.TestHelper) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) Collectors(java.util.stream.Collectors) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState) Serializable(java.io.Serializable) List(java.util.List) VsRequest(eu.bcvsolutions.idm.vs.entity.VsRequest) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Before(org.junit.Before) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) InitTestData(eu.bcvsolutions.idm.InitTestData) VsAttributeDto(eu.bcvsolutions.idm.vs.dto.VsAttributeDto) VsValueChangeType(eu.bcvsolutions.idm.vs.domain.VsValueChangeType) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) VsAccountService(eu.bcvsolutions.idm.vs.service.api.VsAccountService) Test(org.junit.Test) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Component(org.springframework.stereotype.Component) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) VsRequestState(eu.bcvsolutions.idm.vs.domain.VsRequestState) Assert(org.junit.Assert) VirtualSystemGroupPermission(eu.bcvsolutions.idm.vs.domain.VirtualSystemGroupPermission) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) VsRequestService(eu.bcvsolutions.idm.vs.service.api.VsRequestService) VsSystemDto(eu.bcvsolutions.idm.vs.dto.VsSystemDto) Serializable(java.io.Serializable) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsAttributeDto(eu.bcvsolutions.idm.vs.dto.VsAttributeDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 89 with SysSchemaObjectClassDto

use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.

the class AdUserConnectorType method load.

@Override
public ConnectorTypeDto load(ConnectorTypeDto connectorType) {
    super.load(connectorType);
    if (!connectorType.isReopened()) {
        connectorType.getMetadata().put(REGENERATE_SCHEMA_SWITCH, Boolean.TRUE.toString());
        return connectorType;
    }
    connectorType.getMetadata().put(REGENERATE_SCHEMA_SWITCH, Boolean.FALSE.toString());
    // Load the system.
    SysSystemDto systemDto = (SysSystemDto) connectorType.getEmbedded().get(SYSTEM_DTO_KEY);
    Assert.notNull(systemDto, "System must exists!");
    connectorType.getMetadata().put(SYSTEM_NAME, systemDto.getName());
    Map<String, String> metadata = connectorType.getMetadata();
    IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
    // Find attribute with port.
    metadata.put(PORT, getValueFromConnectorInstance(PORT, systemDto, connectorFormDef));
    // Find attribute with host.
    metadata.put(HOST, getValueFromConnectorInstance(HOST, systemDto, connectorFormDef));
    // Find attribute with user.
    metadata.put(USER, getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef));
    // Find attribute with ssl switch.
    metadata.put(SSL_SWITCH, getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
    IdmFormDefinitionDto operationOptionsFormDefinition = this.getSystemService().getOperationOptionsConnectorFormDefinition(systemDto);
    if (operationOptionsFormDefinition != null) {
        // Find attribute with domain.
        metadata.put(DOMAIN_KEY, getValueFromConnectorInstance(DOMAIN_KEY, systemDto, operationOptionsFormDefinition));
        // Find attribute with container with existed users.
        metadata.put(USER_SEARCH_CONTAINER_KEY, getValueFromConnectorInstance(USER_SEARCH_CONTAINER_KEY, systemDto, operationOptionsFormDefinition));
        // Find attribute with container with new users.
        metadata.put(NEW_USER_CONTAINER_KEY, getValueFromConnectorInstance(NEW_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition));
        // Find attribute with container with deleted users.
        metadata.put(DELETE_USER_CONTAINER_KEY, getValueFromConnectorInstance(DELETE_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition));
    }
    // Load the provisioning mapping.
    SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
    mappingFilter.setSystemId(systemDto.getId());
    mappingFilter.setOperationType(SystemOperationType.PROVISIONING);
    SysSystemMappingDto mappingDto = systemMappingService.find(mappingFilter, null).getContent().stream().min(Comparator.comparing(SysSystemMappingDto::getCreated)).orElse(null);
    if (mappingDto != null) {
        connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
        connectorType.getMetadata().put(MAPPING_ID, mappingDto.getId().toString());
        connectorType.getMetadata().put(PROTECTED_MODE_SWITCH_KEY, String.valueOf(mappingDto.isProtectionEnabled()));
    }
    // Load the sync mapping.
    SysSystemMappingFilter syncMappingFilter = new SysSystemMappingFilter();
    syncMappingFilter.setSystemId(systemDto.getId());
    syncMappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
    SysSystemMappingDto syncMappingDto = systemMappingService.find(syncMappingFilter, null).getContent().stream().min(Comparator.comparing(SysSystemMappingDto::getCreated)).orElse(null);
    if (syncMappingDto != null) {
        connectorType.getMetadata().put(MAPPING_SYNC_ID, syncMappingDto.getId().toString());
    }
    // Load the pairing sync (beware by name!).
    SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
    syncFilter.setSystemId(systemDto.getId());
    syncFilter.setName(PAIRING_SYNC_NAME);
    AbstractSysSyncConfigDto syncDto = syncConfigService.find(syncFilter, null).getContent().stream().min(Comparator.comparing(AbstractDto::getCreated)).orElse(null);
    if (syncDto != null) {
        connectorType.getMetadata().put(PAIRING_SYNC_ID, syncDto.getId().toString());
    }
    IdmEntityStateFilter entityStateFilter = new IdmEntityStateFilter();
    entityStateFilter.setOwnerId(systemDto.getId());
    entityStateFilter.setOwnerType(entityStateManager.getOwnerType(systemDto.getClass()));
    entityStateFilter.setResultCode(AccResultCode.WIZARD_AD_CREATED_TEST_USER_DN.getCode());
    IdmEntityStateDto entityStateDto = entityStateManager.findStates(entityStateFilter, null).stream().findFirst().orElse(null);
    Object dn = null;
    if (entityStateDto != null && entityStateDto.getResult() != null && entityStateDto.getResult().getModel() != null && entityStateDto.getResult().getModel().getParameters() != null) {
        dn = entityStateDto.getResult().getModel().getParameters().get(TEST_CREATED_USER_DN_KEY);
    }
    if (dn instanceof String) {
        String testUserDN = (String) dn;
        connectorType.getMetadata().put(ENTITY_STATE_WITH_TEST_CREATED_USER_DN_KEY, entityStateDto.getId().toString());
        connectorType.getMetadata().put(TEST_CREATED_USER_DN_KEY, testUserDN);
    }
    // Load a schema.
    SysSchemaObjectClassFilter schemaFilter = new SysSchemaObjectClassFilter();
    schemaFilter.setSystemId(systemDto.getId());
    schemaFilter.setObjectClassName(getSchemaType());
    SysSchemaObjectClassDto schemaDto = schemaObjectClassService.find(schemaFilter, null).getContent().stream().findFirst().orElse(null);
    if (schemaDto != null) {
        connectorType.getMetadata().put(SCHEMA_ID_KEY, schemaDto.getId().toString());
    }
    return connectorType;
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)

Example 90 with SysSchemaObjectClassDto

use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.

the class AdUserConnectorType method executeStepFour.

/**
 * Step for filling additional information as connector (OU) DNs. Enable protected mode. Add pairing sync.
 */
private void executeStepFour(ConnectorTypeDto connectorType) {
    String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
    String pairingSyncId = connectorType.getMetadata().get(PAIRING_SYNC_ID);
    Assert.notNull(systemId, "System ID cannot be null!");
    SysSystemDto systemDto = this.getSystemService().get(systemId);
    connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
    boolean pairingSyncSwitch = Boolean.parseBoolean(connectorType.getMetadata().get(PAIRING_SYNC_SWITCH_KEY));
    String pairingSyncAttributeCode = connectorType.getMetadata().get(PAIRING_SYNC_DN_ATTR_KEY);
    if (pairingSyncAttributeCode == null) {
        pairingSyncAttributeCode = DN_ATTR_CODE;
    }
    boolean protectedModeSwitch = Boolean.parseBoolean(connectorType.getMetadata().get(PROTECTED_MODE_SWITCH_KEY));
    IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
    String port = getValueFromConnectorInstance(PORT, systemDto, connectorFormDef);
    String host = getValueFromConnectorInstance(HOST, systemDto, connectorFormDef);
    String user = getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef);
    boolean ssl = Boolean.parseBoolean(getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
    String password = getConfidentialValueFromConnectorInstance(CREDENTIALS, systemDto, connectorFormDef);
    String domainContainer = connectorType.getMetadata().get(DOMAIN_KEY);
    Assert.notNull(domainContainer, "Domain cannot be null!");
    String newUserContainer = connectorType.getMetadata().get(NEW_USER_CONTAINER_KEY);
    Assert.notNull(newUserContainer, "Container for new users cannot be null!");
    String searchUserContainer = connectorType.getMetadata().get(USER_SEARCH_CONTAINER_KEY);
    Assert.notNull(searchUserContainer, "Container for search users cannot be null!");
    String deleteUserContainer = null;
    // Delete user container should be used only if protected mode is active.
    if (protectedModeSwitch) {
        deleteUserContainer = connectorType.getMetadata().get(DELETE_USER_CONTAINER_KEY);
    }
    String newUserContainerAD = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", newUserContainer), port, host, user, password, ssl);
    if (Strings.isBlank(newUserContainerAD)) {
        throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", newUserContainer));
    }
    String searchUserContainerAD = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", searchUserContainer), port, host, user, password, ssl);
    if (Strings.isBlank(searchUserContainerAD)) {
        throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", searchUserContainer));
    }
    if (Strings.isNotBlank(deleteUserContainer) && protectedModeSwitch) {
        String deleteUserContainerAD = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", deleteUserContainer), port, host, user, password, ssl);
        if (Strings.isBlank(deleteUserContainerAD)) {
            throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", deleteUserContainer));
        }
    }
    IdmFormDefinitionDto operationOptionsFormDefinition = getSystemService().getOperationOptionsConnectorFormDefinition(systemDto);
    if (operationOptionsFormDefinition != null) {
        // Set domain to system's operation options.
        operationOptionsFormDefinition = initFormAttributeDefinition(operationOptionsFormDefinition, DOMAIN_KEY, (short) 3);
        setValueToConnectorInstance(DOMAIN_KEY, domainContainer, systemDto, operationOptionsFormDefinition);
        // Set container for new users to system's operation options.
        operationOptionsFormDefinition = initFormAttributeDefinition(operationOptionsFormDefinition, NEW_USER_CONTAINER_KEY, (short) 4);
        setValueToConnectorInstance(NEW_USER_CONTAINER_KEY, newUserContainer, systemDto, operationOptionsFormDefinition);
        // Set container for deleted users to system's operation options.
        operationOptionsFormDefinition = initFormAttributeDefinition(operationOptionsFormDefinition, DELETE_USER_CONTAINER_KEY, (short) 5);
        setValueToConnectorInstance(DELETE_USER_CONTAINER_KEY, deleteUserContainer, systemDto, operationOptionsFormDefinition);
        // Set container for exists users to system's operation options.
        operationOptionsFormDefinition = initFormAttributeDefinition(operationOptionsFormDefinition, USER_SEARCH_CONTAINER_KEY, (short) 6);
        setValueToConnectorInstance(USER_SEARCH_CONTAINER_KEY, searchUserContainer, systemDto, operationOptionsFormDefinition);
    }
    String mappingSyncId = connectorType.getMetadata().get(MAPPING_SYNC_ID);
    String mappingId = connectorType.getMetadata().get(MAPPING_ID);
    if (mappingId == null && mappingSyncId == null) {
        // This attributes will be updated only if system doesn't have mapping.
        // Checking by existing mapping and not by reopen flag solves a problem with reopen wizard for to early closed wizard. For example in the certificate step.
        initDefaultConnectorSettings(systemDto, connectorFormDef);
    }
    // Attributes below will updated everytime (for reopen system too).
    // Base context for search users.
    // We need to searching in all containers (for new, existed and deleted users). So all three values will be use in the base context.
    List<Serializable> values = Lists.newArrayList(Sets.newHashSet(searchUserContainer, newUserContainer, deleteUserContainer));
    this.setValueToConnectorInstance(BASE_CONTEXT_USER_KEY, values, systemDto, connectorFormDef);
    // Set root suffixes and generate a schema.
    SysSchemaObjectClassDto schemaDto = generateSchema(connectorType, systemDto, connectorFormDef, searchUserContainer, values);
    // Find sAMAccountName attribute in the schema.
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setObjectClassId(schemaDto.getId());
    schemaAttributeFilter.setSystemId(systemDto.getId());
    schemaAttributeFilter.setName(SAM_ACCOUNT_NAME_ATTRIBUTE);
    SysSchemaAttributeDto sAMAccountNameAttribute = schemaAttributeService.find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
    if (sAMAccountNameAttribute == null) {
        // Attribute missing -> create it now.
        sAMAccountNameAttribute = createSchemaAttribute(schemaDto, SAM_ACCOUNT_NAME_ATTRIBUTE, String.class.getName(), true, true, false);
    }
    // Find __ENABLE__ attribute in the schema.
    schemaAttributeFilter.setName(IcAttributeInfo.ENABLE);
    SysSchemaAttributeDto enableAttribute = schemaAttributeService.find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
    if (enableAttribute == null) {
        // Attribute missing -> create it now.
        createSchemaAttribute(schemaDto, IcAttributeInfo.ENABLE, Boolean.class.getName(), true, true, false);
    }
    // Find __PASSWORD__ attribute in the schema.
    schemaAttributeFilter.setName(IcAttributeInfo.PASSWORD);
    SysSchemaAttributeDto passwordAttribute = schemaAttributeService.find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
    if (passwordAttribute == null) {
        // Attribute missing -> create it now.
        createSchemaAttribute(schemaDto, IcAttributeInfo.PASSWORD, GuardedString.class.getName(), false, true, false);
    } else {
        passwordAttribute.setUpdateable(true);
        schemaAttributeService.save(passwordAttribute);
    }
    // Find Ldap groups attribute in the schema.
    schemaAttributeFilter.setName(LDAP_GROUPS_ATTRIBUTE);
    SysSchemaAttributeDto ldapGroupsAttribute = schemaAttributeService.find(schemaAttributeFilter, null).stream().findFirst().orElse(null);
    if (ldapGroupsAttribute == null) {
        // Attribute missing -> create it now.
        createSchemaAttribute(schemaDto, LDAP_GROUPS_ATTRIBUTE, String.class.getName(), true, true, true);
    }
    mappingId = connectorType.getMetadata().get(MAPPING_ID);
    if (mappingId == null) {
        // Create identity mapping for provisioning.
        SysSystemMappingDto mappingDto = new SysSystemMappingDto();
        mappingDto.setObjectClass(schemaDto.getId());
        mappingDto.setOperationType(SystemOperationType.PROVISIONING);
        mappingDto.setEntityType(SystemEntityType.IDENTITY);
        mappingDto.setName("AD users provisioning mapping.");
        mappingDto.setProtectionEnabled(protectedModeSwitch);
        mappingDto = systemMappingService.publish(new SystemMappingEvent(SystemMappingEvent.SystemMappingEventType.CREATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, Boolean.TRUE))).getContent();
        mappingDto = systemMappingService.save(mappingDto);
        connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
        connectorType.getMetadata().put(DefaultConnectorType.MAPPING_ID, mappingDto.getId().toString());
    } else {
        SysSystemMappingDto mappingDto = systemMappingService.get(UUID.fromString(mappingId));
        // If protected mode switch changed, then mapping will be updated.
        if (mappingDto.isProtectionEnabled() != protectedModeSwitch) {
            mappingDto.setProtectionEnabled(protectedModeSwitch);
            mappingDto = systemMappingService.save(mappingDto);
        }
        connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
    }
    if (pairingSyncSwitch) {
        createPairingSync(connectorType, pairingSyncAttributeCode, schemaDto, schemaAttributeFilter, sAMAccountNameAttribute);
    }
    if (pairingSyncId != null) {
        // If is protected mode activated, then set strategy to LINK_PROTECTED, otherwise set DO_NOT_LINK.
        AbstractSysSyncConfigDto pairingSync = syncConfigService.get(UUID.fromString(pairingSyncId));
        if (pairingSync instanceof SysSyncIdentityConfigDto) {
            SysSyncIdentityConfigDto sync = (SysSyncIdentityConfigDto) pairingSync;
            if (protectedModeSwitch) {
                sync.setInactiveOwnerBehavior(SynchronizationInactiveOwnerBehaviorType.LINK_PROTECTED);
            } else {
                sync.setInactiveOwnerBehavior(SynchronizationInactiveOwnerBehaviorType.DO_NOT_LINK);
            }
            syncConfigService.save(sync);
        }
    }
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) Serializable(java.io.Serializable) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SystemMappingEvent(eu.bcvsolutions.idm.acc.event.SystemMappingEvent) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Aggregations

SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)156 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)125 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)114 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)65 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)63 Test (org.junit.Test)59 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)38 UUID (java.util.UUID)32 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)29 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)28 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)25 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)21 SysSystemMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter)21 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)21 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)20 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)19 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)19 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)18 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)17