Search in sources :

Example 1 with UserSession

use of org.sonar.server.user.UserSession in project sonarqube by SonarSource.

the class UserTokensWsTest method setUp.

@Before
public void setUp() {
    UserSession userSession = mock(UserSession.class);
    DbClient dbClient = mock(DbClient.class);
    System2 system = mock(System2.class);
    TokenGenerator tokenGenerator = mock(TokenGenerator.class);
    ws = new WsTester(new UserTokensWs(new GenerateAction(dbClient, userSession, system, tokenGenerator), new RevokeAction(dbClient, userSession), new SearchAction(dbClient, userSession)));
}
Also used : TokenGenerator(org.sonar.server.usertoken.TokenGenerator) DbClient(org.sonar.db.DbClient) WsTester(org.sonar.server.ws.WsTester) UserSession(org.sonar.server.user.UserSession) System2(org.sonar.api.utils.System2) Before(org.junit.Before)

Example 2 with UserSession

use of org.sonar.server.user.UserSession in project sonarqube by SonarSource.

the class CustomMeasuresWsTest method setUp.

@Before
public void setUp() {
    DbClient dbClient = mock(DbClient.class);
    UserSession userSession = mock(UserSession.class);
    ws = new WsTester(new CustomMeasuresWs(new DeleteAction(dbClient, userSession), new CreateAction(dbClient, userSession, System2.INSTANCE, mock(CustomMeasureValidator.class), mock(CustomMeasureJsonWriter.class), mock(ComponentFinder.class)), new UpdateAction(dbClient, userSession, System2.INSTANCE, mock(CustomMeasureValidator.class), mock(CustomMeasureJsonWriter.class))));
}
Also used : DbClient(org.sonar.db.DbClient) WsTester(org.sonar.server.ws.WsTester) UserSession(org.sonar.server.user.UserSession) Before(org.junit.Before)

Example 3 with UserSession

use of org.sonar.server.user.UserSession in project sonarqube by SonarSource.

the class UserSessionInitializerTest method assertPathIsNotIgnored.

private void assertPathIsNotIgnored(String path) {
    when(request.getRequestURI()).thenReturn(path);
    UserSession session = new MockUserSession("foo");
    when(authenticator.authenticate(request, response)).thenReturn(session);
    assertThat(underTest.initUserSession(request, response)).isTrue();
    verify(threadLocalSession).set(session);
    reset(threadLocalSession, authenticator);
}
Also used : MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) ThreadLocalUserSession(org.sonar.server.user.ThreadLocalUserSession) MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) UserSession(org.sonar.server.user.UserSession)

Example 4 with UserSession

use of org.sonar.server.user.UserSession in project sonarqube by SonarSource.

the class RequestAuthenticatorImplTest method return_empty_if_not_authenticated.

@Test
public void return_empty_if_not_authenticated() {
    when(jwtHttpHandler.validateToken(request, response)).thenReturn(Optional.empty());
    when(httpHeadersAuthentication.authenticate(request, response)).thenReturn(Optional.empty());
    when(basicAuthentication.authenticate(request)).thenReturn(Optional.empty());
    UserSession session = underTest.authenticate(request, response);
    assertThat(session.isLoggedIn()).isFalse();
    assertThat(session.getUuid()).isNull();
    verify(response, never()).setStatus(anyInt());
}
Also used : MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) UserSession(org.sonar.server.user.UserSession) Test(org.junit.Test)

Example 5 with UserSession

use of org.sonar.server.user.UserSession in project sonarqube by SonarSource.

the class UserSessionInitializer method loadUserSession.

private void loadUserSession(HttpServletRequest request, HttpServletResponse response, boolean urlSupportsSystemPasscode) {
    UserSession session = requestAuthenticator.authenticate(request, response);
    if (!session.isLoggedIn() && !urlSupportsSystemPasscode && config.getBoolean(CORE_FORCE_AUTHENTICATION_PROPERTY).orElse(CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE)) {
        // authentication is required
        throw AuthenticationException.newBuilder().setSource(Source.local(AuthenticationEvent.Method.BASIC)).setMessage("User must be authenticated").build();
    }
    threadLocalSession.set(session);
    request.setAttribute(ACCESS_LOG_LOGIN, defaultString(session.getLogin(), "-"));
}
Also used : ThreadLocalUserSession(org.sonar.server.user.ThreadLocalUserSession) UserSession(org.sonar.server.user.UserSession)

Aggregations

UserSession (org.sonar.server.user.UserSession)11 AnonymousMockUserSession (org.sonar.server.tester.AnonymousMockUserSession)5 MockUserSession (org.sonar.server.tester.MockUserSession)5 Before (org.junit.Before)4 DbClient (org.sonar.db.DbClient)4 ThreadLocalUserSession (org.sonar.server.user.ThreadLocalUserSession)4 WsTester (org.sonar.server.ws.WsTester)4 Test (org.junit.Test)3 System2 (org.sonar.api.utils.System2)1 UserDto (org.sonar.db.user.UserDto)1 TemplateGroupsAction (org.sonar.server.permission.ws.template.TemplateGroupsAction)1 TemplateUsersAction (org.sonar.server.permission.ws.template.TemplateUsersAction)1 TokenGenerator (org.sonar.server.usertoken.TokenGenerator)1