SEBSERV-335 name changing and code cleanup

This commit is contained in:
anhefti 2022-12-07 10:34:37 +01:00
parent 6198f26a6f
commit ec6f12a703
9 changed files with 34 additions and 34 deletions

View file

@ -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";

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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,

View file

@ -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<Exam> 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.

View file

@ -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);

View file

@ -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);
}

View file

@ -222,7 +222,7 @@ public class ExamAdministrationController extends EntityController<Exam, Exam> {
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)

View file

@ -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,<br/>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=&nbsp;