use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ConfigurationCrudHelperTest method testCreateException.
@Test
public void testCreateException() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ThrowingSupplier<TestObfuscatedVariable, Exception> modelCreator = () -> {
throw new AlertException("error getting test message");
};
ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ActionResponse response = configurationHelper.create(() -> ValidationResponseModel.success(), () -> Boolean.FALSE, modelCreator);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getHttpStatus());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class AlertTrustStoreManager method getAsKeyStore.
public synchronized KeyStore getAsKeyStore(File keyStore, char[] keyStorePass, String keyStoreType) throws AlertException {
logger.debug("Get key store.");
KeyStore.PasswordProtection protection = new KeyStore.PasswordProtection(keyStorePass);
try {
return KeyStore.Builder.newInstance(keyStoreType, null, keyStore, protection).getKeyStore();
} catch (KeyStoreException e) {
throw new AlertException("There was a problem accessing the trust store.", e);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class AlertTrustStoreManager method getAsJavaCertificate.
private Certificate getAsJavaCertificate(CustomCertificateModel customCertificate) throws AlertException {
try {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
String certificateContent = customCertificate.getCertificateContent();
try (ByteArrayInputStream certInputStream = new ByteArrayInputStream(certificateContent.getBytes())) {
return certFactory.generateCertificate(certInputStream);
}
} catch (CertificateException | IOException e) {
throw new AlertException("The custom certificate could not be read.", e);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class SAMLContext method disableSAML.
public void disableSAML() {
try {
ConfigurationModel configurationModel = getCurrentConfiguration();
Map<String, ConfigurationFieldModel> fields = configurationModel.getCopyOfKeyToFieldMap();
ConfigurationFieldModel enabledField = fields.get(AuthenticationDescriptor.KEY_SAML_ENABLED);
if (null == enabledField) {
enabledField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_SAML_ENABLED);
fields.put(AuthenticationDescriptor.KEY_SAML_ENABLED, enabledField);
}
enabledField.setFieldValue(String.valueOf(false));
configurationModelConfigurationAccessor.updateConfiguration(configurationModel.getConfigurationId(), fields.values());
} catch (AlertException ex) {
logger.error("Error disabling SAML configuration.");
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class AuthenticationEventManager method sendAuthenticationEvent.
private void sendAuthenticationEvent(String username, String emailAddress, AuthenticationType authenticationType, Collection<? extends GrantedAuthority> authorities) throws AlertException {
if (username == null) {
throw new AlertException("Unable to send authentication event with null username");
}
Set<UserRoleModel> alertRoles = authorities.stream().map(this::getRoleFromAuthority).flatMap(Optional::stream).map(UserRoleModel::of).collect(Collectors.toSet());
// The database users will not be enabled because they already exist in the database when this is called. So a new entry will not be added to the database.
UserModel userModel = UserModel.newUser(username, null, emailAddress, authenticationType, alertRoles, true);
sendAuthenticationEvent(userModel);
}
Aggregations