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