Search in sources :

Example 1 with IdentityProvider

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");
}
Also used : OAuth2IdentityProvider(org.sonar.api.server.authentication.OAuth2IdentityProvider) IdentityProvider(org.sonar.api.server.authentication.IdentityProvider) BaseIdentityProvider(org.sonar.api.server.authentication.BaseIdentityProvider) Test(org.junit.Test)

Example 2 with IdentityProvider

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) OAuth2IdentityProvider(org.sonar.api.server.authentication.OAuth2IdentityProvider) IdentityProvider(org.sonar.api.server.authentication.IdentityProvider)

Example 3 with IdentityProvider

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) OAuth2IdentityProvider(org.sonar.api.server.authentication.OAuth2IdentityProvider) IdentityProvider(org.sonar.api.server.authentication.IdentityProvider) BaseIdentityProvider(org.sonar.api.server.authentication.BaseIdentityProvider)

Example 4 with IdentityProvider

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);
}
Also used : OAuth2IdentityProvider(org.sonar.api.server.authentication.OAuth2IdentityProvider) IdentityProvider(org.sonar.api.server.authentication.IdentityProvider) BaseIdentityProvider(org.sonar.api.server.authentication.BaseIdentityProvider) Test(org.junit.Test)

Example 5 with IdentityProvider

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");
}
Also used : AuthenticationException(org.sonar.server.authentication.event.AuthenticationException) OAuth2IdentityProvider(org.sonar.api.server.authentication.OAuth2IdentityProvider) IdentityProvider(org.sonar.api.server.authentication.IdentityProvider) BaseIdentityProvider(org.sonar.api.server.authentication.BaseIdentityProvider) Test(org.junit.Test)

Aggregations

IdentityProvider (org.sonar.api.server.authentication.IdentityProvider)5 OAuth2IdentityProvider (org.sonar.api.server.authentication.OAuth2IdentityProvider)5 BaseIdentityProvider (org.sonar.api.server.authentication.BaseIdentityProvider)4 Test (org.junit.Test)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AuthenticationException (org.sonar.server.authentication.event.AuthenticationException)1