SEBSERV-351 added quitSecret decryption

This commit is contained in:
anhefti 2022-10-25 08:45:03 +02:00
parent bb0c834676
commit 2af314b135
3 changed files with 23 additions and 5 deletions

View file

@ -46,6 +46,7 @@ import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult;
import ch.ethz.seb.sebserver.gbl.model.user.ExamineeAccountDetails; import ch.ethz.seb.sebserver.gbl.model.user.ExamineeAccountDetails;
import ch.ethz.seb.sebserver.gbl.util.Cryptor;
import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
@ -73,6 +74,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
private final ClientCredentialService clientCredentialService; private final ClientCredentialService clientCredentialService;
private final APITemplateDataSupplier apiTemplateDataSupplier; private final APITemplateDataSupplier apiTemplateDataSupplier;
private final ExamConfigurationValueService examConfigurationValueService; private final ExamConfigurationValueService examConfigurationValueService;
private final Cryptor cryptor;
private final Long lmsSetupId; private final Long lmsSetupId;
private OlatLmsRestTemplate cachedRestTemplate; private OlatLmsRestTemplate cachedRestTemplate;
@ -82,6 +84,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
final ClientCredentialService clientCredentialService, final ClientCredentialService clientCredentialService,
final APITemplateDataSupplier apiTemplateDataSupplier, final APITemplateDataSupplier apiTemplateDataSupplier,
final ExamConfigurationValueService examConfigurationValueService, final ExamConfigurationValueService examConfigurationValueService,
final Cryptor cryptor,
final CacheManager cacheManager) { final CacheManager cacheManager) {
super(cacheManager); super(cacheManager);
@ -90,6 +93,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
this.clientCredentialService = clientCredentialService; this.clientCredentialService = clientCredentialService;
this.apiTemplateDataSupplier = apiTemplateDataSupplier; this.apiTemplateDataSupplier = apiTemplateDataSupplier;
this.examConfigurationValueService = examConfigurationValueService; this.examConfigurationValueService = examConfigurationValueService;
this.cryptor = cryptor;
this.lmsSetupId = apiTemplateDataSupplier.getLmsSetup().id; this.lmsSetupId = apiTemplateDataSupplier.getLmsSetup().id;
} }
@ -471,7 +475,16 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
} }
if (StringUtils.isNotEmpty(quitSecret)) { if (StringUtils.isNotEmpty(quitSecret)) {
sebRestrictionData.additionalProperties.put(ADDITIONAL_ATTR_QUIT_SECRET, quitSecret); try {
final String decryptedSecret = this.cryptor
.encrypt(quitSecret)
.getOrThrow()
.toString();
sebRestrictionData.additionalProperties.put(ADDITIONAL_ATTR_QUIT_SECRET, decryptedSecret);
} catch (final Exception e) {
log.error("Failed to decrypt quitSecret: ", e);
}
} }
} catch (final Exception e) { } catch (final Exception e) {

View file

@ -18,6 +18,7 @@ import ch.ethz.seb.sebserver.gbl.async.AsyncService;
import ch.ethz.seb.sebserver.gbl.client.ClientCredentialService; import ch.ethz.seb.sebserver.gbl.client.ClientCredentialService;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
import ch.ethz.seb.sebserver.gbl.util.Cryptor;
import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamConfigurationValueService; import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamConfigurationValueService;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.APITemplateDataSupplier; import ch.ethz.seb.sebserver.webservice.servicelayer.lms.APITemplateDataSupplier;
@ -43,6 +44,7 @@ public class OlatLmsAPITemplateFactory implements LmsAPITemplateFactory {
private final AsyncService asyncService; private final AsyncService asyncService;
private final Environment environment; private final Environment environment;
private final CacheManager cacheManager; private final CacheManager cacheManager;
private final Cryptor cryptor;
public OlatLmsAPITemplateFactory( public OlatLmsAPITemplateFactory(
final ClientHttpRequestFactoryService clientHttpRequestFactoryService, final ClientHttpRequestFactoryService clientHttpRequestFactoryService,
@ -50,7 +52,8 @@ public class OlatLmsAPITemplateFactory implements LmsAPITemplateFactory {
final ExamConfigurationValueService examConfigurationValueService, final ExamConfigurationValueService examConfigurationValueService,
final AsyncService asyncService, final AsyncService asyncService,
final Environment environment, final Environment environment,
final CacheManager cacheManager) { final CacheManager cacheManager,
final Cryptor cryptor) {
this.clientHttpRequestFactoryService = clientHttpRequestFactoryService; this.clientHttpRequestFactoryService = clientHttpRequestFactoryService;
this.clientCredentialService = clientCredentialService; this.clientCredentialService = clientCredentialService;
@ -58,6 +61,7 @@ public class OlatLmsAPITemplateFactory implements LmsAPITemplateFactory {
this.asyncService = asyncService; this.asyncService = asyncService;
this.environment = environment; this.environment = environment;
this.cacheManager = cacheManager; this.cacheManager = cacheManager;
this.cryptor = cryptor;
} }
@Override @Override
@ -73,6 +77,7 @@ public class OlatLmsAPITemplateFactory implements LmsAPITemplateFactory {
this.clientCredentialService, this.clientCredentialService,
apiTemplateDataSupplier, apiTemplateDataSupplier,
this.examConfigurationValueService, this.examConfigurationValueService,
this.cryptor,
this.cacheManager); this.cacheManager);
return new LmsAPITemplateAdapter( return new LmsAPITemplateAdapter(
this.asyncService, this.asyncService,

View file

@ -62,7 +62,7 @@ public final class OlatLmsData {
* "browserExamKeys": [ "1" ], * "browserExamKeys": [ "1" ],
* "configKeys": null, * "configKeys": null,
* "quitLink": "<the quit link from Exam Configuration>", * "quitLink": "<the quit link from Exam Configuration>",
* "quitSecret": "<the quit password from Exam Configuration (base64 encoded)>", * "quitSecret": "<the quit password from Exam Configuration>"
* "key": 8028160 * "key": 8028160
* } * }
*/ */
@ -79,9 +79,9 @@ public final class OlatLmsData {
* OLAT API example: * OLAT API example:
* { * {
* "configKeys": ["a", "b"], * "configKeys": ["a", "b"],
* "browserExamKeys": ["1", "2"] * "browserExamKeys": ["1", "2"],
* "quitLink": "<the quit link from Exam Configuration>", * "quitLink": "<the quit link from Exam Configuration>",
* "quitSecret": "<the quit password from Exam Configuration (base64 encoded)>", * "quitSecret": "<the quit password from Exam Configuration>"
* } * }
*/ */
public List<String> browserExamKeys; public List<String> browserExamKeys;