Search in sources :

Example 46 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class AuditEntryHandlerTestIT method resendNotificationTestIT.

@Test
public void resendNotificationTestIT() throws Exception {
    String content = ResourceUtil.getResourceAsString(getClass(), "/json/policyOverrideNotification.json", StandardCharsets.UTF_8);
    MockNotificationContent mockNotification = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), blackDuckProviderKey.getUniversalKey(), DateUtils.createCurrentDateTimestamp(), "POLICY_OVERRIDE", content, 1L, providerConfigModel.getConfigurationId());
    ConfigurationFieldModel providerConfigId = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
    providerConfigId.setFieldValue(String.valueOf(providerConfigModel.getConfigurationId()));
    DistributionJobRequestModel jobRequestModel = createJobRequestModel();
    DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
    NotificationEntity savedNotificationEntity = notificationContentRepository.save(mockNotification.createEntity());
    AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(jobModel.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasExecutePermission(Mockito.eq(ConfigContextEnum.GLOBAL.name()), Mockito.eq(AuditDescriptor.AUDIT_COMPONENT))).thenReturn(true);
    AuditEntryActions auditEntryActions = createAuditActions(authorizationManager);
    try {
        auditEntryActions.resendNotification(savedNotificationEntity.getId(), null);
        auditEntryActions.resendNotification(savedNotificationEntity.getId(), null);
        auditEntryActions.resendNotification(savedNotificationEntity.getId(), jobModel.getJobId());
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        fail("Expected the Audit POST request(s) not to throw an exception");
    }
    assertResponseStatusException(HttpStatus.GONE, () -> auditEntryActions.resendNotification(-1L, null));
    assertResponseStatusException(HttpStatus.GONE, () -> auditEntryActions.resendNotification(savedNotificationEntity.getId(), UUID.randomUUID()));
}
Also used : MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) ResponseStatusException(org.springframework.web.server.ResponseStatusException) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest)

Example 47 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class CertificateActionsTestIT method init.

@BeforeEach
public void init() throws Exception {
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasCreatePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    Mockito.when(authorizationManager.hasDeletePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    Mockito.when(authorizationManager.hasWritePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    Mockito.when(authorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    certificateActions = new CertificateActions(certificatesDescriptorKey, authorizationManager, certificateAccessor, trustStoreService);
    certTestUtil.init(alertProperties);
}
Also used : DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) CertificatesDescriptorKey(com.synopsys.integration.alert.component.certificates.CertificatesDescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 48 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class SettingsProxyTestActionTestIT method testValidationFailureTest.

@Test
void testValidationFailureTest() {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 49 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class SettingsProxyTestActionTestIT method testConfigurationWithPasswordSaved.

@Test
void testConfigurationWithPasswordSaved() throws AlertConfigurationException {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    settingsProxyConfigAccessor.createConfiguration(createSettingsProxyModel(testProperties));
    settingsProxyModel.setProxyPassword(null);
    settingsProxyModel.setIsProxyPasswordSet(true);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertFalse(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 50 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class SettingsProxyTestActionTestIT method testWithoutPermissionsCheckTest.

@Test
void testWithoutPermissionsCheckTest() {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.NO_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isError());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)83 Test (org.junit.jupiter.api.Test)78 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)49 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)38 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)38 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)38 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)27 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)26 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)20 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)16 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)15 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)14 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)13 ConfigurationTestResult (com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)12 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)9 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)9 JiraServerGlobalConfigurationValidator (com.synopsys.integration.alert.channel.jira.server.validator.JiraServerGlobalConfigurationValidator)8 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)7