use of org.sonar.server.exceptions.UnauthorizedException in project sonarqube by SonarSource.
the class LoginAction method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
if (!request.getMethod().equals(POST.name())) {
response.setStatus(HTTP_BAD_REQUEST);
return;
}
String login = request.getParameter("login");
String password = request.getParameter("password");
try {
UserDto userDto = authenticate(request, login, password);
jwtHttpHandler.generateToken(userDto, request, response);
threadLocalUserSession.set(userSessionFactory.create(userDto));
} catch (AuthenticationException e) {
authenticationEvent.loginFailure(request, e);
response.setStatus(HTTP_UNAUTHORIZED);
} catch (UnauthorizedException e) {
response.setStatus(e.httpCode());
}
}
use of org.sonar.server.exceptions.UnauthorizedException in project sonarqube by SonarSource.
the class LoginActionTest method return_authorized_code_when_unauthorized_exception_is_thrown.
@Test
public void return_authorized_code_when_unauthorized_exception_is_thrown() throws Exception {
doThrow(new UnauthorizedException("error !")).when(credentialsAuthenticator).authenticate(LOGIN, PASSWORD, request, FORM);
executeRequest(LOGIN, PASSWORD);
verify(response).setStatus(401);
assertThat(threadLocalUserSession.hasSession()).isFalse();
verifyZeroInteractions(authenticationEvent);
}
Aggregations