Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAK-50666 Samigo prevent opening links from SEB by default #13004

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3703,6 +3703,14 @@
# DEFAULT: https://safeexambrowser.org/download_en.html
# seb.download.link=

# S2U-21 Enable URL filtering for Safe Exam browser
# DEFAULT: false
# seb.URL.filter.enable=true

# S2U-21 List of URLs to filter for Safe Exam browser
# DEFAULT: [SERVER_URL]
# seb.URL.filter.rules=*.nightly.sakaiproject.org

#########################################
# MEMBERSHIP TOOL
#########################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand All @@ -32,18 +33,18 @@
import org.apache.commons.configuration2.io.FileHandler;
import org.apache.commons.configuration2.plist.XMLPropertyListConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.tool.assessment.shared.api.assessment.SecureDeliveryServiceAPI;
import org.sakaiproject.tool.assessment.util.HashingUtil;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Data
@NoArgsConstructor
@Slf4j
public class SebConfig {

Expand All @@ -69,6 +70,8 @@ public class SebConfig {
private Boolean showWifiControl;
private Boolean userConfirmQuit;

private static String URLFilterEnable;

// Keys in map of assessment metadata

// Not Needed in pList config
Expand Down Expand Up @@ -116,10 +119,26 @@ public class SebConfig {
private static final String USER_CONFIRM_QUIT_KEY = "quitURLConfirm";
private static final String QUIT_PASSWORD_KEY = "hashedQuitPassword";

private static final String URL_FILTER_ENABLE = "URLFilterEnable";
private static final String URL_FILTER_ENABLE_DEFAULT = "false";
private static final String URL_FILTER_ENABLE_PROPERTY = "seb.URL.filter.enable";
private static final String URL_FILTER_RULES = "URLFilterRules";
private static final String URL_FILTER_RULES_PROPERTY = "seb.URL.filter.rules";
private static final String ACTION = "action";
private static final String ACTIVE = "active";
private static final String EXPRESSION = "expression";
private static final String REGEX = "regex";

public static final String CONFIG_ENCODING = "UTF-8";

public enum ConfigMode { MANUAL, UPLOAD, CLIENT }

private ServerConfigurationService serverConfigurationService;

public SebConfig() {
this.serverConfigurationService = ComponentManager.get(ServerConfigurationService.class);
}

public static SebConfig of(HashMap<String, String> assessmentMetaDataMap) {
SebConfig newSebConfig = new SebConfig();

Expand Down Expand Up @@ -194,7 +213,7 @@ public String toJson() {
// keys will need to be sorted based in a case insensitive manner
TreeMap<String, Object> map = toMap().entrySet().stream()
.filter(entry -> entry.getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, TreeMap::new));
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)));
try {
// Write sorted hashmap to string in json format
return new ObjectMapper().writeValueAsString(map);
Expand Down Expand Up @@ -256,6 +275,22 @@ private HashMap<String, Object> toMap() {
map.putIfAbsent(SHOW_RELOAD_BUTTON_KEY, false);
map.putIfAbsent(SEB_SERVICE_IGNORE_KEY, false);

// URLFilterEnable
URLFilterEnable = serverConfigurationService.getString(URL_FILTER_ENABLE_PROPERTY, URL_FILTER_ENABLE_DEFAULT);
if (URLFilterEnable.equals("true")) {
map.put(URL_FILTER_ENABLE, true);

String urlFilterList = serverConfigurationService.getString(URL_FILTER_RULES_PROPERTY, serverConfigurationService.getServerUrl());
List<String> urls = Arrays.asList(urlFilterList.split(","));

List<Map<String, Object>> urlFilterRules = urls.stream()
.map(this::createURLFilterRule)
.map(this::sortMapByKey)
.collect(Collectors.toList());

map.put(URL_FILTER_RULES, urlFilterRules);
}

// Useful properties for demos, makes it possible to record or share the screen
// Commented, since it is disabling security features of SEB
//map.put("killExplorerShell", false);
Expand All @@ -264,4 +299,19 @@ private HashMap<String, Object> toMap() {
return map;
}

}
private Map<String, Object> createURLFilterRule(String expression) {
Map<String, Object> rule = new HashMap<>();
rule.put(ACTION, 1);
rule.put(ACTIVE, true);
rule.put(EXPRESSION, expression);
rule.put(REGEX, false);
return rule;
}

private Map<String, Object> sortMapByKey(Map<String, Object> map) {
return map.entrySet().stream()
.filter(entry -> entry.getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)));
}

}
Loading