Search in sources :

Example 51 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class SAMLManager method initializeConfiguration.

public void initializeConfiguration() {
    logger.info("Initializing SAML identity provider with database configuration.");
    try {
        ConfigurationModel currentConfiguration = samlContext.getCurrentConfiguration();
        boolean samlEnabled = samlContext.isSAMLEnabled(currentConfiguration);
        String metadataURL = samlContext.getFieldValueOrEmpty(currentConfiguration, AuthenticationDescriptor.KEY_SAML_METADATA_URL);
        String entityId = samlContext.getFieldValueOrEmpty(currentConfiguration, AuthenticationDescriptor.KEY_SAML_ENTITY_ID);
        String entityBaseUrl = samlContext.getFieldValueOrEmpty(currentConfiguration, AuthenticationDescriptor.KEY_SAML_ENTITY_BASE_URL);
        if (samlEnabled) {
            // validate the metadata providers.  If they are still valid enable SAML.
            samlEnabled = checkMetadataProvidersValid(metadataURL, entityId);
        }
        updateSAMLConfiguration(samlEnabled, metadataURL, entityId, entityBaseUrl);
    } catch (AlertConfigurationException e) {
        logger.warn(String.format("Cannot initialize the SAML identity provider. %s", e.getMessage()));
    } catch (Exception e) {
        logger.error("Error initializing the SAML identity provider.", e);
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) MetadataProviderException(org.opensaml.saml2.metadata.provider.MetadataProviderException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 52 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelper method update.

public <T extends Obfuscated<T>> ActionResponse<T> update(Supplier<ValidationResponseModel> validator, BooleanSupplier existingModelSupplier, ThrowingSupplier<T, AlertConfigurationException> updateFunction) {
    String actionName = "update";
    logger.trace(ACTION_CALLED_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
    if (!authorizationManager.hasWritePermission(context, descriptorKey)) {
        logger.trace(ACTION_MISSING_PERMISSIONS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
        return ActionResponse.createForbiddenResponse();
    }
    boolean configurationExists = existingModelSupplier.getAsBoolean();
    if (!configurationExists) {
        logger.trace(ACTION_NOT_FOUND_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    ValidationResponseModel validationResponse = validator.get();
    if (validationResponse.hasErrors()) {
        logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
        return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResponse.getMessage());
    }
    try {
        return new ActionResponse<>(HttpStatus.OK, updateFunction.get().obfuscate());
    } catch (AlertConfigurationException ex) {
        logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
        return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Error updating config: %s", ex.getMessage()));
    } catch (Exception ex) {
        logger.error("Error updating config:", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error updating config: %s", ex.getMessage()));
    } finally {
        logger.trace(ACTION_SUCCESS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 53 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class ProxySettingsEnvironmentHandlerFactory method updateFunction.

private EnvironmentProcessingResult updateFunction() {
    EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(PROXY_CONFIGURATION_KEYSET);
    SettingsProxyModel configModel = new SettingsProxyModel();
    configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    configureProxySettings(configModel);
    // TODO: Refactor and remove duplicate code after 6.10.0 model package refactor
    ValidationResponseModel validationResponseModel = validator.validate(configModel);
    if (validationResponseModel.hasErrors()) {
        logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
        Map<String, AlertFieldStatus> errors = validationResponseModel.getErrors();
        for (Map.Entry<String, AlertFieldStatus> error : errors.entrySet()) {
            AlertFieldStatus status = error.getValue();
            logger.error("Field: '{}' failed with the error: {}", status.getFieldName(), status.getFieldMessage());
        }
        return EnvironmentProcessingResult.empty();
    }
    SettingsProxyModel obfuscatedModel = configModel.obfuscate();
    obfuscatedModel.getProxyHost().ifPresent(value -> builder.addVariableValue(PROXY_HOST_KEY, value));
    obfuscatedModel.getProxyPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_PORT_KEY, value));
    obfuscatedModel.getProxyUsername().ifPresent(value -> builder.addVariableValue(PROXY_USERNAME_KEY, value));
    obfuscatedModel.getNonProxyHosts().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_NON_PROXY_HOSTS_KEY, value));
    if (Boolean.TRUE.equals(obfuscatedModel.getIsProxyPasswordSet())) {
        builder.addVariableValue(PROXY_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
    }
    EnvironmentProcessingResult result = builder.build();
    if (result.hasValues()) {
        try {
            configAccessor.createConfiguration(configModel);
        } catch (AlertConfigurationException ex) {
            logger.error("Error creating the configuration: {}", ex.getMessage());
        }
    }
    return result;
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Map(java.util.Map) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 54 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class SAMLStartupComponentTest method testInitializeException.

@Test
public void testInitializeException() throws Exception {
    SAMLContext context = Mockito.mock(SAMLContext.class);
    ParserPool parserPool = Mockito.mock(ParserPool.class);
    ExtendedMetadata extendedMetadata = Mockito.mock(ExtendedMetadata.class);
    MetadataManager metadataManager = Mockito.mock(MetadataManager.class);
    MetadataGenerator metadataGenerator = Mockito.mock(MetadataGenerator.class);
    FilePersistenceUtil filePersistenceUtil = Mockito.mock(FilePersistenceUtil.class);
    Mockito.when(context.getCurrentConfiguration()).thenThrow(new AlertConfigurationException("Test exception"));
    SAMLManager samlManager = new SAMLManager(parserPool, extendedMetadata, metadataManager, metadataGenerator, filePersistenceUtil, context);
    SAMLStartupComponent startupComponent = new SAMLStartupComponent(samlManager);
    startupComponent.initializeComponent();
    Mockito.verify(metadataGenerator, Mockito.times(0)).setEntityId(Mockito.anyString());
    Mockito.verify(metadataGenerator, Mockito.times(0)).setEntityBaseURL(Mockito.anyString());
    Mockito.verify(metadataManager, Mockito.times(0)).setProviders(Mockito.anyList());
    Mockito.verify(metadataManager, Mockito.times(0)).afterPropertiesSet();
}
Also used : ParserPool(org.opensaml.xml.parse.ParserPool) MetadataManager(org.springframework.security.saml.metadata.MetadataManager) FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) SAMLContext(com.synopsys.integration.alert.component.authentication.security.saml.SAMLContext) ExtendedMetadata(org.springframework.security.saml.metadata.ExtendedMetadata) SAMLManager(com.synopsys.integration.alert.component.authentication.security.saml.SAMLManager) MetadataGenerator(org.springframework.security.saml.metadata.MetadataGenerator) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)54 Test (org.junit.jupiter.api.Test)20 Transactional (org.springframework.transaction.annotation.Transactional)10 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 UUID (java.util.UUID)8 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)5 Map (java.util.Map)5 JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)4 JiraServerGlobalConfigModel (com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)4 AlertForbiddenOperationException (com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException)4 UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 HashMap (java.util.HashMap)4 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)3 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)3 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)3 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 UserEntity (com.synopsys.integration.alert.database.user.UserEntity)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3