use of org.sonar.api.server.authentication.IdentityProvider in project sonarqube by SonarSource.
the class InitFilterTest method redirect_with_context_path_when_failing_because_of_UnauthorizedException.
@Test
public void redirect_with_context_path_when_failing_because_of_UnauthorizedException() throws Exception {
when(server.getContextPath()).thenReturn("/sonarqube");
IdentityProvider identityProvider = new FailWithUnauthorizedExceptionIdProvider("failing");
when(request.getRequestURI()).thenReturn("/sonarqube/sessions/init/" + identityProvider.getKey());
identityProviderRepository.addIdentityProvider(identityProvider);
underTest.doFilter(request, response, chain);
verify(response).sendRedirect("/sonarqube/sessions/unauthorized?message=Email+john%40email.com+is+already+used");
}
use of org.sonar.api.server.authentication.IdentityProvider in project sonarqube by SonarSource.
the class OAuth2CallbackFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
IdentityProvider provider = resolveProviderOrHandleResponse(httpRequest, httpResponse, CALLBACK_PATH);
if (provider != null) {
handleProvider(httpRequest, (HttpServletResponse) response, provider);
}
}
use of org.sonar.api.server.authentication.IdentityProvider in project sonarqube by SonarSource.
the class InitFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
IdentityProvider provider = resolveProviderOrHandleResponse(httpRequest, httpResponse, INIT_CONTEXT);
if (provider != null) {
handleProvider(httpRequest, httpResponse, provider);
}
}
use of org.sonar.api.server.authentication.IdentityProvider in project sonarqube by SonarSource.
the class InitFilterTest method fail_if_identity_provider_class_is_unsupported.
@Test
public void fail_if_identity_provider_class_is_unsupported() throws Exception {
String unsupportedKey = "unsupported";
when(request.getRequestURI()).thenReturn("/sessions/init/" + unsupportedKey);
IdentityProvider identityProvider = new UnsupportedIdentityProvider(unsupportedKey);
identityProviderRepository.addIdentityProvider(identityProvider);
underTest.doFilter(request, response, chain);
assertError("Unsupported IdentityProvider class: class org.sonar.server.authentication.InitFilterTest$UnsupportedIdentityProvider");
verifyZeroInteractions(authenticationEvent);
}
use of org.sonar.api.server.authentication.IdentityProvider in project sonarqube by SonarSource.
the class InitFilterTest method redirect_when_failing_because_of_UnauthorizedExceptionException.
@Test
public void redirect_when_failing_because_of_UnauthorizedExceptionException() throws Exception {
IdentityProvider identityProvider = new FailWithUnauthorizedExceptionIdProvider("failing");
when(request.getRequestURI()).thenReturn("/sessions/init/" + identityProvider.getKey());
identityProviderRepository.addIdentityProvider(identityProvider);
underTest.doFilter(request, response, chain);
verify(response).sendRedirect("/sessions/unauthorized?message=Email+john%40email.com+is+already+used");
verify(authenticationEvent).loginFailure(eq(request), authenticationExceptionCaptor.capture());
AuthenticationException authenticationException = authenticationExceptionCaptor.getValue();
assertThat(authenticationException).hasMessage("Email john@email.com is already used");
assertThat(authenticationException.getSource()).isEqualTo(AuthenticationEvent.Source.external(identityProvider));
assertThat(authenticationException.getLogin()).isNull();
assertThat(authenticationException.getPublicMessage()).isEqualTo("Email john@email.com is already used");
}
Aggregations