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