use of com.blackducksoftware.integration.hub.alert.exception.AlertFieldException 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.hub.alert.exception.AlertFieldException in project hub-alert by blackducksoftware.
the class GlobalEmailConfigActionsTest method testInvalidConfig.
@Override
public void testInvalidConfig() {
final MockEmailGlobalRestModel mockUtil = new MockEmailGlobalRestModel();
mockUtil.setMailSmtpPort("qq");
mockUtil.setMailSmtpConnectionTimeout("qq");
mockUtil.setMailSmtpTimeout("qq");
mockUtil.setMailSmtpEhlo(false);
mockUtil.setMailSmtpAuth(true);
mockUtil.setMailSmtpAllow8bitmime(false);
mockUtil.setMailSmtpSendPartial(false);
final GlobalEmailConfigRestModel restModel = mockUtil.createGlobalRestModel();
String result = null;
try {
result = configActions.validateConfig(restModel);
fail();
} catch (final AlertFieldException e) {
assertTrue(true);
}
assertNull(result);
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertFieldException in project hub-alert by blackducksoftware.
the class CommonConfigHandlerTest method testConfigWithAlertFieldExceptionTest.
@Test
public void testConfigWithAlertFieldExceptionTest() throws Exception {
final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
Mockito.when(configActions.testConfig(Mockito.any())).thenThrow(new AlertFieldException(Collections.emptyMap()));
Mockito.when(configActions.getObjectTransformer()).thenReturn(objectTransformer);
final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
final ResponseEntity<String> response = handler.testConfig(restModel);
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertFieldException in project hub-alert by blackducksoftware.
the class LoginHandlerTest method authenticateUserWithAlertFieldExceptionTest.
@Test
public void authenticateUserWithAlertFieldExceptionTest() throws IntegrationException {
final LoginActions loginActions = Mockito.mock(LoginActions.class);
final LoginHandler loginHandler = new LoginHandler(objectTransformer, loginActions, csrfTokenRepository);
Mockito.when(loginActions.authenticateUser(Mockito.any(), Mockito.any())).thenThrow(new AlertFieldException(Collections.emptyMap()));
final ResponseEntity<String> response = loginHandler.authenticateUser(null, null, null);
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertFieldException in project hub-alert by blackducksoftware.
the class GlobalHubConfigActionsTest method testInvalidConfig.
@Override
public void testInvalidConfig() {
final MockGlobalHubRestModel mockUtil = new MockGlobalHubRestModel();
mockUtil.setHubTimeout("qqq");
final GlobalHubConfigRestModel restModel = mockUtil.createGlobalRestModel();
String result = null;
try {
result = configActions.validateConfig(restModel);
fail();
} catch (final AlertFieldException e) {
assertTrue(true);
}
assertNull(result);
mockUtil.setHubApiKey(StringUtils.repeat('a', 300));
final GlobalHubConfigRestModel restModelBigApi = mockUtil.createGlobalRestModel();
String resultBigApi = null;
try {
resultBigApi = configActions.validateConfig(restModelBigApi);
fail();
} catch (final AlertFieldException e) {
assertTrue(true);
}
assertNull(resultBigApi);
}
Aggregations