Search in sources :

Example 86 with DescriptorKey

use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.

the class JiraServerGlobalCrudActionsTestIT method init.

@BeforeEach
public void init() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = ChannelKeys.JIRA_SERVER;
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 87 with DescriptorKey

use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method validateBadRequestTest.

@Test
public void validateBadRequestTest() {
    Descriptor descriptorWithValidator = createDescriptor(Optional::empty, () -> Optional.of(jobFieldModel -> Set.of()));
    JobConfigActions jobConfigActionsForTest = createJobConfigActions(new DescriptorMap(List.of(descriptorKey), List.of(descriptorWithValidator)), List.of());
    Mockito.when(mockedJobAccessor.getJobByName(Mockito.anyString())).thenReturn(Optional.of(distributionJobModel));
    ValidationActionResponse validationActionResponse = jobConfigActionsForTest.validate(jobFieldModel);
    assertTrue(validationActionResponse.isSuccessful());
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent());
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
    assertTrue(validationResponseModel.hasErrors(), "Expected validation response to have errors");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) DistributionChannelTestAction(com.synopsys.integration.alert.common.channel.DistributionChannelTestAction) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) HttpUrl(com.synopsys.integration.rest.HttpUrl) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) GlobalConfigurationFieldModelValidator(com.synopsys.integration.alert.common.descriptor.validator.GlobalConfigurationFieldModelValidator) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) Set(java.util.Set) UUID(java.util.UUID) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Test(org.junit.jupiter.api.Test) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) Optional(java.util.Optional) JobFieldStatuses(com.synopsys.integration.alert.common.rest.model.JobFieldStatuses) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) HashMap(java.util.HashMap) DistributionConfigurationValidator(com.synopsys.integration.alert.common.descriptor.validator.DistributionConfigurationValidator) Supplier(java.util.function.Supplier) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) HttpMethod(com.synopsys.integration.rest.HttpMethod) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) Mockito(org.mockito.Mockito) HttpStatus(org.springframework.http.HttpStatus) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) GlobalConfigExistsValidator(com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) Optional(java.util.Optional) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) Test(org.junit.jupiter.api.Test)

Example 88 with DescriptorKey

use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method validateTest.

@Test
public void validateTest() {
    Descriptor descriptorWithValidator = createDescriptor(Optional::empty, () -> Optional.of(jobFieldModel -> Set.of()));
    JobConfigActions jobConfigActionsForTest = createJobConfigActions(new DescriptorMap(List.of(descriptorKey), List.of(descriptorWithValidator)), List.of());
    ValidationActionResponse validationActionResponse = jobConfigActionsForTest.validate(jobFieldModel);
    assertTrue(validationActionResponse.isSuccessful());
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent());
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
    assertFalse(validationResponseModel.hasErrors());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) DistributionChannelTestAction(com.synopsys.integration.alert.common.channel.DistributionChannelTestAction) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) HttpUrl(com.synopsys.integration.rest.HttpUrl) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) GlobalConfigurationFieldModelValidator(com.synopsys.integration.alert.common.descriptor.validator.GlobalConfigurationFieldModelValidator) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) Set(java.util.Set) UUID(java.util.UUID) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Test(org.junit.jupiter.api.Test) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) Optional(java.util.Optional) JobFieldStatuses(com.synopsys.integration.alert.common.rest.model.JobFieldStatuses) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) HashMap(java.util.HashMap) DistributionConfigurationValidator(com.synopsys.integration.alert.common.descriptor.validator.DistributionConfigurationValidator) Supplier(java.util.function.Supplier) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) HttpMethod(com.synopsys.integration.rest.HttpMethod) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) Mockito(org.mockito.Mockito) HttpStatus(org.springframework.http.HttpStatus) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) GlobalConfigExistsValidator(com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) Optional(java.util.Optional) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) Test(org.junit.jupiter.api.Test)

Example 89 with DescriptorKey

use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelTest method convertDefinedFieldModelTest.

@Test
public void convertDefinedFieldModelTest() throws Exception {
    List<DefinedFieldModel> configFields = createConfigFields();
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    Mockito.when(encryptionUtility.isInitialized()).thenReturn(true);
    DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
    List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
    Optional<ConfigurationFieldModel> optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, false), VALUE_FIELD_1, true);
    assertTrue(optionalModel.isPresent());
    ConfigurationFieldModel actualModel = optionalModel.get();
    assertEquals(VALUE_FIELD_1, actualModel.getFieldValue().orElseThrow(IllegalArgumentException::new));
    assertFalse(actualModel.isSensitive());
    assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
    optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, true), VALUE_FIELD_1, true);
    assertTrue(optionalModel.isPresent());
    actualModel = optionalModel.get();
    assertEquals(VALUE_FIELD_1, actualModel.getFieldValue().orElseThrow(IllegalArgumentException::new));
    assertTrue(actualModel.isSensitive());
    assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 90 with DescriptorKey

use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.

the class AuthorizationManager method getOperations.

public final Set<Integer> getOperations(ConfigContextEnum context, DescriptorKey descriptorKey) {
    PermissionKey permissionKey = new PermissionKey(context.name(), descriptorKey.getUniversalKey());
    Collection<String> roleNames = getCurrentUserRoleNames();
    return roleNames.stream().filter(permissionCache::containsKey).map(permissionCache::get).map(object -> object.getOperations(permissionKey)).collect(Collectors.toSet());
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) AlertForbiddenOperationException(com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) UserDetails(org.springframework.security.core.userdetails.UserDetails) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Logger(org.slf4j.Logger) AccessOperation(com.synopsys.integration.alert.common.enumeration.AccessOperation) Collection(java.util.Collection) Set(java.util.Set) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) RoleAccessor(com.synopsys.integration.alert.common.descriptor.accessor.RoleAccessor) Component(org.springframework.stereotype.Component) Optional(java.util.Optional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Authentication(org.springframework.security.core.Authentication) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey)

Aggregations

DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)91 Test (org.junit.jupiter.api.Test)72 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)42 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)42 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)41 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)39 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)29 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)28 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)23 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)23 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)21 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)18 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)17 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)13 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)12 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)12 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)12 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)12