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)));
}
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))));
}
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);
}
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());
}
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(), "-"));
}
Aggregations