From ec6f12a703dfc67f99bc98c7ff2820d21426f2ff Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 7 Dec 2022 10:34:37 +0100 Subject: [PATCH] SEBSERV-335 name changing and code cleanup --- .../seb/sebserver/gbl/model/exam/Exam.java | 4 ++-- .../institution/SecurityCheckResult.java | 12 +++++----- .../content/exam/ExamSignatureKeyForm.java | 8 +++---- .../servicelayer/dao/impl/ExamDAOImpl.java | 10 ++++----- .../servicelayer/exam/ExamAdminService.java | 4 ++-- .../exam/impl/ExamAdminServiceImpl.java | 4 ++-- .../impl/SecurityKeyServiceImpl.java | 22 +++++++++---------- .../api/ExamAdministrationController.java | 2 +- src/main/resources/messages.properties | 2 +- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Exam.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Exam.java index 2d3eaf96..40267bcc 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Exam.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Exam.java @@ -65,8 +65,8 @@ public final class Exam implements GrantEntity { /** This attribute name is used on exams to store the flag for indicating the signature key check */ public static final String ADDITIONAL_ATTR_SIGNATURE_KEY_CHECK_ENABLED = "SIGNATURE_KEY_CHECK_ENABLED"; - /** This attribute name is used to store the signature check grant threshold for statistical checks */ - public static final String ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD = "STATISTICAL_GRANT_COUNT_THRESHOLD"; + /** This attribute name is used to store the signature check grant threshold for numerical trust checks */ + public static final String ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD = "NUMERICAL_TRUST_THRESHOLD"; /** This attribute name is used to store the signature check encryption certificate is one is used */ public static final String ADDITIONAL_ATTR_SIGNATURE_KEY_CERT_ALIAS = "SIGNATURE_KEY_CERT_ALIAS"; diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/SecurityCheckResult.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/SecurityCheckResult.java index 0891e98c..56566af5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/SecurityCheckResult.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/SecurityCheckResult.java @@ -18,17 +18,17 @@ public class SecurityCheckResult { public final boolean globalGranted; public final boolean examGranted; - public final boolean statisticallyGranted; + public final boolean numericallyGranted; @JsonCreator public SecurityCheckResult( final boolean globalGranted, final boolean examGranted, - final boolean statisticallyGranted) { + final boolean numericallyGranted) { this.globalGranted = globalGranted; this.examGranted = examGranted; - this.statisticallyGranted = statisticallyGranted; + this.numericallyGranted = numericallyGranted; } public boolean isGlobalGranted() { @@ -39,12 +39,12 @@ public class SecurityCheckResult { return this.examGranted; } - public boolean isStatisticallyGranted() { - return this.statisticallyGranted; + public boolean isNumericallyGranted() { + return this.numericallyGranted; } public boolean hasAnyGrant() { - return this.globalGranted | this.examGranted | this.statisticallyGranted; + return this.globalGranted | this.examGranted | this.numericallyGranted; } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamSignatureKeyForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamSignatureKeyForm.java index 89832d1e..41152596 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamSignatureKeyForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamSignatureKeyForm.java @@ -115,7 +115,7 @@ public class ExamSignatureKeyForm implements TemplateComposer { .getOrThrow(); final boolean signatureKeyCheckEnabled = BooleanUtils.toBoolean( exam.additionalAttributes.get(Exam.ADDITIONAL_ATTR_SIGNATURE_KEY_CHECK_ENABLED)); - final String ct = exam.additionalAttributes.get(Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD); + final String ct = exam.additionalAttributes.get(Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD); final Composite content = widgetFactory .defaultPageLayout(pageContext.getParent(), TILE); @@ -135,7 +135,7 @@ public class ExamSignatureKeyForm implements TemplateComposer { .withInputSpan(1)) .addField(FormBuilder.text( - Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD, + Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD, FORM_STAT_GRANT_THRESHOLD, (ct != null) ? ct : "2") .asNumber(number -> { @@ -279,7 +279,7 @@ public class ExamSignatureKeyForm implements TemplateComposer { private PageAction saveSettings(final PageAction action, final Form form) { final String enable = form.getFieldValue(Exam.ADDITIONAL_ATTR_SIGNATURE_KEY_CHECK_ENABLED); - final String threshold = form.getFieldValue(Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD); + final String threshold = form.getFieldValue(Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD); final EntityKey entityKey = action.getEntityKey(); this.pageService @@ -287,7 +287,7 @@ public class ExamSignatureKeyForm implements TemplateComposer { .getBuilder(SaveAppSignatureKeySettings.class) .withURIVariable(API.PARAM_PARENT_MODEL_ID, entityKey.modelId) .withFormParam(Exam.ADDITIONAL_ATTR_SIGNATURE_KEY_CHECK_ENABLED, enable) - .withFormParam(Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD, threshold) + .withFormParam(Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD, threshold) .call() .onError(error -> action.pageContext().notifySaveError(EntityType.EXAM, error)); return action; diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java index 0b594acb..34f7e00a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java @@ -68,7 +68,7 @@ public class ExamDAOImpl implements ExamDAO { private final ApplicationEventPublisher applicationEventPublisher; private final AdditionalAttributesDAO additionalAttributesDAO; private final boolean appSignatureKeyEnabled; - private final int appSignatureKeyThreshold; + private final int defaultNumericalTrustThreshold; public ExamDAOImpl( final ExamRecordMapper examRecordMapper, @@ -76,14 +76,14 @@ public class ExamDAOImpl implements ExamDAO { final ApplicationEventPublisher applicationEventPublisher, final AdditionalAttributesDAO additionalAttributesDAO, final @Value("${sebserver.webservice.api.admin.exam.app.signature.key.enabled:false}") boolean appSignatureKeyEnabled, - final @Value("${sebserver.webservice.api.admin.exam.app.signature.key.threshold:2}") int appSignatureKeyThreshold) { + final @Value("${sebserver.webservice.api.admin.exam.app.signature.key.numerical.threshold:2}") int defaultNumericalTrustThreshold) { this.examRecordMapper = examRecordMapper; this.examRecordDAO = examRecordDAO; this.applicationEventPublisher = applicationEventPublisher; this.additionalAttributesDAO = additionalAttributesDAO; this.appSignatureKeyEnabled = appSignatureKeyEnabled; - this.appSignatureKeyThreshold = appSignatureKeyThreshold; + this.defaultNumericalTrustThreshold = defaultNumericalTrustThreshold; } @Override @@ -776,8 +776,8 @@ public class ExamDAOImpl implements ExamDAO { this.additionalAttributesDAO.initAdditionalAttribute( EntityType.EXAM, examId, - Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD, - String.valueOf(this.appSignatureKeyThreshold)); + Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD, + String.valueOf(this.defaultNumericalTrustThreshold)); final CharSequence salt = KeyGenerators.string().generateKey(); this.additionalAttributesDAO.initAdditionalAttribute( EntityType.EXAM, diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java index e7b020ce..7e6b2bba 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java @@ -49,13 +49,13 @@ public interface ExamAdminService { * @param institutionId The institution identifier * @param examId The exam identifier * @param enabled The enabled setting that indicates if the security key check is enabled or not - * @param statThreshold the statistical SEB client connection number grant threshold + * @param numThreshold the numerical SEB client connection number grant threshold * @return Result refer to the exam with the new settings (additional attributes) or to an error when happened */ Result saveSecurityKeySettings( Long institutionId, Long examId, Boolean enabled, - Integer statThreshold); + Integer numThreshold); /** Applies all additional SEB restriction attributes that are defined by the * type of the LMS of a given Exam to this given Exam. diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamAdminServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamAdminServiceImpl.java index 9f559f26..7fec8634 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamAdminServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamAdminServiceImpl.java @@ -102,10 +102,10 @@ public class ExamAdminServiceImpl implements ExamAdminService { this.additionalAttributesDAO.saveAdditionalAttribute( EntityType.EXAM, examId, - Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD, + Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD, String.valueOf(statThreshold)) .onError(error -> log - .error("Failed to store ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD: ", error)); + .error("Failed to store ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD: ", error)); } this.examDAO.setModified(examId); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/institution/impl/SecurityKeyServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/institution/impl/SecurityKeyServiceImpl.java index 357d3bbb..e7c348d1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/institution/impl/SecurityKeyServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/institution/impl/SecurityKeyServiceImpl.java @@ -267,7 +267,7 @@ public class SecurityKeyServiceImpl implements SecurityKeyService { .collect(Collectors.toList()); if (matches == null || matches.isEmpty()) { - return statisticalCheck(examId, hashedSignatureKey); + return numericalCheck(examId, hashedSignatureKey); } else { return new SecurityCheckResult( matches.stream() @@ -283,22 +283,22 @@ public class SecurityKeyServiceImpl implements SecurityKeyService { }); } - private SecurityCheckResult statisticalCheck( + private SecurityCheckResult numericalCheck( final Long examId, final String hashedSignature) { if (log.isDebugEnabled()) { - log.debug("Apply statistical security check update for exam {}", examId); + log.debug("Apply numerical security check update for exam {}", examId); } - // if there is no exam known yet, no statistical check can be applied + // if there is no exam known yet, no numerical check can be applied if (examId == null) { return SecurityCheckResult.NO_GRANT; } try { - final int statisticalGrantThreshold = getStatisticalGrantThreshold(examId); + final int numericalTrustThreshold = getNumericalTrustThreshold(examId); final Long matches = this.clientConnectionDAO .countSignatureHashes(examId, hashedSignature) .getOr(0L); @@ -306,27 +306,27 @@ public class SecurityKeyServiceImpl implements SecurityKeyService { if (matches <= 0) { return SecurityCheckResult.NO_GRANT; } else { - return new SecurityCheckResult(false, false, matches > statisticalGrantThreshold); + return new SecurityCheckResult(false, false, matches > numericalTrustThreshold); } } catch (final Exception e) { - log.error("Unexpected error while trying to apply statistical app signature key check: ", e); + log.error("Unexpected error while trying to apply numerical app signature key check: ", e); return SecurityCheckResult.NO_GRANT; } } - private int getStatisticalGrantThreshold(final Long examId) { + private int getNumericalTrustThreshold(final Long examId) { // try to ger from running exam. final Exam runningExam = this.examSessionCacheService.getRunningExam(examId); if (runningExam != null) { final String threshold = runningExam.getAdditionalAttribute( - Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD); + Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD); if (StringUtils.isNotBlank(threshold)) { try { return Integer.parseInt(threshold); } catch (final Exception e) { - log.warn("Failed to parse STATISTICAL_GRANT_COUNT_THRESHOLD"); + log.warn("Failed to parse numerical trust threshold"); } } } @@ -336,7 +336,7 @@ public class SecurityKeyServiceImpl implements SecurityKeyService { .getAdditionalAttribute( EntityType.EXAM, examId, - Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD) + Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD) .map(attr -> Integer.valueOf(attr.getValue())) .getOr(1); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java index f1fffd18..a2ad89fd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java @@ -222,7 +222,7 @@ public class ExamAdministrationController extends EntityController { required = true, defaultValue = UserService.USERS_INSTITUTION_AS_DEFAULT) final Long institutionId, @RequestParam(Exam.ADDITIONAL_ATTR_SIGNATURE_KEY_CHECK_ENABLED) final Boolean enableKeyCheck, - @RequestParam(Exam.ADDITIONAL_ATTR_STATISTICAL_GRANT_COUNT_THRESHOLD) final Integer threshold) { + @RequestParam(Exam.ADDITIONAL_ATTR_NUMERICAL_TRUST_THRESHOLD) final Integer threshold) { this.examDAO.byPK(examId) .flatMap(this::checkReadAccess) diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 3db5d0d0..8180d282 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -803,7 +803,7 @@ sebserver.exam.signaturekey.action.deleteGrant=Delete Security Grant sebserver.exam.signaturekey.title=App Signature Key Overview sebserver.exam.signaturekey.form.enabled=Enable App Signature Key Check sebserver.exam.signaturekey.form.enabled.tooltip=Enable the App Signature Key Check for this exam. If disabled no check will be applied -sebserver.exam.signaturekey.form.grant.threshold=Threshold of Statistical Check +sebserver.exam.signaturekey.form.grant.threshold=Numerical Trust Threshold sebserver.exam.signaturekey.form.grant.threshold.tooltip=If there is no explicit grant registered for a given App Signature Key,
a given key will be considered valid if more then the given number of connected SEB clients has the same key. sebserver.exam.signaturekey.keylist.actions=