Search in sources :

Example 1 with PrintStreamIntLogger

use of com.blackducksoftware.integration.log.PrintStreamIntLogger in project hub-alert by blackducksoftware.

the class LoginHandler method authenticateUser.

public ResponseEntity<String> authenticateUser(final HttpServletRequest request, final HttpServletResponse response, final LoginRestModel loginRestModel) {
    final IntLogger logger = new PrintStreamIntLogger(System.out, LogLevel.INFO);
    try {
        if (loginActions.authenticateUser(loginRestModel, logger)) {
            final CsrfToken token = csrfTokenRepository.generateToken(request);
            csrfTokenRepository.saveToken(token, request, response);
            response.setHeader(token.getHeaderName(), token.getToken());
            return createResponse(HttpStatus.OK, "{\"message\":\"Success\"}");
        }
        return createResponse(HttpStatus.UNAUTHORIZED, "User not administrator");
    } catch (final IntegrationRestException e) {
        logger.error(e.getMessage(), e);
        return createResponse(HttpStatus.valueOf(e.getHttpStatusCode()), e.getHttpStatusMessage() + " : " + e.getMessage());
    } catch (final AlertFieldException e) {
        logger.error(e.getMessage(), e);
        final ResponseBodyBuilder responseBodyBuilder = new ResponseBodyBuilder(0L, e.getMessage());
        responseBodyBuilder.putErrors(e.getFieldErrors());
        final String responseBody = responseBodyBuilder.build();
        return createResponse(HttpStatus.BAD_REQUEST, responseBody);
    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
        return createResponse(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) IntLogger(com.blackducksoftware.integration.log.IntLogger) PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) CsrfToken(org.springframework.security.web.csrf.CsrfToken) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) ResponseBodyBuilder(com.blackducksoftware.integration.hub.alert.web.model.ResponseBodyBuilder)

Example 2 with PrintStreamIntLogger

use of com.blackducksoftware.integration.log.PrintStreamIntLogger in project hub-alert by blackducksoftware.

the class HipChatChannelTest method testGlobalConfigThrowsExceptionTest.

@Test
public void testGlobalConfigThrowsExceptionTest() throws IntegrationException, MalformedURLException {
    final ChannelRestConnectionFactory restFactory = Mockito.mock(ChannelRestConnectionFactory.class);
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
    RestConnection restConnection = new UnauthenticatedRestConnection(new PrintStreamIntLogger(System.out, LogLevel.INFO), new URL("http://google.com"), 100, null, new UriCombiner());
    restConnection = Mockito.spy(restConnection);
    Mockito.doThrow(new IntegrationException("Mock exception")).when(restConnection).connect();
    Mockito.when(restFactory.createUnauthenticatedRestConnection(Mockito.anyString())).thenReturn(restConnection);
    hipChatMockUtil.setApiKey("apiKey");
    try {
        final GlobalHipChatConfigEntity entity = hipChatMockUtil.createGlobalEntity();
        hipChatChannel.testGlobalConfig(entity);
    } catch (final IntegrationException ex) {
        assertEquals("Invalid API key: Mock exception", ex.getMessage());
    }
}
Also used : UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) URL(java.net.URL) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 3 with PrintStreamIntLogger

use of com.blackducksoftware.integration.log.PrintStreamIntLogger in project hub-alert by blackducksoftware.

the class AccumulatorProcessorTestIT method init.

@Before
public void init() throws Exception {
    globalProperties = new TestGlobalProperties();
    final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactoryWithCredential(new PrintStreamIntLogger(System.out, LogLevel.TRACE));
    projectService = hubServicesFactory.createProjectService();
    notificationDataService = hubServicesFactory.createNotificationService();
    codeLocationService = hubServicesFactory.createCodeLocationService();
    hubService = hubServicesFactory.createHubService();
}
Also used : PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Before(org.junit.Before)

Aggregations

PrintStreamIntLogger (com.blackducksoftware.integration.log.PrintStreamIntLogger)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)1 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)1 GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)1 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)1 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)1 ResponseBodyBuilder (com.blackducksoftware.integration.hub.alert.web.model.ResponseBodyBuilder)1 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)1 UnauthenticatedRestConnection (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection)1 UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)1 IntegrationRestException (com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException)1 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)1 IntLogger (com.blackducksoftware.integration.log.IntLogger)1 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)1 URL (java.net.URL)1 Before (org.junit.Before)1 Test (org.junit.Test)1 CsrfToken (org.springframework.security.web.csrf.CsrfToken)1