Search in sources :

Example 1 with AlertException

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());
}
Also used : ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) 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) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 2 with AlertException

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);
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 3 with AlertException

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 4 with AlertException

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.");
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 5 with AlertException

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);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Optional(java.util.Optional) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel)

Aggregations

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)101 Test (org.junit.jupiter.api.Test)35 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)22 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 List (java.util.List)18 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)16 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 Optional (java.util.Optional)13 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)11 HashMap (java.util.HashMap)11 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ArrayList (java.util.ArrayList)9 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 UUID (java.util.UUID)8 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)7