diff --git a/api/src/main/java/de/fitko/fitconnect/api/config/Environment.java b/api/src/main/java/de/fitko/fitconnect/api/config/Environment.java index 638e1a5e34439c052a2901e3194c82a8e5bb798f..d92f607d8bf4d713b3181a9eabff539572d7ec0e 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/config/Environment.java +++ b/api/src/main/java/de/fitko/fitconnect/api/config/Environment.java @@ -1,6 +1,8 @@ package de.fitko.fitconnect.api.config; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; @Data @AllArgsConstructor diff --git a/api/src/main/java/de/fitko/fitconnect/api/config/SenderConfig.java b/api/src/main/java/de/fitko/fitconnect/api/config/SenderConfig.java index 07accd0b17d59c3e24016146ae13ea48be4f1a40..545f1e0ea61368d19e8d27440f1c8176782acb7b 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/config/SenderConfig.java +++ b/api/src/main/java/de/fitko/fitconnect/api/config/SenderConfig.java @@ -1,6 +1,8 @@ package de.fitko.fitconnect.api.config; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; @Data @NoArgsConstructor diff --git a/api/src/main/java/de/fitko/fitconnect/api/config/SubscriberConfig.java b/api/src/main/java/de/fitko/fitconnect/api/config/SubscriberConfig.java index 30fc47decd18b091400c62ae21f88a3cae5af0e9..dd36cca40bd823e72064e0d4f7bd3700a01b0667 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/config/SubscriberConfig.java +++ b/api/src/main/java/de/fitko/fitconnect/api/config/SubscriberConfig.java @@ -1,6 +1,9 @@ package de.fitko.fitconnect.api.config; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; @Data @Builder diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/Metadata.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/Metadata.java index 4923277dec569b8bc5addcba4346ebda29b39e1c..3026fffb2e8c02ebcc4faec2c7c9b4ba09ab5a73 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/Metadata.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/Metadata.java @@ -22,11 +22,10 @@ public class Metadata { @JsonProperty("authenticationInformation") private List<AuthenticationInformation> authenticationInformation; - + @JsonProperty("additionalReferenceInfo") private AdditionalReferenceInfo additionalReferenceInfo; @JsonIgnore private Map<String, Object> additionalProperties; } - diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/SignatureFormat.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/SignatureFormat.java index 6d4230e958d24ee72b0316650ef8d94b778cccac..a36975e97a42241fe0e8d60b806d1036404f97e4 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/SignatureFormat.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/SignatureFormat.java @@ -36,5 +36,4 @@ public enum SignatureFormat { .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); } - -} \ No newline at end of file +} diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/attachment/AttachmentWithData.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/attachment/AttachmentWithData.java index f1f2f15c87f2834f36da9f1406a9d73399800382..2a652889b94340b49ee07f106829d8582a1f18df 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/attachment/AttachmentWithData.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/metadata/attachment/AttachmentWithData.java @@ -1,10 +1,13 @@ package de.fitko.fitconnect.api.domain.model.metadata.attachment; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.With; -@Builder -@Getter @With +@Getter +@Builder @AllArgsConstructor public class AttachmentWithData { diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/CreateSubmission.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/CreateSubmission.java index 0aebf74c557208f73ca4ec41445cf44c2a967f1d..e40cbeade7768af764a15b6d70fe0078c68ff346 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/CreateSubmission.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/CreateSubmission.java @@ -1,7 +1,8 @@ package de.fitko.fitconnect.api.domain.model.submission; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.*; +import lombok.Builder; +import lombok.Data; import java.util.List; import java.util.UUID; @@ -24,5 +25,4 @@ public class CreateSubmission { @JsonProperty("callback") private Callback callback; - -} \ No newline at end of file +} diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/ServiceType.java b/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/ServiceType.java index 75def97b73bc95907b76611f00953a2df0cc6214..46c21ec75c1b7a98dbfb8971786962b521a19030 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/ServiceType.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/model/submission/ServiceType.java @@ -1,7 +1,8 @@ package de.fitko.fitconnect.api.domain.model.submission; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.*; +import lombok.Data; +import lombok.NoArgsConstructor; @Data @NoArgsConstructor diff --git a/api/src/main/java/de/fitko/fitconnect/api/domain/validation/ValidationResult.java b/api/src/main/java/de/fitko/fitconnect/api/domain/validation/ValidationResult.java index 9c52d861485b04bf31e73c9ffb9fca61f4455b7d..95b211e49ef357c3ece86128e12af2088c5e9128 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/domain/validation/ValidationResult.java +++ b/api/src/main/java/de/fitko/fitconnect/api/domain/validation/ValidationResult.java @@ -3,7 +3,7 @@ package de.fitko.fitconnect.api.domain.validation; /** * Wrapper for validations including an exception */ -public class ValidationResult { +public final class ValidationResult { private final boolean isValid; private Exception error; diff --git a/api/src/main/java/de/fitko/fitconnect/api/services/Sender.java b/api/src/main/java/de/fitko/fitconnect/api/services/Sender.java index b925b4bbe6115b741cc805b0b4471cc936bb7ed0..0948117b8b72d4dc344aa219a2c653ce99ceeb79 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/services/Sender.java +++ b/api/src/main/java/de/fitko/fitconnect/api/services/Sender.java @@ -36,7 +36,7 @@ public interface Sender { * * @return {@link ValidationResult} that includes an error if the validation failed */ - ValidationResult validatePublicKey(final RSAKey publicKey); + ValidationResult validatePublicKey(RSAKey publicKey); /** * Validates the {@link Metadata} structure against a given JSON-schema to ensure its correctness. @@ -55,7 +55,7 @@ public interface Sender { * * @throws EncryptionException if the encryption fails due to an invalid key or corrupt data */ - String encryptBytes(final RSAKey publicKey, final byte[] data) throws EncryptionException; + String encryptBytes(RSAKey publicKey, byte[] data) throws EncryptionException; /** @@ -67,7 +67,7 @@ public interface Sender { * * @throws EncryptionException if the encryption fails due to an invalid key or corrupt data */ - String encryptObject(final RSAKey publicKey, Object metadata) throws EncryptionException; + String encryptObject(RSAKey publicKey, Object metadata) throws EncryptionException; /** * Create message digest (SHA-512) of a given byte[] diff --git a/api/src/main/java/de/fitko/fitconnect/api/services/Subscriber.java b/api/src/main/java/de/fitko/fitconnect/api/services/Subscriber.java index fa786ce66b71da5b5dc410eb22ef9fcd32732e24..f6f900c5303485f76bc26eb0399d1e493e33fd96 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/services/Subscriber.java +++ b/api/src/main/java/de/fitko/fitconnect/api/services/Subscriber.java @@ -25,7 +25,7 @@ public interface Subscriber { * @param encryptedContent JWE encrypted content that should be decrypted * @return the decrypted content as byte[] */ - byte[] decryptStringContent(final RSAKey privateKey, final String encryptedContent); + byte[] decryptStringContent(RSAKey privateKey, String encryptedContent); /** * Polls available {@link SubmissionForPickup}s for a given destinationId. diff --git a/api/src/main/java/de/fitko/fitconnect/api/services/crypto/CryptoService.java b/api/src/main/java/de/fitko/fitconnect/api/services/crypto/CryptoService.java index ed05c8d99b95d225239ababff7d08bb58a5498e3..220098a0d4b02d966662c3fc2a4a111e37d10af4 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/services/crypto/CryptoService.java +++ b/api/src/main/java/de/fitko/fitconnect/api/services/crypto/CryptoService.java @@ -1,8 +1,8 @@ package de.fitko.fitconnect.api.services.crypto; import com.nimbusds.jose.jwk.RSAKey; -import de.fitko.fitconnect.api.domain.model.metadata.data.Data; import de.fitko.fitconnect.api.domain.model.metadata.attachment.Attachment; +import de.fitko.fitconnect.api.domain.model.metadata.data.Data; import de.fitko.fitconnect.api.domain.model.submission.SubmitSubmission; import de.fitko.fitconnect.api.exceptions.DecryptionException; import de.fitko.fitconnect.api.exceptions.EncryptionException; diff --git a/api/src/main/java/de/fitko/fitconnect/api/services/crypto/MessageDigestService.java b/api/src/main/java/de/fitko/fitconnect/api/services/crypto/MessageDigestService.java index 978cc4421c8a2a349286280fd9bf70a201db4f5e..55185e683360dd65fe884a828b6c74b1eae66575 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/services/crypto/MessageDigestService.java +++ b/api/src/main/java/de/fitko/fitconnect/api/services/crypto/MessageDigestService.java @@ -11,7 +11,7 @@ public interface MessageDigestService { * @param data input bytes that will be hashed * @return byte[] of the hash */ - byte[] createHash(final byte[] data); + byte[] createHash(byte[] data); /** * Create a new hash of a given byte[] and compare it with an existing hash on equality. @@ -20,7 +20,7 @@ public interface MessageDigestService { * @param data data as byte[] that will be hashed * @return boolean if the two hashes are equal */ - boolean verify(final byte[] originalHash, final byte[] data); + boolean verify(byte[] originalHash, byte[] data); /** * Convert hash to a hexadecimal string representation. @@ -28,7 +28,7 @@ public interface MessageDigestService { * @param hash input hash as byte[] * @return hex string of the given hash */ - String toHexString(final byte[] hash); + String toHexString(byte[] hash); /** * Convert a hexadecimal string to byte[]- @@ -36,5 +36,5 @@ public interface MessageDigestService { * @param hexString input hex string * @return byte[] of the given hex string */ - byte[] fromHexString(final String hexString); + byte[] fromHexString(String hexString); } diff --git a/api/src/main/java/de/fitko/fitconnect/api/services/events/EventLogService.java b/api/src/main/java/de/fitko/fitconnect/api/services/events/EventLogService.java index 913c97d8304d1e20904ba9282fa417fc5b67fab9..f6a4ba6bd3ab59738ffce766800e270370ea57bb 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/services/events/EventLogService.java +++ b/api/src/main/java/de/fitko/fitconnect/api/services/events/EventLogService.java @@ -18,7 +18,7 @@ public interface EventLogService { * Get the {@link EventLog} by caseId. * * @param caseId unique case identifier - * @return + * @return EventLog */ EventLog getEventLog(UUID caseId); diff --git a/api/src/main/java/de/fitko/fitconnect/api/services/events/SecurityEventService.java b/api/src/main/java/de/fitko/fitconnect/api/services/events/SecurityEventService.java index c181e0c20bfeeebc47eeeb6da32d8d02bd0d5623..afd9cc9b73a5bd8e668946f6c8afb66557aa366f 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/services/events/SecurityEventService.java +++ b/api/src/main/java/de/fitko/fitconnect/api/services/events/SecurityEventService.java @@ -22,7 +22,7 @@ public interface SecurityEventService { * * @return signed and SET encoded event */ - String createAcceptSubmissionEvent(final UUID submissionId, UUID destinationId, final UUID caseId) ; + String createAcceptSubmissionEvent(UUID submissionId, UUID destinationId, UUID caseId); /** * Create a new reject_submission event for an invalid submission. @@ -33,6 +33,6 @@ public interface SecurityEventService { * * @return signed and SET encoded event */ - String createRejectSubmissionEvent(final UUID submissionId, UUID destinationId, final UUID caseId); + String createRejectSubmissionEvent(UUID submissionId, UUID destinationId, UUID caseId); } diff --git a/api/src/main/java/de/fitko/fitconnect/api/services/submission/SubmissionService.java b/api/src/main/java/de/fitko/fitconnect/api/services/submission/SubmissionService.java index 7d50409419754bf96c65a2819e12a3eb41a34298..5dae7ed383cfd23278e995e0c14e813bbcae8fcf 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/services/submission/SubmissionService.java +++ b/api/src/main/java/de/fitko/fitconnect/api/services/submission/SubmissionService.java @@ -59,7 +59,7 @@ public interface SubmissionService { * @param attachmentId unique destination identifier * @param encryptedAttachment JWE encrypted attachment payload */ - void uploadAttachment(final UUID submissionId, final UUID attachmentId, final String encryptedAttachment); + void uploadAttachment(UUID submissionId, UUID attachmentId, String encryptedAttachment); /** * Get an {@link Attachment} by id for a given {@link Submission}. diff --git a/api/src/main/java/de/fitko/fitconnect/api/services/validation/ValidationService.java b/api/src/main/java/de/fitko/fitconnect/api/services/validation/ValidationService.java index e27d2c74367bfdda772634cd143af3ef745be71d..969a5ea46389484500e30c41c280b407f96cca83 100644 --- a/api/src/main/java/de/fitko/fitconnect/api/services/validation/ValidationService.java +++ b/api/src/main/java/de/fitko/fitconnect/api/services/validation/ValidationService.java @@ -24,7 +24,7 @@ public interface ValidationService { * * @return {@link ValidationResult} that includes an error if the validation failed */ - ValidationResult validatePublicKey(final RSAKey publicKey); + ValidationResult validatePublicKey(RSAKey publicKey); /** * Validates the metadata against a given schema. @@ -34,7 +34,7 @@ public interface ValidationService { * * @return a {@link ValidationResult} with an optional error */ - ValidationResult validateMetadataSchema(final String jsonSchema, final Metadata metadata); + ValidationResult validateMetadataSchema(String jsonSchema, Metadata metadata); /** diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml new file mode 100644 index 0000000000000000000000000000000000000000..15573bac58322148f05332a53af59c5f0bb67458 --- /dev/null +++ b/checkstyle-suppressions.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> + +<!DOCTYPE suppressions PUBLIC + "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" + "https://checkstyle.org/dtds/suppressions_1_2.dtd"> + +<suppressions> + <suppressions> + <suppress checks="Javadoc" files="."/> + </suppressions> +</suppressions> diff --git a/checkstyle.xml b/checkstyle.xml index de4e4420438c488bb0a6aefcd553346f169aa7e2..84354d5224f371c786ebb9774832c6bbde048ee2 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -1,367 +1,156 @@ <?xml version="1.0"?> <!DOCTYPE module PUBLIC - "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" - "https://checkstyle.org/dtds/configuration_1_3.dtd"> + "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" + "https://checkstyle.org/dtds/configuration_1_3.dtd"> -<!-- - Checkstyle configuration that checks the Google coding conventions from Google Java Style - that can be found at https://google.github.io/styleguide/javaguide.html +<module name="Checker"> + <!-- + If you set the basedir property below, then all reported file + names will be relative to the specified directory. See + https://checkstyle.org/config.html#Checker - Checkstyle is very configurable. Be sure to read the documentation at - http://checkstyle.org (or in your downloaded distribution). - - To completely disable a check, just comment it out or delete it from the file. - To suppress certain violations please review suppression filters. - - Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. - --> - -<module name = "Checker"> - <property name="charset" value="UTF-8"/> - - <property name="severity" value="warning"/> + <property name="basedir" value="${basedir}"/> + --> + <property name="severity" value="error"/> <property name="fileExtensions" value="java, properties, xml"/> + <!-- Excludes all 'module-info.java' files --> <!-- See https://checkstyle.org/config_filefilters.html --> <module name="BeforeExecutionExclusionFileFilter"> <property name="fileNamePattern" value="module\-info\.java$"/> </module> + <!-- https://checkstyle.org/config_filters.html#SuppressionFilter --> <module name="SuppressionFilter"> - <property name="file" value="${org.checkstyle.google.suppressionfilter.config}" - default="checkstyle-suppressions.xml" /> + <property name="file" value="${org.checkstyle.sun.suppressionfilter.config}" + default="checkstyle-suppressions.xml"/> <property name="optional" value="true"/> </module> - <!-- Checks for whitespace --> - <!-- See http://checkstyle.org/config_whitespace.html --> - <module name="FileTabCharacter"> - <property name="eachLine" value="true"/> - </module> + <!-- Checks whether files end with a new line. --> + <!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile --> + <module name="NewlineAtEndOfFile"/> + <!-- Checks that property files contain the same keys. --> + <!-- See https://checkstyle.org/config_misc.html#Translation --> + <module name="Translation"/> + + <!-- Checks for Size Violations. --> + <!-- See https://checkstyle.org/config_sizes.html --> + <module name="FileLength"/> <module name="LineLength"> <property name="fileExtensions" value="java"/> - <property name="max" value="100"/> - <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> + <property name="max" value="270"/> + </module> + + + <!-- Checks for whitespace --> + <!-- See https://checkstyle.org/config_whitespace.html --> + <module name="FileTabCharacter"/> + + <!-- Miscellaneous other checks. --> + <!-- See https://checkstyle.org/config_misc.html --> + <module name="RegexpSingleline"> + <property name="format" value="\s+$"/> + <property name="minimum" value="0"/> + <property name="maximum" value="0"/> + <property name="message" value="Line has trailing spaces."/> </module> <module name="TreeWalker"> - <module name="OuterTypeFilename"/> - <module name="IllegalTokenText"> - <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/> - <property name="format" - value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/> - <property name="message" - value="Consider using special escape sequence instead of octal value or Unicode escaped value."/> - </module> - <module name="AvoidEscapedUnicodeCharacters"> - <property name="allowEscapesForControlCharacters" value="true"/> - <property name="allowByTailComment" value="true"/> - <property name="allowNonPrintableEscapes" value="true"/> - </module> + + <!-- Checks for Naming Conventions. --> + <!-- See https://checkstyle.org/config_naming.html --> + <module name="ConstantName"/> + <module name="LocalFinalVariableName"/> + <module name="LocalVariableName"/> + <module name="MemberName"/> + <!-- <module name="MethodName"/> --> + <module name="PackageName"/> + <module name="ParameterName"/> + <module name="StaticVariableName"/> + <module name="TypeName"/> + + <!-- Checks for imports --> + <!-- See https://checkstyle.org/config_imports.html --> <module name="AvoidStarImport"/> - <module name="OneTopLevelClass"/> - <module name="NoLineWrap"> - <property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/> - </module> - <module name="EmptyBlock"> - <property name="option" value="TEXT"/> - <property name="tokens" - value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/> - </module> - <module name="NeedBraces"> - <property name="tokens" - value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/> + <module name="IllegalImport"/> <!-- defaults to sun.* packages --> + <module name="RedundantImport"/> + <module name="UnusedImports"> + <property name="processJavadoc" value="false"/> + </module> + <module name="ImportOrder"> + <property name="groups" value="*,javax,java"/> + <property name="ordered" value="true"/> + <property name="separated" value="true"/> + <property name="option" value="bottom"/> + <property name="sortStaticImportsAlphabetically" value="true"/> </module> - <module name="LeftCurly"> - <property name="tokens" - value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF, - INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, LITERAL_DEFAULT, - LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, - LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF, - OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF"/> - </module> - <module name="RightCurly"> - <property name="id" value="RightCurlySame"/> - <property name="tokens" - value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, - LITERAL_DO"/> - </module> - <module name="RightCurly"> - <property name="id" value="RightCurlyAlone"/> - <property name="option" value="alone"/> - <property name="tokens" - value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT, - INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF, INTERFACE_DEF, RECORD_DEF, - COMPACT_CTOR_DEF"/> - </module> - <module name="SuppressionXpathSingleFilter"> - <!-- suppresion is required till https://github.com/checkstyle/checkstyle/issues/7541 --> - <property name="id" value="RightCurlyAlone"/> - <property name="query" value="//RCURLY[parent::SLIST[count(./*)=1] - or preceding-sibling::*[last()][self::LCURLY]]"/> - </module> - <module name="WhitespaceAfter"> - <property name="tokens" - value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE, LITERAL_RETURN, - LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, LITERAL_FINALLY, DO_WHILE, ELLIPSIS, - LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_CATCH, LAMBDA, - LITERAL_YIELD, LITERAL_CASE"/> - </module> - <module name="WhitespaceAround"> - <property name="allowEmptyConstructors" value="true"/> - <property name="allowEmptyLambdas" value="true"/> - <property name="allowEmptyMethods" value="true"/> - <property name="allowEmptyTypes" value="true"/> - <property name="allowEmptyLoops" value="true"/> - <property name="ignoreEnhancedForColon" value="false"/> - <property name="tokens" - value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, - BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND, - LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, - LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, - LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, - NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, - SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/> - <message key="ws.notFollowed" - value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks - may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/> - <message key="ws.notPreceded" - value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/> - </module> - <module name="OneStatementPerLine"/> + + <!-- Checks for Size Violations. --> + <!-- See https://checkstyle.org/config_sizes.html --> + <module name="MethodLength"/> + <module name="ParameterNumber"/> + + <!-- Checks for whitespace --> + <!-- See https://checkstyle.org/config_whitespace.html --> + <module name="EmptyForIteratorPad"/> + <module name="GenericWhitespace"/> + <module name="MethodParamPad"/> + <module name="NoWhitespaceAfter"/> + <module name="NoWhitespaceBefore"/> + <module name="ParenPad"/> + <module name="TypecastParenPad"/> + <module name="WhitespaceAfter"/> + <module name="WhitespaceAround"/> + + <!-- Modifier Checks --> + <!-- See https://checkstyle.org/config_modifier.html --> + <module name="ModifierOrder"/> + <module name="RedundantModifier"/> + + <!-- Checks for blocks. You know, those {}'s --> + <!-- See https://checkstyle.org/config_blocks.html --> + <module name="AvoidNestedBlocks"/> + <module name="EmptyBlock"/> + <module name="LeftCurly"/> + <module name="NeedBraces"/> + <module name="RightCurly"/> + + <!-- Checks for common coding problems --> + <!-- See https://checkstyle.org/config_coding.html --> + <module name="EmptyStatement"/> + <module name="EqualsHashCode"/> + <module name="IllegalInstantiation"/> + <module name="InnerAssignment"/> + <!--<module name="MagicNumber"/> --> + <module name="MissingSwitchDefault"/> <module name="MultipleVariableDeclarations"/> + <module name="SimplifyBooleanExpression"/> + <module name="SimplifyBooleanReturn"/> + + <!-- Checks for class design --> + <!-- See https://checkstyle.org/config_design.html --> + <!-- <module name="DesignForExtension"/> --> + <module name="FinalClass"/> + <module name="HideUtilityClassConstructor"/> + <module name="InterfaceIsType"/> + <!-- <module name="VisibilityModifier"/> --> + + <!-- Miscellaneous other checks. --> + <!-- See https://checkstyle.org/config_misc.html --> <module name="ArrayTypeStyle"/> - <module name="MissingSwitchDefault"/> - <module name="FallThrough"/> + <!-- <module name="TodoComment"/> --> <module name="UpperEll"/> - <module name="ModifierOrder"/> - <module name="EmptyLineSeparator"> - <property name="tokens" - value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, - STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF, - COMPACT_CTOR_DEF"/> - <property name="allowNoEmptyLineBetweenFields" value="true"/> - </module> - <module name="SeparatorWrap"> - <property name="id" value="SeparatorWrapDot"/> - <property name="tokens" value="DOT"/> - <property name="option" value="nl"/> - </module> - <module name="SeparatorWrap"> - <property name="id" value="SeparatorWrapComma"/> - <property name="tokens" value="COMMA"/> - <property name="option" value="EOL"/> - </module> - <module name="SeparatorWrap"> - <!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/259 --> - <property name="id" value="SeparatorWrapEllipsis"/> - <property name="tokens" value="ELLIPSIS"/> - <property name="option" value="EOL"/> - </module> - <module name="SeparatorWrap"> - <!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/258 --> - <property name="id" value="SeparatorWrapArrayDeclarator"/> - <property name="tokens" value="ARRAY_DECLARATOR"/> - <property name="option" value="EOL"/> - </module> - <module name="SeparatorWrap"> - <property name="id" value="SeparatorWrapMethodRef"/> - <property name="tokens" value="METHOD_REF"/> - <property name="option" value="nl"/> - </module> - <module name="PackageName"> - <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/> - <message key="name.invalidPattern" - value="Package name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="TypeName"> - <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, - ANNOTATION_DEF, RECORD_DEF"/> - <message key="name.invalidPattern" - value="Type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="MemberName"> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> - <message key="name.invalidPattern" - value="Member name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="ParameterName"> - <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> - <message key="name.invalidPattern" - value="Parameter name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="LambdaParameterName"> - <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> - <message key="name.invalidPattern" - value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="CatchParameterName"> - <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> - <message key="name.invalidPattern" - value="Catch parameter name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="LocalVariableName"> - <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> - <message key="name.invalidPattern" - value="Local variable name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="PatternVariableName"> - <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> - <message key="name.invalidPattern" - value="Pattern variable name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="ClassTypeParameterName"> - <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> - <message key="name.invalidPattern" - value="Class type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="RecordComponentName"> - <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> - <message key="name.invalidPattern" - value="Record component name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="RecordTypeParameterName"> - <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> - <message key="name.invalidPattern" - value="Record type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="MethodTypeParameterName"> - <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> - <message key="name.invalidPattern" - value="Method type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="InterfaceTypeParameterName"> - <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> - <message key="name.invalidPattern" - value="Interface type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="NoFinalizer"/> - <module name="GenericWhitespace"> - <message key="ws.followed" - value="GenericWhitespace ''{0}'' is followed by whitespace."/> - <message key="ws.preceded" - value="GenericWhitespace ''{0}'' is preceded with whitespace."/> - <message key="ws.illegalFollow" - value="GenericWhitespace ''{0}'' should followed by whitespace."/> - <message key="ws.notPreceded" - value="GenericWhitespace ''{0}'' is not preceded with whitespace."/> - </module> - <module name="Indentation"> - <property name="basicOffset" value="2"/> - <property name="braceAdjustment" value="2"/> - <property name="caseIndent" value="2"/> - <property name="throwsIndent" value="4"/> - <property name="lineWrappingIndentation" value="4"/> - <property name="arrayInitIndent" value="2"/> - </module> - <module name="AbbreviationAsWordInName"> - <property name="ignoreFinal" value="false"/> - <property name="allowedAbbreviationLength" value="0"/> - <property name="tokens" - value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, - PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF, - RECORD_COMPONENT_DEF"/> - </module> - <module name="NoWhitespaceBeforeCaseDefaultColon"/> - <module name="OverloadMethodsDeclarationOrder"/> - <module name="VariableDeclarationUsageDistance"/> - <module name="CustomImportOrder"> - <property name="sortImportsInGroupAlphabetically" value="true"/> - <property name="separateLineBetweenGroups" value="true"/> - <property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/> - <property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/> - </module> - <module name="MethodParamPad"> - <property name="tokens" - value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, - SUPER_CTOR_CALL, ENUM_CONSTANT_DEF, RECORD_DEF"/> - </module> - <module name="NoWhitespaceBefore"> - <property name="tokens" - value="COMMA, SEMI, POST_INC, POST_DEC, DOT, - LABELED_STAT, METHOD_REF"/> - <property name="allowLineBreaks" value="true"/> - </module> - <module name="ParenPad"> - <property name="tokens" - value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF, - EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, - LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, - METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA, - RECORD_DEF"/> - </module> - <module name="OperatorWrap"> - <property name="option" value="NL"/> - <property name="tokens" - value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, - LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF, - TYPE_EXTENSION_AND "/> - </module> - <module name="AnnotationLocation"> - <property name="id" value="AnnotationLocationMostCases"/> - <property name="tokens" - value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, - RECORD_DEF, COMPACT_CTOR_DEF"/> - </module> - <module name="AnnotationLocation"> - <property name="id" value="AnnotationLocationVariables"/> - <property name="tokens" value="VARIABLE_DEF"/> - <property name="allowSamelineMultipleAnnotations" value="true"/> - </module> - <module name="NonEmptyAtclauseDescription"/> - <module name="InvalidJavadocPosition"/> - <module name="JavadocTagContinuationIndentation"/> - <module name="SummaryJavadoc"> - <property name="forbiddenSummaryFragments" - value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/> - </module> - <module name="JavadocParagraph"/> - <module name="RequireEmptyLineBeforeBlockTagGroup"/> - <module name="AtclauseOrder"> - <property name="tagOrder" value="@param, @return, @throws, @deprecated"/> - <property name="target" - value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/> - </module> - <module name="JavadocMethod"> - <property name="accessModifiers" value="public"/> - <property name="allowMissingParamTags" value="true"/> - <property name="allowMissingReturnTag" value="true"/> - <property name="allowedAnnotations" value="Override, Test"/> - <property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF"/> - </module> - <module name="MissingJavadocMethod"> - <property name="scope" value="public"/> - <property name="minLineCount" value="2"/> - <property name="allowedAnnotations" value="Override, Test"/> - <property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, - COMPACT_CTOR_DEF"/> - </module> - <module name="MissingJavadocType"> - <property name="scope" value="protected"/> - <property name="tokens" - value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, - RECORD_DEF, ANNOTATION_DEF"/> - <property name="excludeScope" value="nothing"/> - </module> - <module name="MethodName"> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/> - <message key="name.invalidPattern" - value="Method name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="SingleLineJavadoc"/> - <module name="EmptyCatchBlock"> - <property name="exceptionVariableName" value="expected"/> - </module> - <module name="CommentsIndentation"> - <property name="tokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/> - </module> + <!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter --> <module name="SuppressionXpathFilter"> - <property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}" - default="checkstyle-xpath-suppressions.xml" /> + <property name="file" value="${org.checkstyle.sun.suppressionxpathfilter.config}" + default="checkstyle-xpath-suppressions.xml"/> <property name="optional" value="true"/> </module> + </module> + </module> diff --git a/client/pom.xml b/client/pom.xml index 4de59a2a71bc25003512732f8a3ecf4375f761ed..300bf2f42e7053eb14ce455eb70dccd1e1455581 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -65,17 +65,11 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> - <version>${maven-compiler-plugin.version}</version> - <configuration> - <source>11</source> - <target>11</target> - </configuration> </plugin> <plugin> <!-- Build an executable JAR --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> - <version>3.2.2</version> <configuration> <archive> <manifest> @@ -89,7 +83,6 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> - <version>3.3.0</version> <executions> <execution> <phase>package</phase> diff --git a/client/src/main/java/de/fitko/fitconnect/client/SenderClient.java b/client/src/main/java/de/fitko/fitconnect/client/SenderClient.java index 0092c2867883d54f2b94326ae1345200c3fce02e..ea6225595c95c3986aaaa4f98043cc6af68f4a0e 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/SenderClient.java +++ b/client/src/main/java/de/fitko/fitconnect/client/SenderClient.java @@ -39,9 +39,9 @@ import java.util.stream.Collectors; /** * A fluent client for announcing and handing in a {@link SubmitSubmission} */ -public class SenderClient { +public final class SenderClient { - private static final Logger logger = LoggerFactory.getLogger(SenderClient.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SenderClient.class); private SenderClient() { } @@ -216,15 +216,17 @@ public class SenderClient { public Optional<SubmitSubmission> submit() { try { - if (!isAllNecessaryDataSet()) return Optional.empty(); + if (!isAllNecessaryDataSet()) { + return Optional.empty(); + } /** Get encryption key for destination **/ final Destination destination = sender.getDestination(destinationId); final RSAKey encryptionKey = sender.getEncryptionKeyForDestination(destinationId, destination.getEncryptionKid()); final ValidationResult validationResult = sender.validatePublicKey(encryptionKey); if (validationResult.hasError()) { - logger.warn("The public key is not valid, {}", validationResult.getError().getMessage()); - if(!environment.isSilentKeyValidation()){ + LOGGER.warn("The public key is not valid, {}", validationResult.getError().getMessage()); + if (!environment.isSilentKeyValidation()) { return Optional.empty(); } } @@ -245,12 +247,12 @@ public class SenderClient { final List<Attachment> hashedAttachments = toHashedAttachments(attachmentPayloads); /** Set encrypted metadata with data payload and attachments **/ - logger.info("Adding data payload with mime-type {} to submission", this.dataPayload.mimeType); + LOGGER.info("Adding data payload with mime-type {} to submission", this.dataPayload.mimeType); final DataPayload dataToSend = getEncryptedData(this.dataPayload, destination, encryptionKey); final Metadata metadata = createMetadata(hashedAttachments, dataToSend); final ValidationResult validatedMetadata = sender.validateMetadata(metadata, metadataSchema); if (validatedMetadata.hasError()) { - logger.error("Metadata does not match schema", validatedMetadata.getError()); + LOGGER.error("Metadata does not match schema", validatedMetadata.getError()); sender.rejectSubmission(submissionId, destinationId, announcedSubmission.getCaseId()); return Optional.empty(); } @@ -259,21 +261,21 @@ public class SenderClient { /** submit submission **/ sender.sendSubmission(submission); - logger.info("SUCCESSFULLY HANDED IN SUBMISSION !"); + LOGGER.info("SUCCESSFULLY HANDED IN SUBMISSION !"); return Optional.of(submission); } catch (final EncryptionException e) { - logger.error("Encrypting submission failed", e); + LOGGER.error("Encrypting submission failed", e); } catch (final RestApiException e) { - logger.error("Sending submission failed", e); + LOGGER.error("Sending submission failed", e); } catch (final SchemaNotFoundException e) { - logger.error("Required schema to send valid submission not found", e); + LOGGER.error("Required schema to send valid submission not found", e); } catch (final SubmissionNotCreatedException e) { - logger.error("Failed to announce new submission", e); + LOGGER.error("Failed to announce new submission", e); } catch (final KeyNotRetrievedException e) { - logger.error("Getting encryption key for destination {} failed", destinationId, e); + LOGGER.error("Getting encryption key for destination {} failed", destinationId, e); } catch (final AttachmentCreationException e) { - logger.error("Reading file failed. Attachment will not be created.", e); + LOGGER.error("Reading file failed. Attachment will not be created.", e); } return Optional.empty(); } @@ -337,9 +339,9 @@ public class SenderClient { private void uploadAttachments(final List<AttachmentPayload> attachmentPayloads, final UUID submissionId) { if (attachmentPayloads.isEmpty()) { - logger.info("No attachments to upload"); + LOGGER.info("No attachments to upload"); } else { - logger.info("Uploading {} attachment(s)", attachmentPayloads.size()); + LOGGER.info("Uploading {} attachment(s)", attachmentPayloads.size()); } for (final AttachmentPayload payload : attachmentPayloads) { sender.uploadAttachment(submissionId, payload.attachmentId, payload.encryptedData); @@ -448,22 +450,22 @@ public class SenderClient { } catch (final IOException e) { mimeType = URLConnection.guessContentTypeFromName(file.getName()); } - logger.info("Detected attachment mime-type {}", mimeType); + LOGGER.info("Detected attachment mime-type {}", mimeType); return attachmentPayload.withMimeType(mimeType); } private boolean isAllNecessaryDataSet() { if (this.dataPayload == null) { - logger.error("Data is mandatory, but was null."); + LOGGER.error("Data is mandatory, but was null."); return false; } else if (this.serviceType.getName() == null) { - logger.error("Service type name is mandatory, but was null."); + LOGGER.error("Service type name is mandatory, but was null."); return false; } else if (this.serviceType.getIdentifier() == null) { - logger.error("Service type identifier is mandatory, but was null."); + LOGGER.error("Service type identifier is mandatory, but was null."); return false; } else if (this.destinationId == null) { - logger.error("DestinationId is mandatory, but was null."); + LOGGER.error("DestinationId is mandatory, but was null."); return false; } else { return true; @@ -493,4 +495,4 @@ public class SenderClient { private URI schemaUri; } } -} \ No newline at end of file +} diff --git a/client/src/main/java/de/fitko/fitconnect/client/SubscriberClient.java b/client/src/main/java/de/fitko/fitconnect/client/SubscriberClient.java index 03d92ba42a9997971c058ab5cb8df6fc02071267..f471e6260e2dd4e37c46fd241f795a0c427a19ca 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/SubscriberClient.java +++ b/client/src/main/java/de/fitko/fitconnect/client/SubscriberClient.java @@ -27,21 +27,20 @@ import java.util.*; /** * A fluent client for handing in a subscription for a {@link Subscriber} */ -public class SubscriberClient { - - private static final Logger logger = LoggerFactory.getLogger(SubscriberClient.class); +public final class SubscriberClient { + private static final Logger LOGGER = LoggerFactory.getLogger(SubscriberClient.class); private SubscriberClient() { } public static RequestSubmission builder(final Subscriber subscriber, final String privateKey, final String metadataSchema) { if (privateKey == null) { - logger.error("No decryption key set, please check environment (config.yml) and provide a reference to the private decryption key"); + LOGGER.error("No decryption key set, please check environment (config.yml) and provide a reference to the private decryption key"); return null; } if (metadataSchema == null) { - logger.error("No metadata schema present, please check environment (config.yml) and provide a metadata json schema"); + LOGGER.error("No metadata schema present, please check environment (config.yml) and provide a metadata json schema"); return null; } return new ClientBuilder(subscriber, privateKey, metadataSchema); @@ -99,7 +98,7 @@ public class SubscriberClient { @Override public Set<SubmissionForPickup> getAvailableSubmissions(final UUID destinationId, final int offset, final int limit) { final Set<SubmissionForPickup> submissions = subscriber.pollAvailableSubmissions(destinationId, offset, limit); - logger.info("Received {} submission(s) for destination {}", submissions.size(), destinationId); + LOGGER.info("Received {} submission(s) for destination {}", submissions.size(), destinationId); return submissions; } @@ -107,15 +106,15 @@ public class SubscriberClient { public Optional<ReceivedSubmission> requestSubmission(final UUID submissionId) { try { - if(decryptionKey == null) { - logger.error("Private decryption key is not available"); + if (decryptionKey == null) { + LOGGER.error("Private decryption key is not available"); return Optional.empty(); } /** Get submission by id **/ final Submission submission = subscriber.getSubmission(submissionId); if (submission == null) { - logger.error("Submission with id {} does not exist", submissionId); + LOGGER.error("Submission with id {} does not exist", submissionId); return Optional.empty(); } @@ -123,7 +122,7 @@ public class SubscriberClient { final Metadata metadata = getMetadata(submission); final ValidationResult metadataValidation = subscriber.validateMetadata(metadata, metadataSchema); if (metadataValidation.hasError()) { - logger.error("Metadata does not match schema", metadataValidation.getError()); + LOGGER.error("Metadata does not match schema", metadataValidation.getError()); subscriber.rejectSubmission(submissionId, submission.getDestinationId(), submission.getCaseId()); return Optional.empty(); } @@ -133,7 +132,7 @@ public class SubscriberClient { final String hashFromSender = getHashFromSender(metadata); final ValidationResult dataValidation = subscriber.validateHashIntegrity(hashFromSender, decryptedData); if (dataValidation.hasError()) { - logger.error("Data might be corrupted, hash-sum doe not match", dataValidation.getError()); + LOGGER.error("Data might be corrupted, hash-sum doe not match", dataValidation.getError()); subscriber.rejectSubmission(submissionId, submission.getDestinationId(), submission.getCaseId()); return Optional.empty(); } @@ -143,7 +142,7 @@ public class SubscriberClient { final List<AttachmentWithData> decryptedAttachments = decryptAttachments(submissionId, attachmentMetadata); final ValidationResult attachmentValidation = validateAttachments(decryptedAttachments); if (attachmentValidation.hasError()) { - logger.error("One of the attachments is invalid", attachmentValidation.getError()); + LOGGER.error("One of the attachments is invalid", attachmentValidation.getError()); subscriber.rejectSubmission(submissionId, submission.getDestinationId(), submission.getCaseId()); return Optional.empty(); } @@ -153,22 +152,22 @@ public class SubscriberClient { return Optional.of(buildReceivedSubmission(metadata, decryptedAttachments, decryptedData)); } catch (final DecryptionException e) { - logger.error("Decrypting payload failed", e); + LOGGER.error("Decrypting payload failed", e); } catch (final RestApiException e) { - logger.error("API request failed", e); + LOGGER.error("API request failed", e); } catch (final EventCreationException e) { - logger.error("Creating SET event failed", e); + LOGGER.error("Creating SET event failed", e); } catch (final InvalidSigningKeyException e) { - logger.error("Signing the SET event failed", e); - }catch (final IOException e) { - logger.error("Reading metadata failed", e); + LOGGER.error("Signing the SET event failed", e); + } catch (final IOException e) { + LOGGER.error("Reading metadata failed", e); } return Optional.empty(); } private List<AttachmentWithData> decryptAttachments(final UUID submissionId, final List<Attachment> attachmentMetadata) { if (attachmentMetadata == null || attachmentMetadata.isEmpty()) { - logger.info("Submission contains no attachments"); + LOGGER.info("Submission contains no attachments"); return Collections.emptyList(); } return decryptAttachments(getAttachments(submissionId, attachmentMetadata)); @@ -186,7 +185,7 @@ public class SubscriberClient { try { return RSAKey.parse(privateKey); } catch (final ParseException e) { - logger.error("Private key could not be parsed", e); + LOGGER.error("Private key could not be parsed", e); return null; } } @@ -228,10 +227,10 @@ public class SubscriberClient { final Hash__1 hash = attachmentMetadata.getHash(); final ValidationResult result = subscriber.validateHashIntegrity(hash.getContent(), attachmentData.getDecryptedData()); if (result.hasError()) { - logger.error("Attachment data for id {} is corrupted", attachmentMetadata.getAttachmentId(), result.getError()); + LOGGER.error("Attachment data for id {} is corrupted", attachmentMetadata.getAttachmentId(), result.getError()); return ValidationResult.error(new DataIntegrityException("Attachment " + attachmentMetadata.getAttachmentId() + " is corrupt")); } else { - logger.info("Attachment {} with id {} is valid", attachmentMetadata.getFilename(), attachmentMetadata.getAttachmentId()); + LOGGER.info("Attachment {} with id {} is valid", attachmentMetadata.getFilename(), attachmentMetadata.getAttachmentId()); } } return ValidationResult.ok(); @@ -253,4 +252,4 @@ public class SubscriberClient { MimeType mimeType; List<AttachmentWithData> attachments; } -} \ No newline at end of file +} diff --git a/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineClient.java b/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineClient.java index aa8e36af5f9d142a1b04251e2d4c01dc986bdddd..2c26a9a9ea96bc41d38229259fc44c846998b640 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineClient.java +++ b/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineClient.java @@ -24,7 +24,7 @@ import static de.fitko.fitconnect.client.cmd.util.AttachmentDataType.XML; public class CommandLineClient { - private static final Logger logger = LoggerFactory.getLogger(CommandLineClient.class); + private static final Logger LOGGER = LoggerFactory.getLogger(CommandLineClient.class); private final SendSubmissionCommand sendSubmissionCommand; private final ListAllSubmissionsCommand listAllSubmissionsCommand; @@ -85,30 +85,30 @@ public class CommandLineClient { jc.parse(args); return jc.getParsedCommand(); } catch (final ParameterException e) { - logger.error(e.getMessage(), "\n"); + LOGGER.error(e.getMessage(), "\n"); jc.usage(); return null; } } private void listOneSubmission(final ListOneSubmissionCommand listOneSubmissionCommand) throws IOException { - logger.info("Listing submission for id {}", listOneSubmissionCommand.submissionId); + LOGGER.info("Listing submission for id {}", listOneSubmissionCommand.submissionId); final var submission = subscriberClient.requestSubmission(listOneSubmissionCommand.submissionId); if (submission.isEmpty()) { - logger.info("No submission found for submission id {}", listOneSubmissionCommand.submissionId); + LOGGER.info("No submission found for submission id {}", listOneSubmissionCommand.submissionId); } else { writeData(submission.get(), getTargetFolderPath(listOneSubmissionCommand)); } } private void listSubmissions(final ListAllSubmissionsCommand listAllSubmissionsCommand) { - logger.info("Listing available submissions for destination {}", listAllSubmissionsCommand.destinationId); + LOGGER.info("Listing available submissions for destination {}", listAllSubmissionsCommand.destinationId); subscriberClient.getAvailableSubmissions(listAllSubmissionsCommand.destinationId) .forEach(submission -> System.out.println(submission.getSubmissionId())); } private void sendSubmission(final SendSubmissionCommand sendSubmissionCommand) { - logger.info("Sending new submission to destination {}", sendSubmissionCommand.destinationId); + LOGGER.info("Sending new submission to destination {}", sendSubmissionCommand.destinationId); final var client = senderClient .withDestination(sendSubmissionCommand.destinationId) .withServiceType(sendSubmissionCommand.serviceName, sendSubmissionCommand.leikaKey) @@ -129,17 +129,17 @@ public class CommandLineClient { } private void writeData(final SubscriberClient.ReceivedSubmission submissionData, final String dataDirPath) throws IOException { - logger.info("Creating data directory for submission in {}", dataDirPath); + LOGGER.info("Creating data directory for submission in {}", dataDirPath); Files.createDirectories(Path.of(dataDirPath)); final var fileEnding = AttachmentDataType.getFileTypeFromMimeType(submissionData.getMimeType()); final var filePath = Path.of(dataDirPath + "/data." + fileEnding); - logger.info("Writing data.{}", fileEnding); + LOGGER.info("Writing data.{}", fileEnding); Files.write(filePath, submissionData.getData().getBytes(StandardCharsets.UTF_8)); for (final AttachmentWithData attachment : submissionData.getAttachments()) { final String filename = attachment.getAttachmentMetadata().getFilename(); - logger.info("Writing attachment {}", filename); + LOGGER.info("Writing attachment {}", filename); Files.write(Path.of(dataDirPath, filename), attachment.getDecryptedData()); } } diff --git a/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineRunner.java b/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineRunner.java index 07c8649c85bb3f8921f74c571f6f651dc3a6046a..39d71f52f8cc8afa38f08fe640014feb029e8d5e 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineRunner.java +++ b/client/src/main/java/de/fitko/fitconnect/client/cmd/CommandLineRunner.java @@ -4,7 +4,10 @@ import de.fitko.fitconnect.client.factory.ClientFactory; import java.io.IOException; -public class CommandLineRunner { +public final class CommandLineRunner { + + private CommandLineRunner() { + } public static void main(final String[] args) throws IOException { final var senderClient = ClientFactory.senderClient(); diff --git a/client/src/main/java/de/fitko/fitconnect/client/cmd/commands/SendSubmissionCommand.java b/client/src/main/java/de/fitko/fitconnect/client/cmd/commands/SendSubmissionCommand.java index 776db6462ce0fe60e1051969a35a72b37321a6eb..3baa75b8e2a0c6b5c574d5cf1a12077d66d3c496 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/cmd/commands/SendSubmissionCommand.java +++ b/client/src/main/java/de/fitko/fitconnect/client/cmd/commands/SendSubmissionCommand.java @@ -25,11 +25,11 @@ public class SendSubmissionCommand { public UUID destinationId; - @Parameter(names ={ "--serviceName"}, arity = 1, description = "Name of the service type", required = true) + @Parameter(names = { "--serviceName"}, arity = 1, description = "Name of the service type", required = true) public String serviceName; - @Parameter(names ={ "--leikaKey"}, arity = 1, description = "The LeikaKey of the service type", required = true) + @Parameter(names = { "--leikaKey"}, arity = 1, description = "The LeikaKey of the service type", required = true) public String leikaKey; diff --git a/client/src/main/java/de/fitko/fitconnect/client/cmd/util/UUIDValidator.java b/client/src/main/java/de/fitko/fitconnect/client/cmd/util/UUIDValidator.java index 60a80d8c565c84be89a793024b4017dff182226d..f5843b3b036f0690c3c8585c946226d5906c298c 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/cmd/util/UUIDValidator.java +++ b/client/src/main/java/de/fitko/fitconnect/client/cmd/util/UUIDValidator.java @@ -22,4 +22,4 @@ public class UUIDValidator implements IParameterValidator { .matcher(value) .matches(); } -} \ No newline at end of file +} diff --git a/client/src/main/java/de/fitko/fitconnect/client/factory/ApplicationConfigLoader.java b/client/src/main/java/de/fitko/fitconnect/client/factory/ApplicationConfigLoader.java index ce7b0f3f6313918982f47f9249f67e58d942c40b..c3f4797781c5dd315224c5367e3b4e18f5912806 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/factory/ApplicationConfigLoader.java +++ b/client/src/main/java/de/fitko/fitconnect/client/factory/ApplicationConfigLoader.java @@ -8,9 +8,9 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -public class ApplicationConfigLoader { +public final class ApplicationConfigLoader { - private ApplicationConfigLoader(){} + private ApplicationConfigLoader() { } /** * Load ApplicationConfig from path. diff --git a/client/src/main/java/de/fitko/fitconnect/client/factory/ClientFactory.java b/client/src/main/java/de/fitko/fitconnect/client/factory/ClientFactory.java index 07103124d045d098dba76e16286d68a453f25bd6..ac682199a3d3da73f0bbd9ef84e20f791c60709c 100644 --- a/client/src/main/java/de/fitko/fitconnect/client/factory/ClientFactory.java +++ b/client/src/main/java/de/fitko/fitconnect/client/factory/ClientFactory.java @@ -37,9 +37,9 @@ import java.util.stream.Collectors; /** * Factory that constructs clients for {@link Sender} and {@link Subscriber}. */ -public class ClientFactory { +public final class ClientFactory { - private static final Logger logger = LoggerFactory.getLogger(ClientFactory.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ClientFactory.class); private static final String CONFIG_DEFAULT_LOCATION = "config.yml"; private static final String CUSTOM_CONFIG_KEY = "CONFIG_LOCATION"; @@ -66,11 +66,11 @@ public class ClientFactory { * @return the sender client */ public static SenderClient.WithDestination senderClient(final ApplicationConfig config) { - logger.info(SENDER_BANNER); - logger.info("Initializing sender client ..."); + LOGGER.info(SENDER_BANNER); + LOGGER.info("Initializing sender client ..."); final Sender sender = getSender(config); - logger.info("Reading metadata schema from {} ", config.getMetadataSchemaPath()); + LOGGER.info("Reading metadata schema from {} ", config.getMetadataSchemaPath()); final String metadataSchema = readPath(config.getMetadataSchemaPath()); return SenderClient.build(sender, metadataSchema, config.getCurrentEnvironment()); @@ -93,15 +93,15 @@ public class ClientFactory { * @return the subscriber client */ public static SubscriberClient.RequestSubmission subscriberClient(final ApplicationConfig config) { - logger.info(SUBSCRIBER_BANNER); - logger.info("Initializing subscriber client ..."); + LOGGER.info(SUBSCRIBER_BANNER); + LOGGER.info("Initializing subscriber client ..."); final Subscriber subscriber = getSubscriber(config); final SubscriberConfig subscriberConfig = config.getSubscriberConfig(); - logger.info("Reading private key from {} ", subscriberConfig.getPrivateDecryptionKeyPath()); + LOGGER.info("Reading private key from {} ", subscriberConfig.getPrivateDecryptionKeyPath()); final String privateKey = readPath(subscriberConfig.getPrivateDecryptionKeyPath()); - logger.info("Reading metadata schema from {} ", config.getMetadataSchemaPath()); + LOGGER.info("Reading metadata schema from {} ", config.getMetadataSchemaPath()); final String metadataSchema = readPath(config.getMetadataSchemaPath()); // TODO read SET-Event Token schema @@ -176,7 +176,7 @@ public class ClientFactory { } private static SecurityEventTokenService getSecurityEventTokenService(final ApplicationConfig config) { - logger.info("Reading private signing key from {} ", config.getPrivateSigningKeyPath()); + LOGGER.info("Reading private signing key from {} ", config.getPrivateSigningKeyPath()); final String signingKey = readPath(config.getPrivateSigningKeyPath()); return new SecurityEventTokenService(signingKey); } @@ -185,7 +185,7 @@ public class ClientFactory { try { return Files.readString(Path.of(pathName)); } catch (final IOException e) { - logger.error("Path {} could not be loaded", pathName); + LOGGER.error("Path {} could not be loaded", pathName); } return null; } @@ -194,7 +194,7 @@ public class ClientFactory { try { return System.getenv(variableName); } catch (final NullPointerException e) { - logger.error("Environment variable {} could not be loaded", variableName); + LOGGER.error("Environment variable {} could not be loaded", variableName); return null; } } @@ -211,7 +211,7 @@ public class ClientFactory { try { final Path pathToConfig = Path.of(configPath); final ApplicationConfig applicationConfig = ApplicationConfigLoader.loadConfig(pathToConfig); - logger.info("Using sdk environment config {} with {}", applicationConfig.getCurrentEnvironment(), applicationConfig); + LOGGER.info("Using sdk environment config {} with {}", applicationConfig.getCurrentEnvironment(), applicationConfig); return applicationConfig; } catch (final IOException e) { throw new IllegalStateException("Config could not be loaded, please provide a 'config.yml' in the root path or in the ENV-var 'CONFIG_LOCATION'", e); diff --git a/core/src/main/java/de/fitko/fitconnect/core/SubmissionSender.java b/core/src/main/java/de/fitko/fitconnect/core/SubmissionSender.java index 4342e03d335934462b0cfcfada56cffa7bf869af..d19332a82ccb5e075ac2a744b497e8f932ea1402 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/SubmissionSender.java +++ b/core/src/main/java/de/fitko/fitconnect/core/SubmissionSender.java @@ -29,7 +29,7 @@ import java.util.UUID; public class SubmissionSender implements Sender { - private static final Logger logger = LoggerFactory.getLogger(SubmissionSender.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SubmissionSender.class); private final ValidationService validationService; private final CryptoService cryptoService; @@ -55,7 +55,7 @@ public class SubmissionSender implements Sender { @Override public ValidationResult validatePublicKey(final RSAKey publicKey) { - logger.info("Validating public key integrity"); + LOGGER.info("Validating public key integrity"); return validationService.validatePublicKey(publicKey); } @@ -66,31 +66,31 @@ public class SubmissionSender implements Sender { @Override public String encryptBytes(final RSAKey publicKey, final byte[] data) { - logger.info("Encrypting ..."); + LOGGER.info("Encrypting ..."); return cryptoService.encryptBytes(publicKey, data); } @Override public String createHash(final byte[] data) { - logger.info("Creating hash ..."); + LOGGER.info("Creating hash ..."); return cryptoService.hashBytes(data); } @Override public SubmissionForPickup createSubmission(final CreateSubmission submission) { - logger.info("Creating new submission for destination {}", submission.getDestinationId()); + LOGGER.info("Creating new submission for destination {}", submission.getDestinationId()); return submissionService.announceSubmission(submission); } @Override public void uploadAttachment(final UUID submissionId, final UUID attachmentId, final String encryptedAttachment) { - logger.info("Uploading attachment(s) {} for submission {}", attachmentId, submissionId); + LOGGER.info("Uploading attachment(s) {} for submission {}", attachmentId, submissionId); submissionService.uploadAttachment(submissionId, attachmentId, encryptedAttachment); } @Override public RSAKey getEncryptionKeyForDestination(final UUID destinationId, final String encryptionKid) { - logger.info("Getting encryption key for destination id {}", destinationId); + LOGGER.info("Getting encryption key for destination id {}", destinationId); try { final JWK jwk = destinationService.getEncryptionKey(destinationId, encryptionKid); return RSAKey.parse(new ObjectMapper().writeValueAsString(jwk)); @@ -110,13 +110,13 @@ public class SubmissionSender implements Sender { @Override public void sendSubmission(final SubmitSubmission submission) { - logger.info("Sending submission {}", submission.getSubmissionId()); + LOGGER.info("Sending submission {}", submission.getSubmissionId()); submissionService.sendSubmission(submission); } @Override public Destination getDestination(final UUID destinationId) { - logger.info("Getting destination for id {}", destinationId); + LOGGER.info("Getting destination for id {}", destinationId); return destinationService.getDestination(destinationId); } @@ -124,7 +124,7 @@ public class SubmissionSender implements Sender { public void rejectSubmission(final UUID submissionId, final UUID destinationId, final UUID caseId) { final String rejectSubmissionEvent = securityEventService.createRejectSubmissionEvent(submissionId, destinationId, caseId); eventLogService.sendEvent(caseId, rejectSubmissionEvent); - logger.info("REJECTED submission {}", submissionId); + LOGGER.info("REJECTED submission {}", submissionId); } } diff --git a/core/src/main/java/de/fitko/fitconnect/core/SubmissionSubscriber.java b/core/src/main/java/de/fitko/fitconnect/core/SubmissionSubscriber.java index 4371d373ad7940563709ebca7f9397235204fabf..963ed559a505acf6a1490a5df4da85639418ea29 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/SubmissionSubscriber.java +++ b/core/src/main/java/de/fitko/fitconnect/core/SubmissionSubscriber.java @@ -19,7 +19,7 @@ import java.util.UUID; public class SubmissionSubscriber implements Subscriber { - private static final Logger logger = LoggerFactory.getLogger(SubmissionSubscriber.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SubmissionSubscriber.class); private final SubmissionService submissionService; private final CryptoService cryptoService; @@ -77,16 +77,16 @@ public class SubmissionSubscriber implements Subscriber { @Override public void confirmValidSubmission(final UUID submissionID, final UUID destinationId, final UUID caseId) { - final String confirmedSubmissionEvent = securityEventService.createAcceptSubmissionEvent(submissionID, destinationId,caseId); + final String confirmedSubmissionEvent = securityEventService.createAcceptSubmissionEvent(submissionID, destinationId, caseId); eventLogService.sendEvent(caseId, confirmedSubmissionEvent); - logger.info("CONFIRMED submission {} successfully", submissionID); + LOGGER.info("CONFIRMED submission {} successfully", submissionID); } @Override public void rejectSubmission(final UUID submissionId, final UUID destinationId, final UUID caseId) { final String rejectSubmissionEvent = securityEventService.createRejectSubmissionEvent(submissionId, destinationId, caseId); eventLogService.sendEvent(caseId, rejectSubmissionEvent); - logger.info("REJECTED submission {}", submissionId); + LOGGER.info("REJECTED submission {}", submissionId); } diff --git a/core/src/main/java/de/fitko/fitconnect/core/auth/DefaultOAuthService.java b/core/src/main/java/de/fitko/fitconnect/core/auth/DefaultOAuthService.java index 08da79e454f564e3e2d51e410f3a1b79e4c02a93..db38f08b07cdb381891ec3c89bbb32ebf56ba046 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/auth/DefaultOAuthService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/auth/DefaultOAuthService.java @@ -24,7 +24,7 @@ import static java.util.stream.Collectors.joining; public class DefaultOAuthService implements OAuthService { - private static final Logger logger = LoggerFactory.getLogger(DefaultOAuthService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultOAuthService.class); private final RestTemplate restTemplate; @@ -45,15 +45,15 @@ public class DefaultOAuthService implements OAuthService { @Override public synchronized OAuthToken getCurrentToken() throws RestApiException { - if(tokenExpired()){ - logger.info("Current token is expired, authenticating ..."); + if (tokenExpired()) { + LOGGER.info("Current token is expired, authenticating ..."); authenticate(); } return currentToken; } private boolean tokenExpired() { - if(currentToken == null || tokenExpirationTime == null){ + if (currentToken == null || tokenExpirationTime == null) { return true; } final var now = LocalDateTime.now(); @@ -99,7 +99,7 @@ public class DefaultOAuthService implements OAuthService { final HttpHeaders headers = getHeaders(); final HttpEntity<String> entity = new HttpEntity<>(requestBody, headers); try { - logger.info("Sending authentication request"); + LOGGER.info("Sending authentication request"); return restTemplate.exchange(tokenUrl, HttpMethod.POST, entity, OAuthToken.class).getBody(); } catch (final RestClientException e) { throw new RestApiException("Could not retrieve OAuth token", e); diff --git a/core/src/main/java/de/fitko/fitconnect/core/crypto/HashService.java b/core/src/main/java/de/fitko/fitconnect/core/crypto/HashService.java index d8158b9fa6b4ab982bdf1f703084393b42994bda..17070af66907c8f55803d755b320d33cbf2af16b 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/crypto/HashService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/crypto/HashService.java @@ -66,8 +66,8 @@ public class HashService implements MessageDigestService { private int toDigit(final char hexChar) { final int digit = Character.digit(hexChar, 16); - if(digit == -1) { - throw new IllegalArgumentException("Invalid Hexadecimal Character: "+ hexChar); + if (digit == -1) { + throw new IllegalArgumentException("Invalid Hexadecimal Character: " + hexChar); } return digit; } diff --git a/core/src/main/java/de/fitko/fitconnect/core/crypto/JWECryptoService.java b/core/src/main/java/de/fitko/fitconnect/core/crypto/JWECryptoService.java index 4ebd6c63d5750442629302ac449aacefe3a0173d..1eea483efead1d28ea715037eebd5bf30c57cb63 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/crypto/JWECryptoService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/crypto/JWECryptoService.java @@ -11,6 +11,7 @@ import de.fitko.fitconnect.api.services.crypto.MessageDigestService; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; + import java.security.NoSuchAlgorithmException; import java.text.ParseException; diff --git a/core/src/main/java/de/fitko/fitconnect/core/destination/DestinationRestService.java b/core/src/main/java/de/fitko/fitconnect/core/destination/DestinationRestService.java index 37723f5caf147d4282568ddd14c4070c8ea2a6a7..d4cdc5addcf4771b45837561fa7c09be466e6e55 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/destination/DestinationRestService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/destination/DestinationRestService.java @@ -21,7 +21,7 @@ public class DestinationRestService implements DestinationService { private final RestTemplate restTemplate; private final ApplicationConfig config; - public DestinationRestService(final OAuthService authService, final RestTemplate restTemplate, final ApplicationConfig config){ + public DestinationRestService(final OAuthService authService, final RestTemplate restTemplate, final ApplicationConfig config) { this.authService = authService; this.restTemplate = restTemplate; this.config = config; diff --git a/core/src/main/java/de/fitko/fitconnect/core/events/SecurityEventTokenService.java b/core/src/main/java/de/fitko/fitconnect/core/events/SecurityEventTokenService.java index e4264cf1db35bfc61f2c20d8bd54bdea99683b3f..9eb25b5f79620a960e27f99da53c95e9b9ff13b1 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/events/SecurityEventTokenService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/events/SecurityEventTokenService.java @@ -45,7 +45,7 @@ public class SecurityEventTokenService implements SecurityEventService { validateRSAKey(signingKey); final JWSSigner signer = getJwsSigner(signingKey); - final JWTClaimsSet claimsSet = getJwtClaimsSet(ACCEPT_EVENT, destinationId.toString(),transactionId, subject); + final JWTClaimsSet claimsSet = getJwtClaimsSet(ACCEPT_EVENT, destinationId.toString(), transactionId, subject); final JWSHeader header = getJwsHeader(signingKey); final SignedJWT signedJWT = new SignedJWT(header, claimsSet); @@ -67,13 +67,13 @@ public class SecurityEventTokenService implements SecurityEventService { private JWSHeader getJwsHeader(final JWK signingKey) { - try{ + try { return JWSHeader.parse(Map.of( "typ", "secevent+jwt", "kid", signingKey.getKeyID(), "alg", "PS512" )); - }catch(final ParseException e){ + } catch (final ParseException e) { throw new EventCreationException("Parsing JWS header failed", e); } } @@ -111,7 +111,7 @@ public class SecurityEventTokenService implements SecurityEventService { } } - public static void validateRSAKey(final RSAKey rsaKey){ + public static void validateRSAKey(final RSAKey rsaKey) { validateTrueOrElseThrow(rsaKey.getModulus().decodeToBigInteger().bitLength() >= 4096, "JWK has wrong key length."); validateTrueOrElseThrow(rsaKey.getAlgorithm().equals(JWSAlgorithm.PS512), "The specified public key does not use PS512 as algorithm."); //validateTrueOrElseThrow(RSAKey.getKeyOperations().size() == 1 && RSAKey.getKeyOperations().contains(KeyOperation.VERIFY), "The specified public key is not intended for 'verify' as specified through key operation."); diff --git a/core/src/main/java/de/fitko/fitconnect/core/http/ApiRequestInterceptor.java b/core/src/main/java/de/fitko/fitconnect/core/http/ApiRequestInterceptor.java index 1cfed10367688796b8bd5061a71c053005f6b739..6802ff6c0519cef9a102060a7e66ab678066e049 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/http/ApiRequestInterceptor.java +++ b/core/src/main/java/de/fitko/fitconnect/core/http/ApiRequestInterceptor.java @@ -14,12 +14,12 @@ import java.io.IOException; */ public class ApiRequestInterceptor implements ClientHttpRequestInterceptor { - private static final Logger logger = LoggerFactory.getLogger(ApiRequestInterceptor.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ApiRequestInterceptor.class); @Override public ClientHttpResponse intercept(final HttpRequest req, final byte[] reqBody, final ClientHttpRequestExecution ex) throws IOException { - logger.info("{}", req.getURI()); + LOGGER.info("{}", req.getURI()); return ex.execute(req, reqBody); } -} \ No newline at end of file +} diff --git a/core/src/main/java/de/fitko/fitconnect/core/http/ProxyConfig.java b/core/src/main/java/de/fitko/fitconnect/core/http/ProxyConfig.java index f514ce578f39b81c830581ea7bd4cc200d282f64..4f6a8c0a962e5ac007159bb47762377abae6eb52 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/http/ProxyConfig.java +++ b/core/src/main/java/de/fitko/fitconnect/core/http/ProxyConfig.java @@ -13,7 +13,7 @@ import java.util.List; public class ProxyConfig { - private static final Logger logger = LoggerFactory.getLogger(ProxyConfig.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProxyConfig.class); private final String host; private final int port; @@ -25,13 +25,13 @@ public class ProxyConfig { public RestTemplate proxyRestTemplate() { if (!hasProxySet()) { - logger.info("No proxy configured"); + LOGGER.info("No proxy configured"); final RestTemplate restTemplate = new RestTemplate(); setLoggingInterceptor(restTemplate); return restTemplate; } - logger.info("Using proxy {}", this); + LOGGER.info("Using proxy {}", this); final var requestFactory = new SimpleClientHttpRequestFactory(); final var proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); requestFactory.setProxy(proxy); @@ -54,4 +54,4 @@ public class ProxyConfig { public String toString() { return String.format("ProxyConfig {host='%s', port=%d}", host, port); } -} \ No newline at end of file +} diff --git a/core/src/main/java/de/fitko/fitconnect/core/http/X509CRLHttpMessageConverter.java b/core/src/main/java/de/fitko/fitconnect/core/http/X509CRLHttpMessageConverter.java index 1c677f3402f056c0ecdeba4f901b5adccce54837..9613a614314bc3256bf68647c25b5b4d7a9ac1da 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/http/X509CRLHttpMessageConverter.java +++ b/core/src/main/java/de/fitko/fitconnect/core/http/X509CRLHttpMessageConverter.java @@ -18,25 +18,25 @@ public class X509CRLHttpMessageConverter extends AbstractHttpMessageConverter<X5 } @Override - protected boolean supports(@NonNull Class<?> clazz) { + protected boolean supports(@NonNull final Class<?> clazz) { return X509CRL.class == clazz; } @Override - protected X509CRL readInternal(@NonNull Class<? extends X509CRL> clazz, @NonNull HttpInputMessage inputMessage) + protected X509CRL readInternal(@NonNull final Class<? extends X509CRL> clazz, @NonNull final HttpInputMessage inputMessage) throws HttpMessageNotReadableException { try { - var cf = CertificateFactory.getInstance("X.509"); + final var cf = CertificateFactory.getInstance("X.509"); return (X509CRL) cf.generateCRL(inputMessage.getBody()); - } catch (Exception e) { + } catch (final Exception e) { throw new HttpMessageNotReadableException("CertificateFactory of type X.509 could not be created", inputMessage); } } @Override - protected void writeInternal(@NonNull X509CRL x509CRL, @NonNull HttpOutputMessage outputMessage) + protected void writeInternal(@NonNull final X509CRL x509CRL, @NonNull final HttpOutputMessage outputMessage) throws HttpMessageNotWritableException { throw new HttpMessageNotWritableException("Writing X509CRL is not supported in ProxyRestTemplate"); } -} \ No newline at end of file +} diff --git a/core/src/main/java/de/fitko/fitconnect/core/submission/SubmissionApiService.java b/core/src/main/java/de/fitko/fitconnect/core/submission/SubmissionApiService.java index 1d145480e0e9ae50f29c715dee19692cbd2fffb0..813c1b3567491545b6f6e02368dae703355daa8d 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/submission/SubmissionApiService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/submission/SubmissionApiService.java @@ -129,7 +129,7 @@ public class SubmissionApiService implements SubmissionService { .responseType(Submission.class) .entity(getHttpEntity(getHeaders())) .params(params) - .errorMessage("Submission with id "+ submissionId +" does not exist") + .errorMessage("Submission with id " + submissionId + " does not exist") .build(); return performRequest(requestSettings); } @@ -152,7 +152,9 @@ public class SubmissionApiService implements SubmissionService { } private HttpEntity<String> getHttpEntity(final Object body, final HttpHeaders headers) { - if(body == null ) return new HttpEntity<>(headers); + if (body == null) { + return new HttpEntity<>(headers); + } try { return getHttpEntity(new ObjectMapper().writeValueAsString(body), headers); } catch (final JsonProcessingException e) { diff --git a/core/src/main/java/de/fitko/fitconnect/core/util/Preconditions.java b/core/src/main/java/de/fitko/fitconnect/core/util/Preconditions.java index ea9677126646d63ea3951792dea69c7691caf419..318d163b2bf7b951cd127a21269673eebe1c97b2 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/util/Preconditions.java +++ b/core/src/main/java/de/fitko/fitconnect/core/util/Preconditions.java @@ -2,9 +2,10 @@ package de.fitko.fitconnect.core.util; import java.util.function.Supplier; -public class Preconditions { +public final class Preconditions { - private Preconditions() {} + private Preconditions() { + } /** * Throws a supplied (runtime) exception if the expression evaluates to false diff --git a/core/src/main/java/de/fitko/fitconnect/core/util/Strings.java b/core/src/main/java/de/fitko/fitconnect/core/util/Strings.java index 4dd79e64189698b6b3f9597cf5753f6bf16316ff..217fdc9acd1066496051154b6cf71a340b6d0289 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/util/Strings.java +++ b/core/src/main/java/de/fitko/fitconnect/core/util/Strings.java @@ -1,15 +1,16 @@ package de.fitko.fitconnect.core.util; -public class Strings { +public final class Strings { - private Strings() {} + private Strings() { + } /** * Tests a given string on null or empty * @param s string to test * @return true if the string is null OR empty, false if both conditions do not apply */ - public static boolean isNullOrEmpty(final String s){ + public static boolean isNullOrEmpty(final String s) { return s == null || s.isEmpty(); } @@ -18,7 +19,7 @@ public class Strings { * @param s string to test * @return true if the string is not null AND not empty, false if one condition does not apply */ - public static boolean isNotNullOrEmpty(final String s){ + public static boolean isNotNullOrEmpty(final String s) { return !isNullOrEmpty(s); } diff --git a/core/src/main/java/de/fitko/fitconnect/core/validation/DefaultValidationService.java b/core/src/main/java/de/fitko/fitconnect/core/validation/DefaultValidationService.java index 313f037aba413c6b511f5a0dd9bebd288612aff3..aaf6f8be9bb1665377f81b9b492761f2774b938e 100644 --- a/core/src/main/java/de/fitko/fitconnect/core/validation/DefaultValidationService.java +++ b/core/src/main/java/de/fitko/fitconnect/core/validation/DefaultValidationService.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; public class DefaultValidationService implements ValidationService { - private static final Logger logger = LoggerFactory.getLogger(DefaultValidationService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultValidationService.class); private final MessageDigestService messageDigestService; private final ApplicationConfig config; @@ -93,7 +93,7 @@ public class DefaultValidationService implements ValidationService { private void validateWithX509AndProxy(final List<String> pemCerts, final RSAKey publicKey) throws JWKValidationException { final var proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(config.getHttpProxyHost(), config.getHttpProxyPort())); - logger.info("Using proxy {} for key validation", proxy); + LOGGER.info("Using proxy {} for key validation", proxy); JWKValidator.withX5CValidation() .withProxy(proxy) .withRootCertificatesAsPEM(pemCerts) @@ -103,7 +103,7 @@ public class DefaultValidationService implements ValidationService { } private void validateWithX509AndWithoutProxy(final List<String> pemCerts, final RSAKey publicKey) throws JWKValidationException { - logger.info("No proxy set for validation"); + LOGGER.info("No proxy set for validation"); JWKValidator.withX5CValidation() .withoutProxy() .withRootCertificatesAsPEM(pemCerts) @@ -113,13 +113,13 @@ public class DefaultValidationService implements ValidationService { } private void validateWithoutCertChain(final RSAKey publicKey) throws JWKValidationException { - logger.info("Validation public key without XC5 certificate chain"); + LOGGER.info("Validation public key without XC5 certificate chain"); JWKValidator.withoutX5CValidation().build().validate(publicKey); } private void validateCertChain(final RSAKey publicKey) throws JWKValidationException, CertificateEncodingException { final List<String> pemCerts = getPemCerts(publicKey.getParsedX509CertChain()); - logger.info("Validation public key with XC5 certificate chain checks"); + LOGGER.info("Validation public key with XC5 certificate chain checks"); if (isProxySet()) { validateWithX509AndProxy(pemCerts, publicKey); } else { diff --git a/pom.xml b/pom.xml index 4be22d201588c12a91e9b29926216443bf50f676..c96ae95032fab0a6c7c1cfbdd48d5372992c9ac7 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,9 @@ <maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version> <maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version> <maven-failsafe-plugin.version>3.0.0-M7</maven-failsafe-plugin.version> - <maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version> + <maven-checkstyle-plugin.version>3.2.0</maven-checkstyle-plugin.version> + <maven-jar-plugin.version>3.2.2</maven-jar-plugin.version> + <maven-shade-plugin.version>3.3.0</maven-shade-plugin.version> </properties> @@ -184,6 +186,38 @@ <artifactId>maven-failsafe-plugin</artifactId> <version>${maven-failsafe-plugin.version}</version> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>${maven-jar-plugin.version}</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>${maven-shade-plugin.version}</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <version>${maven-checkstyle-plugin.version}</version> + <configuration> + <configLocation>checkstyle.xml</configLocation> + </configuration> + <executions> + <execution> + <id>verify</id> + <phase>verify</phase> + <configuration> + <suppressionsLocation> + checkstyle-suppressions.xml + </suppressionsLocation> + </configuration> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </pluginManagement> </build>