-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
523 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/dev/mieser/tsa/signing/config/validator/EitherKeystoreOrPkcs11.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dev.mieser.tsa.signing.config.validator; | ||
|
||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
/** | ||
* Custom type-level validation constraint, which supports for the {@link dev.mieser.tsa.signing.config.TsaProperties}. | ||
* Validates that either a Keystore or PKCS#11 has been configured. | ||
* | ||
* @see EitherKeystoreOrPkcs11Validator | ||
*/ | ||
@Target(TYPE_USE) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = EitherKeystoreOrPkcs11Validator.class) | ||
@Documented | ||
public @interface EitherKeystoreOrPkcs11 { | ||
|
||
String message() default "Either a Keystore or a PKCS#11 device must be configured."; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...rc/main/java/dev/mieser/tsa/signing/config/validator/EitherKeystoreOrPkcs11Validator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.mieser.tsa.signing.config.validator; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
import dev.mieser.tsa.signing.config.TsaProperties; | ||
|
||
/** | ||
* {@link ConstraintValidator} for the {@link EitherKeystoreOrPkcs11} annotation. | ||
* | ||
* @see EitherKeystoreOrPkcs11 | ||
*/ | ||
public class EitherKeystoreOrPkcs11Validator implements ConstraintValidator<EitherKeystoreOrPkcs11, TsaProperties> { | ||
|
||
@Override | ||
public boolean isValid(TsaProperties value, ConstraintValidatorContext context) { | ||
boolean keystoreConfigured = value.keystore().isPresent(); | ||
boolean pkcs11Configured = value.pkcs11().isPresent(); | ||
|
||
return (keystoreConfigured && !pkcs11Configured) || (!keystoreConfigured && pkcs11Configured); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.