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