Search in sources :

Example 1 with EncryptionException

use of com.blackducksoftware.integration.exception.EncryptionException in project hub-fortify-ssc-integration-service by blackducksoftware.

the class RestConnectionHelper method getRestConnection.

/**
 * Get the Hub REST connection
 *
 * @param serverConfig
 * @param logLevel
 * @return
 */
private static CredentialsRestConnection getRestConnection(final HubServerConfig serverConfig, final LogLevel logLevel) {
    CredentialsRestConnection restConnection;
    try {
        final ProxyInfo proxyInfo = getProxyInfo(serverConfig);
        restConnection = new CredentialsRestConnection(new PrintStreamIntLogger(System.out, logLevel), serverConfig.getHubUrl(), serverConfig.getGlobalCredentials().getUsername(), serverConfig.getGlobalCredentials().getDecryptedPassword(), serverConfig.getTimeout(), proxyInfo, new UriCombiner());
    } catch (final IllegalArgumentException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (final EncryptionException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return restConnection;
}
Also used : ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) CredentialsRestConnection(com.blackducksoftware.integration.hub.rest.CredentialsRestConnection) EncryptionException(com.blackducksoftware.integration.exception.EncryptionException)

Example 2 with EncryptionException

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

the class AuditEntryRepositoryWrapperTest method testFindFirstByCommonConfigIdOrderByTimeLastSentDesc.

@Test
public void testFindFirstByCommonConfigIdOrderByTimeLastSentDesc() throws IOException {
    final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
    final AuditEntryRepository repository = Mockito.mock(AuditEntryRepository.class);
    Mockito.when(repository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.anyLong())).thenReturn(mockAuditEntryEntity.createEntity());
    final AuditEntryRepositoryWrapper auditEntryRepositoryWrapper = new AuditEntryRepositoryWrapper(repository) {

        @Override
        public AuditEntryEntity decryptSensitiveData(final AuditEntryEntity entity) throws EncryptionException {
            throw new EncryptionException();
        }
    };
    final AuditEntryEntity actual = auditEntryRepositoryWrapper.findFirstByCommonConfigIdOrderByTimeLastSentDesc(1L);
    assertNull(actual);
    assertTrue(outputLogger.isLineContainingText("Error finding common distribution config"));
}
Also used : EncryptionException(com.blackducksoftware.integration.exception.EncryptionException) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) Test(org.junit.Test)

Example 3 with EncryptionException

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

the class ConfiguredProjectsRepositoryWrapperTest method testFindByProjectName.

@Test
public void testFindByProjectName() throws IOException {
    final ProjectMockUtils projectMockUtils = new ProjectMockUtils();
    final ConfiguredProjectsRepository repository = Mockito.mock(ConfiguredProjectsRepository.class);
    Mockito.when(repository.findByProjectName(Mockito.anyString())).thenReturn(projectMockUtils.getProjectOneEntity());
    final ConfiguredProjectsRepositoryWrapper configuredProjectsRepositoryWrapper = new ConfiguredProjectsRepositoryWrapper(repository) {

        @Override
        public ConfiguredProjectEntity decryptSensitiveData(final ConfiguredProjectEntity entity) throws EncryptionException {
            throw new EncryptionException();
        }
    };
    final ConfiguredProjectEntity actual = configuredProjectsRepositoryWrapper.findByProjectName("any");
    assertNull(actual);
    assertTrue(outputLogger.isLineContainingText("Error finding common distribution config"));
}
Also used : ProjectMockUtils(com.blackducksoftware.integration.hub.alert.mock.ProjectMockUtils) EncryptionException(com.blackducksoftware.integration.exception.EncryptionException) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) Test(org.junit.Test)

Example 4 with EncryptionException

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

the class RepositoryWrapperTest method getExceptionThrowingRepositoryWrapper.

@SuppressWarnings("unchecked")
public W getExceptionThrowingRepositoryWrapper() throws EncryptionException {
    final R repository = getMockedRepository();
    final W wrapper = getRepositoryObjectWrapper(repository);
    final W wrapperSpy = Mockito.spy(wrapper);
    Mockito.doThrow(new EncryptionException()).when(wrapperSpy).decryptSensitiveData((E) Mockito.any(DatabaseEntity.class));
    Mockito.doThrow(new EncryptionException()).when(wrapperSpy).encryptSensitiveData((E) Mockito.any(DatabaseEntity.class));
    return wrapperSpy;
}
Also used : EncryptionException(com.blackducksoftware.integration.exception.EncryptionException)

Example 5 with EncryptionException

use of com.blackducksoftware.integration.exception.EncryptionException in project hub-detect by blackducksoftware.

the class HubServiceWrapper method init.

public void init() throws IntegrationException, DetectUserFriendlyException {
    try {
        slf4jIntLogger = new Slf4jIntLogger(logger);
        hubServerConfig = createHubServerConfig(slf4jIntLogger);
        hubServicesFactory = createHubServicesFactory(slf4jIntLogger, hubServerConfig);
    } catch (IllegalStateException | EncryptionException e) {
        throw new DetectUserFriendlyException(String.format("Not able to initialize Hub connection: %s", e.getMessage()), e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
    }
    final HubService hubService = createHubService();
    final CurrentVersionView currentVersion = hubService.getResponse(ApiDiscovery.CURRENT_VERSION_LINK_RESPONSE);
    logger.info(String.format("Successfully connected to Hub (version %s)!", currentVersion.version));
    detectPhoneHomeManager.init(createPhoneHomeService());
    detectPhoneHomeManager.startPhoneHome();
}
Also used : CurrentVersionView(com.blackducksoftware.integration.hub.api.generated.response.CurrentVersionView) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) EncryptionException(com.blackducksoftware.integration.exception.EncryptionException) HubService(com.blackducksoftware.integration.hub.service.HubService)

Aggregations

EncryptionException (com.blackducksoftware.integration.exception.EncryptionException)5 Test (org.junit.Test)2 MockAuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity)1 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)1 ProjectMockUtils (com.blackducksoftware.integration.hub.alert.mock.ProjectMockUtils)1 CurrentVersionView (com.blackducksoftware.integration.hub.api.generated.response.CurrentVersionView)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)1 CredentialsRestConnection (com.blackducksoftware.integration.hub.rest.CredentialsRestConnection)1 UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)1 HubService (com.blackducksoftware.integration.hub.service.HubService)1 PrintStreamIntLogger (com.blackducksoftware.integration.log.PrintStreamIntLogger)1 Slf4jIntLogger (com.blackducksoftware.integration.log.Slf4jIntLogger)1