SEBSERV-417 fixed SEB Restriction
This commit is contained in:
parent
c4dc211cb6
commit
9bf843e4fa
5 changed files with 49 additions and 5 deletions
|
@ -18,6 +18,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
|
||||
public interface MoodleAPIRestTemplate {
|
||||
|
||||
public enum MoodlePluginVersion {
|
||||
NONE,
|
||||
V1_0,
|
||||
V2_0,
|
||||
}
|
||||
|
||||
String URI_VAR_USER_NAME = "username";
|
||||
String URI_VAR_PASSWORD = "pwd";
|
||||
String URI_VAR_SERVICE = "service";
|
||||
|
@ -33,6 +39,8 @@ public interface MoodleAPIRestTemplate {
|
|||
|
||||
String getService();
|
||||
|
||||
MoodlePluginVersion getMoodlePluginVersion();
|
||||
|
||||
CharSequence getAccessToken();
|
||||
|
||||
void testAPIConnection(String... functions);
|
||||
|
|
|
@ -24,6 +24,8 @@ import java.util.Set;
|
|||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.moodle.plugin.MoodlePluginCourseRestriction;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.moodle.plugin.MoodlePluginFullIntegration;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
@ -237,6 +239,8 @@ public class MoodleRestTemplateFactoryImpl implements MoodleRestTemplateFactory
|
|||
private final Map<String, String> tokenReqURIVars;
|
||||
private final HttpEntity<?> tokenReqEntity = new HttpEntity<>(new LinkedMultiValueMap<>());
|
||||
|
||||
private MoodlePluginVersion moodlePluginVersion = null;
|
||||
|
||||
protected MoodleAPIRestTemplateImpl(
|
||||
final JSONMapper jsonMapper,
|
||||
final APITemplateDataSupplier apiTemplateDataSupplier,
|
||||
|
@ -266,6 +270,30 @@ public class MoodleRestTemplateFactoryImpl implements MoodleRestTemplateFactory
|
|||
return this.tokenReqURIVars.get(URI_VAR_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoodlePluginVersion getMoodlePluginVersion() {
|
||||
if (moodlePluginVersion == null) {
|
||||
try {
|
||||
final String apiInfo = this.callMoodleAPIFunction(REST_API_TEST_FUNCTION);
|
||||
final WebserviceInfo webserviceInfo = this.jsonMapper.readValue(
|
||||
apiInfo,
|
||||
WebserviceInfo.class);
|
||||
if (webserviceInfo.functions.containsKey(MoodlePluginCourseRestriction.RESTRICTION_SET_FUNCTION_NAME)) {
|
||||
if (webserviceInfo.functions.containsKey(MoodlePluginFullIntegration.FUNCTION_NAME_SEBSERVER_CONNECTION)) {
|
||||
this.moodlePluginVersion = MoodlePluginVersion.V2_0;
|
||||
} else {
|
||||
this.moodlePluginVersion = MoodlePluginVersion.V1_0;
|
||||
}
|
||||
} else {
|
||||
this.moodlePluginVersion = MoodlePluginVersion.NONE;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log.warn("Failed to verify MoodlePluginVersion. Error: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
return moodlePluginVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getAccessToken() {
|
||||
if (this.accessToken == null) {
|
||||
|
|
|
@ -132,8 +132,6 @@ public class MoodlePluginCourseRestriction implements SEBRestrictionAPI {
|
|||
|
||||
final ArrayList<String> beks = new ArrayList<>(sebRestrictionData.browserExamKeys);
|
||||
final ArrayList<String> configKeys = new ArrayList<>(sebRestrictionData.configKeys);
|
||||
final String quitLink = this.examConfigurationValueService.getQuitLink(exam.id);
|
||||
final String quitSecret = this.examConfigurationValueService.getQuitPassword(exam.id);
|
||||
String additionalBEK = sebRestrictionData.additionalProperties.get(SEBRestrictionService.ADDITIONAL_ATTR_ALTERNATIVE_SEB_BEK);
|
||||
if (additionalBEK == null) {
|
||||
additionalBEK = exam.getAdditionalAttribute(
|
||||
|
@ -147,8 +145,13 @@ public class MoodlePluginCourseRestriction implements SEBRestrictionAPI {
|
|||
final LinkedMultiValueMap<String, String> queryAttributes = new LinkedMultiValueMap<>();
|
||||
queryAttributes.put(ATTRIBUTE_CONFIG_KEYS, configKeys);
|
||||
queryAttributes.put(ATTRIBUTE_BROWSER_EXAM_KEYS, beks);
|
||||
queryAttributes.add(ATTRIBUTE_QUIT_URL, quitLink);
|
||||
queryAttributes.add(ATTRIBUTE_QUIT_SECRET, quitSecret);
|
||||
|
||||
if (restTemplate.getMoodlePluginVersion() == MoodleAPIRestTemplate.MoodlePluginVersion.V1_0) {
|
||||
final String quitLink = this.examConfigurationValueService.getQuitLink(exam.id);
|
||||
final String quitSecret = this.examConfigurationValueService.getQuitPassword(exam.id);
|
||||
queryAttributes.add(ATTRIBUTE_QUIT_URL, quitLink);
|
||||
queryAttributes.add(ATTRIBUTE_QUIT_SECRET, quitSecret);
|
||||
}
|
||||
|
||||
final String srJSON = restTemplate.callMoodleAPIFunction(
|
||||
RESTRICTION_SET_FUNCTION_NAME,
|
||||
|
|
|
@ -38,7 +38,7 @@ public class MoodlePluginFullIntegration implements FullLmsIntegrationAPI {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(MoodlePluginFullIntegration.class);
|
||||
|
||||
private static final String FUNCTION_NAME_SEBSERVER_CONNECTION = "quizaccess_sebserver_connection";
|
||||
public static final String FUNCTION_NAME_SEBSERVER_CONNECTION = "quizaccess_sebserver_connection";
|
||||
private static final String FUNCTION_NAME_SEBSERVER_CONNECTION_DELETE = "quizaccess_sebserver_connection_delete";
|
||||
private static final String FUNCTION_NAME_SET_EXAM_DATA = "quizaccess_sebserver_set_exam_data";
|
||||
private static final String ATTRIBUTE_CONNECTION = "connection";
|
||||
|
|
|
@ -114,6 +114,11 @@ public class MoodleMockupRestTemplateFactory implements MoodleRestTemplateFactor
|
|||
return "mockup-service";
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoodlePluginVersion getMoodlePluginVersion() {
|
||||
return MoodlePluginVersion.V1_0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getAccessToken() {
|
||||
return this.accessToken;
|
||||
|
|
Loading…
Reference in a new issue