use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class AlertStartupInitializer method saveAction.
private Collection<ConfigurationFieldModel> saveAction(DescriptorKey descriptorKey, Collection<ConfigurationFieldModel> configurationFieldModels) throws AlertException {
Map<String, FieldValueModel> fieldValueModelMap = modelConverter.convertToFieldValuesMap(configurationFieldModels);
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), fieldValueModelMap);
FieldModel savedFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
return modelConverter.convertToConfigurationFieldModelMap(savedFieldModel).values();
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class ConfigurationOverridesStartupComponent method initialize.
@Override
protected void initialize() {
try {
FieldModel fieldModel = getFieldModel();
checkAndDisableLdapAuthentication(fieldModel);
checkAndDisableSamlAuthentication(fieldModel);
checkAndResetDefaultAdminPassword();
if (StringUtils.isBlank(fieldModel.getId())) {
configUtility.save(fieldModel);
} else {
configUtility.update(Long.valueOf(fieldModel.getId()), fieldModel);
}
} catch (AlertException | NumberFormatException ex) {
logger.error("Error performing configuration overrides.", ex);
}
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class BlackDuckGlobalConfigurationFieldModelValidatorTest method nonUniqueName.
@Test
public void nonUniqueName() {
String duplicateName = "duplicateName";
Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of(duplicateName), true);
defaultKeyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, apiKeyFieldValueModel);
FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
ConfigurationFieldModel configurationFieldModel = Mockito.mock(ConfigurationFieldModel.class);
Mockito.when(configurationFieldModel.getFieldValue()).thenReturn(Optional.of(duplicateName));
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
Mockito.when(configurationModel.getDescriptorContext()).thenReturn(ConfigContextEnum.GLOBAL);
Mockito.when(configurationModel.getField(Mockito.any())).thenReturn(Optional.of(configurationFieldModel));
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(Mockito.any())).thenReturn(List.of(configurationModel));
BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(configurationModelConfigurationAccessor);
Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
assertEquals(1, alertFieldStatuses.size());
AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElse(null);
assertNotNull(alertFieldStatus);
assertEquals(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, alertFieldStatus.getFieldName());
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class BlackDuckGlobalConfigurationFieldModelValidatorTest method verifyValidConfiguration.
/*
* Provider config name: Required, no duplicate names
* Url: required, valid Url
* API key: required, Specific length
* Timeout: required, long timeout warning, < 0 timeout error
*/
@Test
public void verifyValidConfiguration() {
Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(createDefaultConfigurationAccessor());
Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
assertEquals(0, alertFieldStatuses.size());
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class AzureBoardsCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<OAuthEndpointResponse> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
try {
Optional<FieldModel> savedFieldModel = saveIfValid(fieldModel);
if (!savedFieldModel.isPresent()) {
return createErrorResponse("The configuration is invalid. Please test the configuration.");
}
FieldUtility fieldUtility = createFieldAccessor(savedFieldModel.get());
Optional<String> clientId = fieldUtility.getString(AzureBoardsDescriptor.KEY_CLIENT_ID);
if (!clientId.isPresent()) {
return createErrorResponse("App ID not found.");
}
Optional<String> alertServerUrl = alertWebServerUrlManager.getServerUrl();
if (!alertServerUrl.isPresent()) {
return createErrorResponse("Could not determine the alert server url for the callback.");
}
String requestKey = oAuthRequestValidator.generateRequestKey();
// since we have only one OAuth channel now remove any other requests.
// if we have more OAuth clients then the "remove requests" will have to be removed from here.
// beginning authentication process create the request id at the start.
oAuthRequestValidator.removeRequestsOlderThan5MinutesAgo();
oAuthRequestValidator.addAuthorizationRequest(requestKey);
logger.info("OAuth authorization request created: {}", requestKey);
String authUrl = createAuthURL(clientId.get(), requestKey);
logger.debug("Authenticating Azure OAuth URL: {}", authUrl);
return new ActionResponse<>(HttpStatus.OK, new OAuthEndpointResponse(isAuthenticated(fieldUtility), authUrl, "Authenticating..."));
} catch (Exception ex) {
logger.error("Error activating Azure Boards", ex);
return createErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, "Error activating azure oauth.");
}
}
Aggregations