Search in sources :

Example 6 with UserSession

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

the class MetricsWsTest method setUp.

@Before
public void setUp() {
    DbClient dbClient = mock(DbClient.class);
    UserSession userSession = mock(UserSession.class);
    ws = new WsTester(new MetricsWs(new SearchAction(dbClient), new CreateAction(dbClient, userSession), new UpdateAction(dbClient, userSession), new DeleteAction(dbClient, userSession), new TypesAction(), new DomainsAction(dbClient)));
}
Also used : DbClient(org.sonar.db.DbClient) WsTester(org.sonar.server.ws.WsTester) UserSession(org.sonar.server.user.UserSession) Before(org.junit.Before)

Example 7 with UserSession

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

the class PermissionsWsTest method setUp.

@Before
public void setUp() {
    DbClient dbClient = mock(DbClient.class);
    UserSession userSession = mock(UserSession.class);
    PermissionWsSupport permissionWsSupport = mock(PermissionWsSupport.class);
    ws = new WsTester(new PermissionsWs(new TemplateUsersAction(dbClient, userSession, permissionWsSupport), new TemplateGroupsAction(dbClient, userSession, permissionWsSupport)));
}
Also used : DbClient(org.sonar.db.DbClient) WsTester(org.sonar.server.ws.WsTester) UserSession(org.sonar.server.user.UserSession) TemplateUsersAction(org.sonar.server.permission.ws.template.TemplateUsersAction) TemplateGroupsAction(org.sonar.server.permission.ws.template.TemplateGroupsAction) Before(org.junit.Before)

Example 8 with UserSession

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

the class UserSessionInitializer method setUserSession.

private void setUserSession(HttpServletRequest request, HttpServletResponse response) {
    Optional<UserDto> user = authenticate(request, response);
    if (user.isPresent()) {
        UserSession session = userSessionFactory.create(user.get());
        threadLocalSession.set(session);
        request.setAttribute(ACCESS_LOG_LOGIN, session.getLogin());
    } else {
        if (settings.getBoolean(CORE_FORCE_AUTHENTICATION_PROPERTY)) {
            throw AuthenticationException.newBuilder().setSource(Source.local(Method.BASIC)).setMessage("User must be authenticated").build();
        }
        threadLocalSession.set(userSessionFactory.createAnonymous());
        request.setAttribute(ACCESS_LOG_LOGIN, "-");
    }
}
Also used : UserDto(org.sonar.db.user.UserDto) ThreadLocalUserSession(org.sonar.server.user.ThreadLocalUserSession) UserSession(org.sonar.server.user.UserSession)

Example 9 with UserSession

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

the class UserSessionInitializerTest method assertPathIsIgnoredWithAnonymousAccess.

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

Example 10 with UserSession

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

the class RequestAuthenticatorImplTest method delegate_to_CustomAuthentication.

@Test
public void delegate_to_CustomAuthentication() {
    when(customAuthentication1.authenticate(request, response)).thenReturn(Optional.of(new MockUserSession("foo")));
    UserSession session = underTest.authenticate(request, response);
    assertThat(session.getLogin()).isEqualTo("foo");
}
Also used : MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) UserSession(org.sonar.server.user.UserSession) Test(org.junit.Test)

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