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

Fix AUP signature validity #834

Merged
merged 8 commits into from
Aug 29, 2024
Merged
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 @@ -32,7 +32,11 @@ public IamAup entityFromDto(AupDTO dto) {
aup.setSignatureValidityInDays(dto.getSignatureValidityInDays());
aup.setUrl(dto.getUrl());
aup.setText(dto.getText());
aup.setAupRemindersInDays(dto.getAupRemindersInDays());
if (dto.getAupRemindersInDays() == null) {
aup.setAupRemindersInDays("");
} else {
aup.setAupRemindersInDays(dto.getAupRemindersInDays());
}
return aup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class AupRemindersAndSignatureValidator implements ConstraintValidator<AupRemindersAndSignature, AupDTO> {
public class AupRemindersAndSignatureValidator
implements ConstraintValidator<AupRemindersAndSignature, AupDTO> {

@Override
public boolean isValid(AupDTO value, ConstraintValidatorContext context) {
Expand All @@ -50,11 +51,22 @@ public boolean isValid(AupDTO value, ConstraintValidatorContext context) {
return false;
}

if (aupRemindersInDays == null || aupRemindersInDays.isEmpty()) {
if (signatureValidityInDays == 0) {
if (aupRemindersInDays != null && !aupRemindersInDays.isEmpty()) {
context.disableDefaultConstraintViolation();
context
.buildConstraintViolationWithTemplate(
"Invalid AUP: aupRemindersInDays cannot be set if signatureValidityInDays is 0")
.addConstraintViolation();
return false;
}
return true;
}

if (aupRemindersInDays == null) {
context.disableDefaultConstraintViolation();
context
.buildConstraintViolationWithTemplate(
"Invalid AUP: aupRemindersInDays cannot be empty or null")
context.buildConstraintViolationWithTemplate(
"Invalid AUP: aupRemindersInDays must be set when signatureValidityInDays is greater than 0")
.addConstraintViolation();
return false;
}
Expand Down Expand Up @@ -87,15 +99,18 @@ public boolean isValid(AupDTO value, ConstraintValidatorContext context) {
if (uniqueNumbers.size() != numbers.size()) {
context.disableDefaultConstraintViolation();
context
.buildConstraintViolationWithTemplate("Invalid AUP: duplicate values for reminders are not allowed")
.buildConstraintViolationWithTemplate(
"Invalid AUP: duplicate values for reminders are not allowed")
.addConstraintViolation();
return false;
}

return true;
} catch (NumberFormatException e) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("Invalid AUP: non-integer value found")
context
.buildConstraintViolationWithTemplate(
"Invalid AUP: non-integer value found for aupRemindersInDays")
.addConstraintViolation();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h1>
If set to zero, the AUP signature will be asked only at registration time.
</span>
</div>
<div class="form-group">
<div class="form-group" ng-if="$ctrl.aup.data.signatureValidityInDays > 0">
<label>AUP reminders (in days)</label>
<p class="aup-text">
{{$ctrl.aup.data.aupRemindersInDays}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
self.doSaveAup = function() {
self.error = undefined;
self.enabled = false;
if(self.aupVal.signatureValidityInDays == 0 || !self.aupVal.aupRemindersInDays) {
self.aupVal.aupRemindersInDays = "";
}
AupService.updateAup(self.aupVal)
.then(function(res) {
$uibModalInstance.close('AUP updated succesfully');
Expand All @@ -106,7 +109,7 @@
self.aupVal = {
url: "",
signatureValidityInDays: 0,
aupRemindersInDays: "30,15,1"
aupRemindersInDays: ""
};
};

Expand All @@ -115,6 +118,9 @@
self.doCreateAup = function() {
self.error = undefined;
self.enabled = false;
if(self.aupVal.signatureValidityInDays == 0 || !self.aupVal.aupRemindersInDays) {
self.aupVal.aupRemindersInDays = "";
}
AupService.createAup(self.aupVal)
.then(function(res) {
$uibModalInstance.close('AUP created succesfully');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ <h3 class="modal-title">
</div>
<div class="modal-body">
<form name="createAup">
<div class="form-group" ng-class="{'has-error': $ctrl.error || createAup.url.$dirty && !createAup.url.$valid}">
<div class="form-group has-error" ng-if="$ctrl.error">
<span class="help-block">
{{ $ctrl.error }}
</span>
</div>
<div class="form-group">
<label>Acceptable Usage Policy URL</label>
<input name="url" class="form-control" type="url" value="http://" ng-model="$ctrl.aupVal.url" required="true">
enricovianello marked this conversation as resolved.
Show resolved Hide resolved
<input name="url" class="form-control" value="http://" ng-model="$ctrl.aupVal.url" required="true">
<span class="help-block">
The URL above is presented to users at registration time or periodically
if the AUP is configured for periodic reacceptance
</span>
<span class="help-block" ng-if="createAup.url.$dirty && createAup.url.$error.required">
Please provide a valid URL for the AUP
</span>
<span class="help-block" ng-if="$ctrl.error">
{{ $ctrl.error }}
</span>
<div class="form-group has-error" ng-if="createAup.url.$dirty && createAup.url.$error.required">
<span class="help-block">
Please provide a valid URL for the AUP
</span>
</div>
</div>
<div class="form-group">
<label>AUP signature validity (in days)</label>
Expand All @@ -45,20 +49,22 @@ <h3 class="modal-title">
If set to zero, the AUP signature will be asked only at registration time.
</span>
</div>
<div class="form-group" ng-class="{'has-error': $ctrl.error || createAup.aupReminder.$dirty && !createAup.aupReminder.$valid}">
<div class="form-group" ng-if="$ctrl.aupVal.signatureValidityInDays > 0">
<label>AUP signature reminders (in days)</label>
<input name="aupReminder" class="form-control" type="text" ng-model="$ctrl.aupVal.aupRemindersInDays" placeholder="30,15,1" required="true">
<input name="aupReminder" class="form-control" type="text" ng-model="$ctrl.aupVal.aupRemindersInDays" placeholder="30,15,1" ng-required="$ctrl.aupVal.signatureValidityInDays > 0">
<span class="help-block">
Indicate a sequence of comma-separated numbers representing how many days before the AUP expiration reminder messages must be sent.
</span>
<span class="help-block" ng-if="createAup.aupReminder.$dirty && createAup.aupReminder.$error.required">
Required input
</span>
<div class="form-group has-error" ng-if="createAup.aupReminder.$dirty && createAup.aupReminder.$error.required">
<span class="help-block">
Required input
</span>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" id="modal-btn-confirm" ng-disabled="!$ctrl.aupVal.url || !$ctrl.aupVal.aupRemindersInDays || !$ctrl.enabled" ng-click="$ctrl.doCreateAup()">Create AUP</button>
<button class="btn btn-primary" type="button" id="modal-btn-confirm" ng-disabled="!$ctrl.enabled" ng-click="$ctrl.doCreateAup()">Create AUP</button>

<button class="btn btn-warning" type="button" id="modal-btn-reset" ng-click="$ctrl.reset()">Reset form</button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ <h3 class="modal-title">
</div>
<div class="modal-body">
<form name="createAup">
<div class="form-group" ng-class="{'has-error': $ctrl.error || createAup.url.$dirty && !createAup.url.$valid}">
<div class="form-group has-error" ng-if="$ctrl.error">
<span class="help-block">
{{ $ctrl.error }}
</span>
</div>
<div class="form-group">
<label>Acceptable Usage Policy URL</label>
<input name="url" class="form-control" type="url" value="http://" ng-model="$ctrl.aupVal.url"
enricovianello marked this conversation as resolved.
Show resolved Hide resolved
<input name="url" class="form-control" value="http://" ng-model="$ctrl.aupVal.url"
required="true">
<span class="help-block" ng-if="$ctrl.aup.text">
Since v1.6.0, IAM has moved to external AUP documents. Please provide a valid URL pointing to your AUP
Expand All @@ -34,14 +39,12 @@ <h3 class="modal-title">
The URL above is presented to users at registration time or periodically
if the AUP is configured for periodic reacceptance
</span>
<span class="help-block" ng-if="createAup.url.$dirty && createAup.url.$error.required">
Please provide a valid URL pointing to your AUP document.
</span>
<span class="help-block" ng-if="$ctrl.error">
{{ $ctrl.error }}
</span>
<div class="form-group has-error" ng-if="createAup.url.$dirty && createAup.url.$error.required">
<span class="help-block">
Please provide a valid URL for the AUP
</span>
</div>
</div>

<div class="form-group">
<label>AUP signature validity (in days)</label>
<input name="signatureValidity" class="form-control" type="number" value="365"
Expand All @@ -52,15 +55,17 @@ <h3 class="modal-title">
If set to zero, the AUP signature will be asked only at registration time.
</span>
</div>
<div class="form-group" ng-class="{'has-error': $ctrl.error || createAup.aupReminder.$dirty && !createAup.aupReminder.$valid}">
<div class="form-group" ng-if="$ctrl.aupVal.signatureValidityInDays > 0">
<label>AUP signature reminders (in days)</label>
<input name="aupReminder" class="form-control" type="text" ng-model="$ctrl.aupVal.aupRemindersInDays" placeholder="30,15,1" required="true">
<input name="aupReminder" class="form-control" type="text" ng-model="$ctrl.aupVal.aupRemindersInDays" placeholder="30,15,1" ng-required="$ctrl.aupVal.signatureValidityInDays > 0">
<span class="help-block">
Indicate a sequence of comma-separated numbers representing how many days before the AUP expiration reminder messages must be sent.
</span>
<span class="help-block" ng-if="createAup.aupReminder.$dirty && createAup.aupReminder.$error.required">
Required input
</span>
<div class="form-group has-error" ng-if="createAup.aupReminder.$dirty && createAup.aupReminder.$error.required">
<span class="help-block">
Required input
</span>
</div>
</div>
<div class="form-group">
<div class="bs-callout bs-callout-primary">
Expand All @@ -74,7 +79,7 @@ <h4>Editing the AUP will <strong>not</strong> trigger an AUP signature
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" id="modal-btn-confirm"
ng-disabled="!$ctrl.aupVal.url || !$ctrl.enabled" ng-click="$ctrl.doSaveAup()">Edit AUP</button>
ng-disabled="!$ctrl.enabled" ng-click="$ctrl.doSaveAup()">Edit AUP</button>

<button class="btn btn-warning" type="button" id="modal-btn-reset" ng-click="$ctrl.reset()">Reset form</button>

Expand Down
Loading
Loading