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