Search in sources :

Example 96 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.

the class DefaultUniformPasswordManagerIntegrationTest method testDisableUniformPasswordByProcessor.

@Test
public void testDisableUniformPasswordByProcessor() {
    try {
        // Disable the IdentityInitUniformPasswordProcessor processor -> state will be not created -> feature uniform password have to be disabled.
        getHelper().disableProcessor(IdentityInitUniformPasswordProcessor.PROCESSOR_NAME);
        // Turn on an async execution.
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
        getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
        // Create password generate policy if missing.
        createGeneratePolicy();
        SysSystemDto contractSystem = initData();
        Assert.assertNotNull(contractSystem);
        IdmTreeTypeDto treeType = helper.createTreeType();
        AbstractSysSyncConfigDto config = doCreateSyncConfig(contractSystem, treeType);
        Assert.assertTrue(config instanceof SysSyncContractConfigDto);
        SysSystemDto targetSystemOne = helper.createTestResourceSystem(true);
        // Create system two with account suffix "_targetSystemTwo".
        String targetSystemTwoSuffix = "_targetSystemTwo";
        SysSystemDto targetSystemTwo = helper.createTestResourceSystem(true);
        SysSystemMappingDto provisioningMapping = systemMappingService.findProvisioningMapping(targetSystemTwo.getId(), SystemEntityType.IDENTITY);
        List<SysSystemAttributeMappingDto> attributeMappingDtos = schemaAttributeMappingService.findBySystemMapping(provisioningMapping);
        SysSystemAttributeMappingDto uidAttribute = schemaAttributeMappingService.getUidAttribute(attributeMappingDtos, targetSystemTwo);
        uidAttribute.setTransformToResourceScript("return attributeValue + \"" + targetSystemTwoSuffix + "\"");
        schemaAttributeMappingService.save(uidAttribute);
        IdmRoleDto automaticRoleTreeOne = helper.createRole();
        helper.createRoleSystem(automaticRoleTreeOne, targetSystemOne);
        IdmTreeNodeDto treeNodeOne = helper.createTreeNode(treeType, null);
        helper.createAutomaticRole(automaticRoleTreeOne, treeNodeOne);
        IdmRoleDto automaticRoleTreeTwo = helper.createRole();
        helper.createRoleSystem(automaticRoleTreeTwo, targetSystemTwo);
        IdmTreeNodeDto treeNodeTwo = helper.createTreeNode(treeType, null);
        helper.createAutomaticRole(automaticRoleTreeTwo, treeNodeTwo);
        IdmIdentityDto ownerOne = helper.createIdentityOnly();
        List<TestContractResource> contractResources = Lists.newArrayList(this.createContract("1", ownerOne.getUsername(), null, "true", treeNodeOne.getCode(), null, null, null), this.createContract("2", ownerOne.getUsername(), null, "false", treeNodeTwo.getCode(), null, null, null));
        this.getBean().initContractData(contractResources);
        IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
        contractFilter.setIdentity(ownerOne.getId());
        contractService.find(contractFilter, null).getContent().forEach(contract -> contractService.delete(contract));
        Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
        ownerOne = identityService.get(ownerOne.getId());
        // Identities should be in the CREATED state.
        Assert.assertEquals(IdentityState.CREATED, ownerOne.getState());
        SynchronizationSchedulableTaskExecutor lrt = new SynchronizationSchedulableTaskExecutor(config.getId());
        LongRunningFutureTask<Boolean> longRunningFutureTask = longRunningTaskManager.execute(lrt);
        UUID transactionIdLrt = longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getTransactionId();
        // Waiting for the LRT will be running.
        getHelper().waitForResult(res -> {
            return !longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).isRunning();
        }, 50, 40);
        // Waiting for the LRT will be EXECUTED.
        getHelper().waitForResult(res -> {
            return longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getResultState() != OperationState.EXECUTED;
        }, 250, 100);
        Assert.assertEquals(OperationState.EXECUTED, longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getResultState());
        SysSyncLogDto log = helper.checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.SUCCESS);
        Assert.assertFalse(log.isRunning());
        Assert.assertFalse(log.isContainsError());
        UUID transactionId = log.getTransactionId();
        Assert.assertNotNull(transactionId);
        Assert.assertEquals(transactionIdLrt, transactionId);
        contractFilter.setIdentity(ownerOne.getId());
        Assert.assertEquals(2, contractService.count(contractFilter));
        ownerOne = identityService.get(ownerOne.getId());
        // Identities should have a valid state.
        Assert.assertEquals(IdentityState.VALID, ownerOne.getState());
        // Uniform password feature is disabled -> password could be not same.
        IdmEntityStateDto entityStateDtoOwnerOne = uniformPasswordManager.getEntityState(ownerOne.getId(), IdmIdentityDto.class, transactionId);
        Assert.assertNull(entityStateDtoOwnerOne);
        TestResource resourceOwnerOne = helper.findResource(ownerOne.getUsername());
        Assert.assertNotNull(resourceOwnerOne);
        TestResource resourceOwnerTwo = helper.findResource(ownerOne.getUsername() + targetSystemTwoSuffix);
        Assert.assertNotNull(resourceOwnerTwo);
        String passwordOwnerOne = resourceOwnerOne.getPassword();
        String passwordOwnerTwo = resourceOwnerTwo.getPassword();
        Assert.assertNotNull(passwordOwnerOne);
        Assert.assertNotNull(passwordOwnerTwo);
        // Uniform password feature is disabled -> password cannot be not same.
        Assert.assertNotEquals(passwordOwnerOne, passwordOwnerTwo);
        // None a uniform password notification was send.
        IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
        notificationFilter.setRecipient(ownerOne.getUsername());
        notificationFilter.setNotificationType(IdmEmailLog.class);
        notificationFilter.setTopic(CoreModule.TOPIC_UNIFORM_PASSWORD_SET);
        List<IdmNotificationLogDto> notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
        Assert.assertEquals(0, notificationLogDtos.size());
        // None a new password notification was send.
        notificationFilter.setTopic(AccModuleDescriptor.TOPIC_NEW_PASSWORD);
        notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
        Assert.assertEquals(2, notificationLogDtos.size());
        // None a password change notification was send.
        notificationFilter.setTopic(CoreModule.TOPIC_PASSWORD_SET);
        notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
        Assert.assertEquals(0, notificationLogDtos.size());
        // Delete log
        syncLogService.delete(log);
        // Delete identities.
        identityService.delete(ownerOne);
    } finally {
        // Turn off an async execution.
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
        getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
        // Enable processor.
        getHelper().enableProcessor(IdentityInitUniformPasswordProcessor.PROCESSOR_NAME);
    }
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) TestContractResource(eu.bcvsolutions.idm.acc.entity.TestContractResource) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) SynchronizationSchedulableTaskExecutor(eu.bcvsolutions.idm.acc.scheduler.task.impl.SynchronizationSchedulableTaskExecutor) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 97 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.

the class NotificationSmtpTest method D_sendEmailWithPersistedAttachments.

/**
 * Smtp email model don't contain attachments - it's tested, if attachment are not lost diring processing only.
 */
@Test
public void D_sendEmailWithPersistedAttachments() {
    // create config
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    config.setTopic(TOPIC);
    config.setLevel(NotificationLevel.SUCCESS);
    config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
    config = notificationConfigurationService.save(config);
    String textHtml = "textHtml-" + System.currentTimeMillis();
    String textText = "textText-" + System.currentTimeMillis();
    String subject = "subject-" + System.currentTimeMillis();
    IdmIdentityDto identity = helper.createIdentity();
    identity.setEmail("example@example.tld");
    identity = identityService.save(identity);
    IdmAttachmentDto attachment = new IdmAttachmentDto();
    attachment.setName("rest2.txt");
    attachment.setInputData(IOUtils.toInputStream("test txt content 1234567899 ě+ščřžýáííéáýžřčšě+;ěščřžýáíééů", AttachableEntity.DEFAULT_CHARSET));
    attachment.setEncoding(AttachableEntity.DEFAULT_ENCODING);
    attachment.setMimetype("text/plain");
    attachment.setOwnerType("mock");
    attachment.setOwnerId(UUID.randomUUID());
    attachment = attachmentManager.saveAttachment(null, attachment);
    assertNull(attachment.getInputData());
    List<IdmNotificationLogDto> send = notificationManager.send(TOPIC, new IdmMessageDto.Builder().setTextMessage(textText).setHtmlMessage(textHtml).setSubject(subject).setLevel(NotificationLevel.SUCCESS).build(), null, Lists.newArrayList(identity), Lists.newArrayList(attachment));
    assertEquals(attachment.getName(), send.get(0).getAttachments().get(0).getName());
    notificationConfigurationService.delete(config);
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractNotificationTest(eu.bcvsolutions.idm.test.api.AbstractNotificationTest)

Example 98 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.

the class NotificationSmtpTest method B_sendEmailViaSmtpByWf.

@Test
public void B_sendEmailViaSmtpByWf() throws InterruptedException, BindPortException, OutOfRangePortException {
    assertTrue(this.isRunning());
    // init observer for this test only
    NotificationObserver observer = new NotificationObserver(1);
    this.addObserver(observer);
    int currentEmails = observer.getEmails().size();
    IdmIdentityDto identity = identityService.getByUsername(TO_WF);
    if (identity == null) {
        identity = helper.createIdentity(TO_WF);
    }
    identity.setEmail("example@example.tld");
    identity = identityService.save(identity);
    processInstanceService.startProcess(WF_NAME, null, InitTestDataProcessor.TEST_USER_1, null, null);
    // email is send by apache camel asynchronously
    if (observer.getEmails().size() == currentEmails) {
        observer.waitForMails();
    }
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setRecipient(identity.getUsername());
    filter.setNotificationType(IdmNotificationLog.class);
    List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
    // 
    assertEquals(1, notifications.size());
    assertTrue(this.isRunning());
    assertEquals(currentEmails + 1, observer.getEmails().size());
    for (EmailModel email : observer.getEmails()) {
        assertEquals(FROM, email.getFrom());
        assertEquals(identity.getEmail(), email.getTo());
    }
    // in last test stop smtp server
    this.stopSmtpServer();
}
Also used : IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) EmailModel(com.nilhcem.fakesmtp.model.EmailModel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractNotificationTest(eu.bcvsolutions.idm.test.api.AbstractNotificationTest)

Example 99 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.

the class IdmNotificationAttachmentControllerTest method prepareDto.

@Override
protected IdmNotificationAttachmentDto prepareDto() {
    IdmNotificationLogDto notification = new IdmNotificationLogDto();
    notification.setMessage(new IdmMessageDto.Builder(NotificationLevel.SUCCESS).setMessage(getHelper().createName()).build());
    // related notification
    notification = notificationLogService.save(notification);
    // 
    IdmAttachmentDto attachment = attachmentManager.save(DefaultAttachmentManagerIntegrationTest.prepareDto());
    // 
    IdmNotificationAttachmentDto dto = new IdmNotificationAttachmentDto();
    dto.setAttachment(attachment.getId());
    dto.setName(attachment.getName());
    dto.setNotification(notification.getId());
    // 
    return dto;
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)

Example 100 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.

the class IdentityDisableBulkActionTest method checkNotification.

@Test
public void checkNotification() {
    List<IdmIdentityDto> identities = this.createIdentities(5);
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityDisableBulkAction.NAME);
    Set<UUID> ids = this.getIdFromList(identities);
    bulkAction.setIdentifiers(ids);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, 5l, null, null);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setRecipient(loginIdentity.getUsername());
    filter.setNotificationType(IdmEmailLog.class);
    List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
    assertEquals(1, notifications.size());
    IdmNotificationLogDto notificationLogDto = notifications.get(0);
    assertEquals(IdmEmailLog.NOTIFICATION_TYPE, notificationLogDto.getType());
    assertTrue(notificationLogDto.getMessage().getHtmlMessage().contains(bulkAction.getName()));
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)107 Test (org.junit.Test)97 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)93 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)82 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)63 List (java.util.List)40 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)33 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)33 ZonedDateTime (java.time.ZonedDateTime)32 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)28 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)28 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)26 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)26 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)26 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)26 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)25 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)25 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)23 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)20 UUID (java.util.UUID)18