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);
}
use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class HipChatChannelTest method testGlobalConfigInvalidApiKeyTest.
@Test
public void testGlobalConfigInvalidApiKeyTest() {
final TestGlobalProperties globalProperties = new TestGlobalProperties();
globalProperties.setHubTrustCertificate(Boolean.TRUE);
final ChannelRestConnectionFactory restFactory = new ChannelRestConnectionFactory(globalProperties);
final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
hipChatMockUtil.setApiKey("garbage");
try {
final GlobalHipChatConfigEntity entity = hipChatMockUtil.createGlobalEntity();
hipChatChannel.testGlobalConfig(entity);
} catch (final IntegrationException ex) {
assertTrue(ex.getMessage().contains("Invalid API key: "));
}
}
Aggregations