Skip to content

Commit 78c1ac5

Browse files
metsmamrts
authored andcommitted
Use java 17 for SonarCloud
WE2-841 Signed-off-by: Raul Metsma <[email protected]>
1 parent c919aa5 commit 78c1ac5

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed

.github/workflows/sonarcloud-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
with:
1414
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
15-
- name: Set up JDK 11
15+
- name: Set up JDK 17
1616
uses: actions/setup-java@v3
1717
with:
1818
distribution: zulu
19-
java-version: 11
19+
java-version: 17
2020
- name: Cache SonarCloud packages
2121
uses: actions/cache@v3
2222
with:
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
path: ~/.m2
3030
key: ${{ runner.os }}-m2-v11-${{ hashFiles('**/pom.xml') }}
31-
restore-keys: ${{ runner.os }}-m2-v11
31+
restore-keys: ${{ runner.os }}-m2-v17
3232
- name: Build and analyze
3333
env:
3434
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
2323
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
2424
<maven-javadoc-plugin.version>3.6.2</maven-javadoc-plugin.version>
25-
<jacoco.version>0.8.5</jacoco.version>
25+
<jacoco.version>0.8.8</jacoco.version>
2626
<sonar.coverage.jacoco.xmlReportPaths>
2727
${project.basedir}/../jacoco-coverage-report/target/site/jacoco-aggregate/jacoco.xml
2828
</sonar.coverage.jacoco.xmlReportPaths>

src/main/java/eu/webeid/security/util/DateAndTime.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ public static void requirePositiveDuration(Duration duration, String fieldName)
4545

4646
public static class DefaultClock implements Clock {
4747

48-
public static final Clock INSTANCE = new DefaultClock();
48+
protected static Clock instance = new DefaultClock();
49+
50+
public static Clock getInstance() {
51+
return instance;
52+
}
4953

5054
@Override
5155
public Date now() {

src/main/java/eu/webeid/security/validator/certvalidators/SubjectCertificateExpiryValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public SubjectCertificateExpiryValidator(Set<TrustAnchor> trustedCACertificateAn
5252
*/
5353
public void validateCertificateExpiry(X509Certificate subjectCertificate) throws AuthTokenException {
5454
// Use the clock instance so that the date can be mocked in tests.
55-
final Date now = DateAndTime.DefaultClock.INSTANCE.now();
55+
final Date now = DateAndTime.DefaultClock.getInstance().now();
5656
CertificateValidator.trustedCACertificatesAreValidOnDate(trustedCACertificateAnchors, now);
5757
LOG.debug("CA certificates are valid.");
5858
CertificateValidator.certificateIsValidOnDate(subjectCertificate, now, "User");

src/main/java/eu/webeid/security/validator/certvalidators/SubjectCertificateTrustedValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public SubjectCertificateTrustedValidator(Set<TrustAnchor> trustedCACertificateA
5656
*/
5757
public void validateCertificateTrusted(X509Certificate subjectCertificate) throws AuthTokenException {
5858
// Use the clock instance so that the date can be mocked in tests.
59-
final Date now = DateAndTime.DefaultClock.INSTANCE.now();
59+
final Date now = DateAndTime.DefaultClock.getInstance().now();
6060
subjectCertificateIssuerCertificate = CertificateValidator.validateIsSignedByTrustedCA(
6161
subjectCertificate,
6262
trustedCACertificateAnchors,

src/test/java/eu/webeid/security/testutil/Dates.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ public static void resetMockedCertificateValidatorDate() throws NoSuchFieldExcep
4747
}
4848

4949
private static void setClockField(Class<? extends Clock> cls, Date date) throws NoSuchFieldException, IllegalAccessException {
50-
final Field clockField = cls.getDeclaredField("INSTANCE");
50+
final Field clockField = cls.getDeclaredField("instance");
5151
setFinalStaticField(clockField, (Clock) () -> date);
5252
}
5353

5454
private static void setFinalStaticField(Field field, Object newValue) throws NoSuchFieldException, IllegalAccessException {
5555
field.setAccessible(true);
5656

57+
/* https://stackoverflow.com/questions/56039341/get-declared-fields-of-java-lang-reflect-fields-in-jdk12
5758
final Field modifiersField = Field.class.getDeclaredField("modifiers");
5859
modifiersField.setAccessible(true);
5960
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
61+
*/
6062

6163
field.set(null, newValue);
6264
}

src/test/java/eu/webeid/security/validator/certvalidators/SubjectCertificateNotRevokedValidatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ void whenOcspUrlIsInvalid_thenThrows() throws Exception {
114114

115115
@Test
116116
void whenOcspRequestFails_thenThrows() throws Exception {
117-
final OcspServiceProvider ocspServiceProvider = getDesignatedOcspServiceProvider("https://web-eid-test.free.beeceptor.com");
117+
final OcspServiceProvider ocspServiceProvider = getDesignatedOcspServiceProvider("http://demo.sk.ee/ocsps");
118118
final SubjectCertificateNotRevokedValidator validator = new SubjectCertificateNotRevokedValidator(trustedValidator, ocspClient, ocspServiceProvider);
119119
assertThatCode(() ->
120120
validator.validateCertificateNotRevoked(estEid2018Cert))
121121
.isInstanceOf(UserCertificateOCSPCheckFailedException.class)
122122
.cause()
123123
.isInstanceOf(IOException.class)
124-
.hasMessageStartingWith("OCSP request was not successful, response: (POST https://web-eid-test.free.beeceptor.com) 404");
124+
.hasMessageStartingWith("OCSP request was not successful, response: (POST http://demo.sk.ee/ocsps) 404");
125125
}
126126

127127
@Test

0 commit comments

Comments
 (0)