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);
}
}
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);
}
}
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;
}
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();
}
Aggregations