Skip to content

Commit

Permalink
Merge branch 'develop' into feature/programming-exercises/document-lo…
Browse files Browse the repository at this point in the history
…calvc-jenkins
  • Loading branch information
BaumiCoder committed Sep 16, 2024
2 parents 57097a7 + 8ff8197 commit d579a60
Show file tree
Hide file tree
Showing 29 changed files with 714 additions and 101 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ spotless {
"**/src/main/resources/templates/**",
"/docker/**",
"checked-out-repos/**",
"**/src/main/java/org/eclipse/**"
"**/src/main/java/org/eclipse/**",
"supporting_scripts/**"
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions docs/user/communication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This video provides an overview of the course-wide channel types existing in a c

.. raw:: html

<iframe src="https://live.rbg.tum.de/w/artemisintro/42164?video_only=1&t=0" allowfullscreen="1" frameborder="0" width="600" height="450">
<iframe src="https://live.rbg.tum.de/w/artemisintro/47622?video_only=1&t=0" allowfullscreen="1" frameborder="0" width="600" height="350">
Watch this video on TUM-Live.
</iframe>

Expand Down Expand Up @@ -85,7 +85,7 @@ This video shows how link previews work in Artemis:

.. raw:: html

<iframe src="https://live.rbg.tum.de/w/artemisintro/40580?video_only=1&t=0" allowfullscreen="1" frameborder="0" width="600" height="350">
<iframe src="https://live.rbg.tum.de/w/artemisintro/47626?video_only=1&t=0" allowfullscreen="1" frameborder="0" width="600" height="350">
Watch this video on TUM-Live.
</iframe>

Expand Down Expand Up @@ -198,7 +198,7 @@ Reference Lecture Unit Slides

.. raw:: html

<iframe src="https://live.rbg.tum.de/w/artemisintro/40579?video_only=1&t=0" allowfullscreen="1" frameborder="0" width="600" height="350">
<iframe src="https://live.rbg.tum.de/w/artemisintro/47625?video_only=1&t=0" allowfullscreen="1" frameborder="0" width="600" height="350">
Watch this video on TUM-Live.
</iframe>

Expand Down Expand Up @@ -260,7 +260,7 @@ The video below provides a demonstration for the creation of a course-wide chann

.. raw:: html

<iframe src="https://live.rbg.tum.de/w/artemisintro/42163?video_only=1&t=0" allowfullscreen="1" frameborder="0" width="600" height="450">
<iframe src="https://live.rbg.tum.de/w/artemisintro/47623?video_only=1&t=0" allowfullscreen="1" frameborder="0" width="600" height="350">
Watch this video on TUM-Live.
</iframe>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ public final class Constants {
*/
public static final String PROFILE_LTI = "lti";

/**
* The name of the Spring profile used for activating SAML2 in Artemis, see {@link de.tum.cit.aet.artemis.core.service.connectors.SAML2Service}.
*/
public static final String PROFILE_SAML2 = "saml2";

public static final String PROFILE_SCHEDULING = "scheduling";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* Describes the security configuration for SAML2.
*/
@Configuration
@Profile("saml2")
@Profile(Constants.PROFILE_SAML2)
public class SAML2Configuration {

private static final Logger log = LoggerFactory.getLogger(SAML2Configuration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@Profile(PROFILE_CORE)
@Component
@ConfigurationProperties("saml2")
@ConfigurationProperties(Constants.PROFILE_SAML2)
public class SAML2Properties {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.audit.AuditEvent;
import org.springframework.boot.actuate.audit.AuditEventRepository;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.core.config.Constants;
import de.tum.cit.aet.artemis.core.config.audit.AuditEventConverter;
import de.tum.cit.aet.artemis.core.domain.PersistentAuditEvent;

Expand All @@ -24,6 +28,10 @@
@Repository
public class CustomAuditEventRepository implements AuditEventRepository {

private final boolean isSaml2Active;

private static final String AUTHENTICATION_SUCCESS = "AUTHENTICATION_SUCCESS";

private static final String AUTHORIZATION_FAILURE = "AUTHORIZATION_FAILURE";

/**
Expand All @@ -37,9 +45,10 @@ public class CustomAuditEventRepository implements AuditEventRepository {

private static final Logger log = LoggerFactory.getLogger(CustomAuditEventRepository.class);

public CustomAuditEventRepository(PersistenceAuditEventRepository persistenceAuditEventRepository, AuditEventConverter auditEventConverter) {
public CustomAuditEventRepository(Environment environment, PersistenceAuditEventRepository persistenceAuditEventRepository, AuditEventConverter auditEventConverter) {
this.persistenceAuditEventRepository = persistenceAuditEventRepository;
this.auditEventConverter = auditEventConverter;
this.isSaml2Active = Set.of(environment.getActiveProfiles()).contains(Constants.PROFILE_SAML2);
}

@Override
Expand All @@ -51,6 +60,11 @@ public List<AuditEvent> find(String principal, Instant after, String type) {
@Override
public void add(AuditEvent event) {
if (!AUTHORIZATION_FAILURE.equals(event.getType())) {
if (isSaml2Active && AUTHENTICATION_SUCCESS.equals(event.getType()) && SecurityContextHolder.getContext().getAuthentication() == null) {
// If authentication is null, Auth is success, and SAML2 profile is active => SAML2 authentication is running.
// Logging is handled manually.
return;
}

PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
persistentAuditEvent.setPrincipal(event.getPrincipal());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package de.tum.cit.aet.artemis.core.service;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_SCHEDULING;

import java.util.Arrays;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;

@Service
@Profile(PROFILE_SCHEDULING)
public class TelemetrySendingService {

private static final Logger log = LoggerFactory.getLogger(TelemetrySendingService.class);

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public record TelemetryData(String version, String serverUrl, String operator, String contact, List<String> profiles, String adminName) {
}

private final Environment env;

private final RestTemplate restTemplate;

public TelemetrySendingService(Environment env, RestTemplate restTemplate) {
this.env = env;
this.restTemplate = restTemplate;
}

@Value("${artemis.version}")
private String version;

@Value("${server.url}")
private String serverUrl;

@Value("${info.operatorName}")
private String operator;

@Value("${info.operatorAdminName}")
private String operatorAdminName;

@Value("${info.contact}")
private String contact;

@Value("${artemis.telemetry.sendAdminDetails}")
private boolean sendAdminDetails;

@Value("${artemis.telemetry.destination}")
private String destination;

/**
* Assembles the telemetry data, and sends it to the external telemetry server.
*
* @throws Exception if the writing the telemetry data to a json format fails, or the connection to the telemetry server fails
*/
@Async
public void sendTelemetryByPostRequest() throws Exception {
List<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
TelemetryData telemetryData;
if (sendAdminDetails) {
telemetryData = new TelemetryData(version, serverUrl, operator, contact, activeProfiles, operatorAdminName);
}
else {
telemetryData = new TelemetryData(version, serverUrl, operator, null, activeProfiles, null);
}

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter();

var telemetryJson = objectWriter.writeValueAsString(telemetryData);
HttpEntity<String> requestEntity = new HttpEntity<>(telemetryJson, headers);
var response = restTemplate.postForEntity(destination + "/api/telemetry", requestEntity, String.class);
log.info("Successfully sent telemetry data. {}", response.getBody());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,35 @@

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_SCHEDULING;

import java.util.Arrays;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;

@Service
@Profile(PROFILE_SCHEDULING)
public class TelemetryService {

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public record TelemetryData(String version, String serverUrl, String operator, String contact, List<String> profiles, String adminName) {
}

private static final Logger log = LoggerFactory.getLogger(TelemetryService.class);

private final Environment env;

private final RestTemplate restTemplate;

private final ProfileService profileService;

private final TelemetrySendingService telemetrySendingService;

@Value("${artemis.telemetry.enabled}")
public boolean useTelemetry;

@Value("${artemis.telemetry.sendAdminDetails}")
private boolean sendAdminDetails;

@Value("${artemis.telemetry.destination}")
private String destination;

@Value("${artemis.version}")
private String version;

@Value("${server.url}")
private String serverUrl;

@Value("${info.operatorName}")
private String operator;

@Value("${info.operatorAdminName}")
private String operatorAdminName;

@Value("${info.contact}")
private String contact;

public TelemetryService(Environment env, RestTemplate restTemplate, ProfileService profileService) {
this.env = env;
this.restTemplate = restTemplate;
public TelemetryService(ProfileService profileService, TelemetrySendingService telemetrySendingService) {
this.profileService = profileService;
this.telemetrySendingService = telemetrySendingService;
}

/**
Expand All @@ -82,39 +46,13 @@ public void sendTelemetry() {

log.info("Sending telemetry information");
try {
sendTelemetryByPostRequest();
telemetrySendingService.sendTelemetryByPostRequest();
}
catch (JsonProcessingException e) {
log.warn("JsonProcessingException in sendTelemetry.", e);
}
catch (Exception e) {
log.warn("Exception in sendTelemetry, with dst URI: {}", destination, e);
}

}

/**
* Assembles the telemetry data, and sends it to the external telemetry server.
*
* @throws Exception if the writing the telemetry data to a json format fails, or the connection to the telemetry server fails
*/
public void sendTelemetryByPostRequest() throws Exception {
List<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
TelemetryData telemetryData;
if (sendAdminDetails) {
telemetryData = new TelemetryData(version, serverUrl, operator, contact, activeProfiles, operatorAdminName);
}
else {
telemetryData = new TelemetryData(version, serverUrl, operator, null, activeProfiles, null);
}

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter();

var telemetryJson = objectWriter.writeValueAsString(telemetryData);
HttpEntity<String> requestEntity = new HttpEntity<>(telemetryJson, headers);
var response = restTemplate.postForEntity(destination + "/api/telemetry", requestEntity, String.class);
log.info("Successfully sent telemetry data. {}", response.getBody());
}
}
Loading

0 comments on commit d579a60

Please sign in to comment.