Search in sources :

Example 11 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class AuditEntryActions method resendNotification.

public List<AuditEntryRestModel> resendNotification(final Long id) throws IntegrationException, IllegalArgumentException {
    AuditEntryEntity auditEntryEntity = null;
    auditEntryEntity = auditEntryRepository.findOne(id);
    if (auditEntryEntity == null) {
        throw new AlertException("No audit entry with the provided id exists.");
    }
    final List<AuditNotificationRelation> relations = auditNotificationRepository.findByAuditEntryId(auditEntryEntity.getId());
    final List<Long> notificationIds = relations.stream().map(relation -> relation.getNotificationId()).collect(Collectors.toList());
    final List<NotificationModel> notifications = notificationManager.findByIds(notificationIds);
    final Long commonConfigId = auditEntryEntity.getCommonConfigId();
    final CommonDistributionConfigEntity commonConfigEntity = commonDistributionRepository.findOne(commonConfigId);
    if (notifications == null || notifications.isEmpty()) {
        throw new IllegalArgumentException("The notification for this entry was purged. To edit the purge schedule, please see the Scheduling Configuration.");
    }
    if (commonConfigEntity == null) {
        throw new IllegalArgumentException("The job for this entry was deleted, can not re-send this entry.");
    }
    final Collection<ProjectData> projectDataList = projectDataFactory.createProjectDataCollection(notifications);
    for (final ProjectData projectData : projectDataList) {
        final AbstractChannelEvent event = channelEventFactory.createEvent(commonConfigId, commonConfigEntity.getDistributionType(), projectData);
        event.setAuditEntryId(auditEntryEntity.getId());
        channelTemplateManager.sendEvent(event);
    }
    return get();
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) ChannelEventFactory(com.blackducksoftware.integration.hub.alert.channel.manager.ChannelEventFactory) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) DistributionChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) ArrayList(java.util.ArrayList) AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) ComponentRestModel(com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel) Logger(org.slf4j.Logger) GlobalChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity) Transactional(javax.transaction.Transactional) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ProjectDataFactory(com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory) List(java.util.List) Component(org.springframework.stereotype.Component) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) NotificationRestModel(com.blackducksoftware.integration.hub.alert.web.model.NotificationRestModel) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)

Example 12 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class VulnerabilityCache method getEvents.

@Override
public Collection<NotificationEvent> getEvents() throws HubIntegrationException {
    final Collection<NotificationEvent> vulnerabilities = super.getEvents();
    // need to group the vulnerabilities by severity which can be gathered by the vulnerability API.
    final Collection<NotificationEvent> result = new LinkedList<>();
    for (final NotificationEvent event : vulnerabilities) {
        List<NotificationEvent> vulnerabilityEvents;
        try {
            vulnerabilityEvents = createVulnerabilityEvents(event);
        } catch (final IntegrationException e) {
            throw new HubIntegrationException(e);
        }
        for (final NotificationEvent vulnerability : vulnerabilityEvents) {
            result.add(vulnerability);
        }
    }
    return this.addUserInformation(result);
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) LinkedList(java.util.LinkedList) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Example 13 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class LoginActions method isUserRoleValid.

public boolean isUserRoleValid(final String userName, final RestConnection restConnection) {
    final HubServicesFactory hubServicesFactory = new HubServicesFactory(restConnection);
    final UserGroupService userGroupService = hubServicesFactory.createUserGroupService();
    try {
        final List<RoleAssignmentView> userRoles = userGroupService.getRolesForUser(userName);
        for (final RoleAssignmentView roles : userRoles) {
            if ("System Administrator".equalsIgnoreCase(roles.name)) {
                return true;
            }
        }
    } catch (final IntegrationException e) {
        return false;
    }
    return false;
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) RoleAssignmentView(com.blackducksoftware.integration.hub.api.generated.view.RoleAssignmentView) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory)

Example 14 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class LoginActions method authenticateUser.

public boolean authenticateUser(final LoginRestModel loginRestModel, final IntLogger logger) throws IntegrationException {
    final HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setLogger(logger);
    serverConfigBuilder.setHubUrl(globalProperties.getHubUrl());
    serverConfigBuilder.setTimeout(HubServerConfigBuilder.DEFAULT_TIMEOUT_SECONDS);
    if (globalProperties.getHubTrustCertificate() != null) {
        serverConfigBuilder.setAlwaysTrustServerCertificate(globalProperties.getHubTrustCertificate());
    }
    serverConfigBuilder.setProxyHost(globalProperties.getHubProxyHost());
    serverConfigBuilder.setProxyPort(globalProperties.getHubProxyPort());
    serverConfigBuilder.setProxyUsername(globalProperties.getHubProxyUsername());
    serverConfigBuilder.setProxyPassword(globalProperties.getHubProxyPassword());
    serverConfigBuilder.setPassword(loginRestModel.getHubPassword());
    serverConfigBuilder.setUsername(loginRestModel.getHubUsername());
    try {
        validateHubConfiguration(serverConfigBuilder);
        final RestConnection restConnection = createRestConnection(serverConfigBuilder);
        restConnection.connect();
        logger.info("Connected");
        final boolean isValidLoginUser = isUserRoleValid(loginRestModel.getHubUsername(), restConnection);
        if (isValidLoginUser) {
            final Authentication authentication = new UsernamePasswordAuthenticationToken(loginRestModel.getHubUsername(), loginRestModel.getHubPassword(), Arrays.asList(new SimpleGrantedAuthority("ROLE_ADMIN")));
            SecurityContextHolder.getContext().setAuthentication(authentication);
            return authentication.isAuthenticated();
        }
    } catch (final AlertFieldException afex) {
        logger.error("Error establishing connection", afex);
        final Map<String, String> fieldErrorMap = afex.getFieldErrors();
        fieldErrorMap.keySet().forEach(key -> {
            final String value = fieldErrorMap.get(key);
            logger.error(String.format("Field Error %s - %s", key, value));
        });
        logger.info("User not authenticated");
        return false;
    } catch (final IntegrationException ex) {
        logger.error("Error establishing connection", ex);
        logger.info("User not authenticated");
        return false;
    }
    logger.info("User role not authenticated");
    return false;
}
Also used : AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) Arrays(java.util.Arrays) IntLogger(com.blackducksoftware.integration.log.IntLogger) FieldEnum(com.blackducksoftware.integration.validator.FieldEnum) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) Map(java.util.Map) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) RoleAssignmentView(com.blackducksoftware.integration.hub.api.generated.view.RoleAssignmentView) ValidationResults(com.blackducksoftware.integration.validator.ValidationResults) Set(java.util.Set) AbstractValidator(com.blackducksoftware.integration.validator.AbstractValidator) List(java.util.List) Component(org.springframework.stereotype.Component) LoginRestModel(com.blackducksoftware.integration.hub.alert.web.model.LoginRestModel) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) Entry(java.util.Map.Entry) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ValidationResult(com.blackducksoftware.integration.validator.ValidationResult) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig) Authentication(org.springframework.security.core.Authentication) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class HipChatChannelTest method createRequestThrowsExceptionWhenRoomIdIsNullTest.

public void createRequestThrowsExceptionWhenRoomIdIsNullTest() {
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, null);
    IntegrationException intException = null;
    try {
        hipChatChannel.createRequest(null, new HipChatDistributionConfigEntity(null, null, null), null);
    } catch (final IntegrationException e) {
        intException = e;
    }
    assertNotNull(intException);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HipChatDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.distribution.HipChatDistributionConfigEntity)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)24 Test (org.junit.Test)12 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)5 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)5 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)4 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)4 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)3 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)3 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)3 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 Request (com.blackducksoftware.integration.hub.request.Request)3 UserGroupService (com.blackducksoftware.integration.hub.service.UserGroupService)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 HashMap (java.util.HashMap)3 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)2 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)2