Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void start() {
if (!responseStatus.getOutstandingComponents().isEmpty()) {
if (getTimeoutValue().compareTo(Duration.ZERO) > 0) { // TODO From Java 18 use: getTimeoutValue().isPositive()
CountAndTimeUnit delay = TimeUtils.durationToCountAndTimeUnit(getTimeoutValue());
scheduledTimeout = timer.schedule(new TimeoutHandler(), delay.getCount(), delay.getUnit());
scheduledTimeout = timer.schedule(new TimeoutHandler(), delay.count(), delay.unit());
}
sendRequest();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,23 @@
*/
package org.bitrepository.client.conversation.selector;

import org.jetbrains.annotations.NotNull;

/**
* Container for information about a pillar which as been identified and are marked as selected for a request.
* Container for information about a pillar which has been identified and marked as selected for a request.
*/
public class SelectedComponentInfo {
/**
* The ID of the selected pillar
*/
protected final String componentID;
/**
* The topic for communication with the selected pillar
*/
protected final String componentTopic;

/**
* @param componentID The ID of the pillar
* @param componentTopic the topic for communication with the selected pillar
*/
public SelectedComponentInfo(String componentID, String componentTopic) {
super();
this.componentID = componentID;
this.componentTopic = componentTopic;
}
public record SelectedComponentInfo(String componentID, String componentTopic) {

/**
* @return The ID of the pillar chosen by this selector if finished. If unfinished null is returned
*/
public String getID() {
return componentID;
}

/**
* @return If finished return the topic for sending messages to the pillar chosen by this selector.
* If unfinished null is returned
*/
public String getDestination() {
return componentTopic;
}

@Override
public String toString() {
return getClass().getSimpleName() + ": componentID=" + componentID + ", componentTopic=" + componentTopic;
public @NotNull String toString() {
return "SelectedComponentInfo: componentID=" + componentID + ", componentTopic=" + componentTopic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public abstract class CompleteEventAwaiter implements EventHandler {
* @param settings The settings.
* @param outputHandler The {@link OutputHandler} for handling outputting results
*/
public CompleteEventAwaiter(Settings settings, OutputHandler outputHandler) {
protected CompleteEventAwaiter(Settings settings, OutputHandler outputHandler) {
this.timeout = settings.getIdentificationTimeout().plus(settings.getOperationTimeout());
this.output = outputHandler;
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public void handleEvent(OperationEvent event) {
public OperationEvent getFinish() {
try {
CountAndTimeUnit pollTimeout = TimeUtils.durationToCountAndTimeUnit(timeout);
return finalEventQueue.poll(pollTimeout.getCount(), pollTimeout.getUnit());
return finalEventQueue.poll(pollTimeout.count(), pollTimeout.unit());
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted while waiting for the final response.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void handleEvent(OperationEvent event) {
public OperationEvent getFinish() {
try {
CountAndTimeUnit pollTimeout = TimeUtils.durationToCountAndTimeUnit(timeout);
return finalEventQueue.poll(pollTimeout.getCount(), pollTimeout.getUnit());
return finalEventQueue.poll(pollTimeout.count(), pollTimeout.unit());
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted while waiting for the final response.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@
/**
* File info for the files of a default file system.
*/
public class DefaultFileInfo implements FileInfo {
private final File file;

public DefaultFileInfo(File file) {
this.file = file;
}
public record DefaultFileInfo(File file) implements FileInfo {

@Override
public String getFileID() {
Expand All @@ -55,8 +50,4 @@ public Long getLastModifiedDate() {
public long getSize() {
return file.length();
}

public File getFile() {
return file;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,8 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class CountAndTimeUnit {
private final long count;
private final TimeUnit unit;

public CountAndTimeUnit(long count, TimeUnit unit) {
this.count = count;
this.unit = Objects.requireNonNull(unit, "unit");
}

public long getCount() {
return count;
}

public TimeUnit getUnit() {
return unit;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CountAndTimeUnit that = (CountAndTimeUnit) o;
return count == that.count && unit == that.unit;
}

@Override
public int hashCode() {
return Objects.hash(count, unit);
public record CountAndTimeUnit(long count, TimeUnit unit) {
public CountAndTimeUnit {
Objects.requireNonNull(unit, "unit");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,4 @@
/**
* Contains information about the message, not contained in the message itself.
*/
public class MessageContext {
private final String certificateFingerprint;

public MessageContext(String certificateFingerprint) {
this.certificateFingerprint = certificateFingerprint;
}

public String getCertificateFingerprint() {
return certificateFingerprint;
}
}
public record MessageContext(String certificateFingerprint) {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,80 +28,19 @@
import java.math.BigInteger;

/**
* Class to be used as an identifier of certificates.
* Identification is based on the issuer (X500Principal) and the certificates serial number.
* Those combined should provide a unique ID, and the information can be extracted from a signature.
* Identifies a certificate by issuer (X500Principal) and serial number.
* Those combined provide a unique ID extractable from a signature.
*/
public class CertificateID {
private final X500Principal issuer;
private final BigInteger serial;
public record CertificateID(X500Principal issuer, BigInteger serial) {

/**
* @param issuer The X500Principal object that identifies the certificate issuer.
* Can be extracted from a SignerID and a X509Certificate
* @param serialNumber The certificates SerialNumber, ca be extracted from a SignerID and a X509Certificate
* Creates a CertificateID from an X500Name issuer, converting it to X500Principal.
*/
public CertificateID(X500Principal issuer, BigInteger serialNumber) {
this.issuer = issuer;
this.serial = serialNumber;
}

public CertificateID(X500Name issuer, BigInteger serialNumber) {
public static CertificateID of(X500Name issuer, BigInteger serialNumber) {
try {
this.issuer = new X500Principal(issuer.getEncoded());
return new CertificateID(new X500Principal(issuer.getEncoded()), serialNumber);
} catch (IOException e) {
throw new RuntimeException("Failed to create X500Principal from X500Name", e);
}
this.serial = serialNumber;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((issuer == null) ? 0 : issuer.hashCode());
result = prime * result + ((serial == null) ? 0 : serial.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CertificateID other = (CertificateID) obj;
if (issuer == null) {
if (other.issuer != null)
return false;
} else if (!issuer.equals(other.issuer))
return false;
if (serial == null) {
return other.serial == null;
} else return serial.equals(other.serial);
}

@Override
public String toString() {
return "CertificateID [issuer=" + issuer + ", serial=" + serial + "]";
}

/**
* @return Identifying object of the issuer of a certificate
* @see CertificateID constructor
*/
public X500Principal getIssuer() {
return issuer;
}

/**
* @return The serial number of a certificate (unique within an issuer)
* @see CertificateID constructor
*/
public BigInteger getSerial() {
return serial;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void loadPermissions(PermissionSet permissions, String componentID) {
* @throws PermissionStoreException if no certificate can be found based on the SignerId
*/
public X509Certificate getCertificate(SignerId signer) throws PermissionStoreException {
CertificateID certificateID = new CertificateID(signer.getIssuer(), signer.getSerialNumber());
CertificateID certificateID = CertificateID.of(signer.getIssuer(), signer.getSerialNumber());
CertificatePermission permission = permissionMap.get(certificateID);
if (permission != null) {
return permission.getCertificate();
Expand All @@ -150,7 +150,7 @@ public X509Certificate getCertificate(SignerId signer) throws PermissionStoreExc
* @throws PermissionStoreException in case no certificate has been registered for the given signerId
*/
public boolean checkCertificateUser(SignerId signer, String certificateUser) throws PermissionStoreException {
CertificateID certificateID = new CertificateID(signer.getIssuer(), signer.getSerialNumber());
CertificateID certificateID = CertificateID.of(signer.getIssuer(), signer.getSerialNumber());
CertificatePermission certificatePermission = permissionMap.get(certificateID);
if (certificatePermission == null) {
throw new PermissionStoreException("Failed to find certificate and permissions for the requested signer: " + certificateID);
Expand All @@ -165,7 +165,7 @@ public boolean checkCertificateUser(SignerId signer, String certificateUser) thr
* @throws UnregisteredPermissionException No finger-print could be found for the indicated signer.
*/
public String getCertificateFingerprint(SignerId signer) throws UnregisteredPermissionException {
CertificateID certificateID = new CertificateID(signer.getIssuer(), signer.getSerialNumber());
CertificateID certificateID = CertificateID.of(signer.getIssuer(), signer.getSerialNumber());
CertificatePermission certificatePermission = permissionMap.get(certificateID);
if (certificatePermission != null) {
return certificatePermission.getFingerprint();
Expand All @@ -185,7 +185,7 @@ public String getCertificateFingerprint(SignerId signer) throws UnregisteredPerm
* @throws PermissionStoreException in case no certificate and permission set can be found for the provided signer.
*/
public boolean checkPermission(SignerId signer, Operation permission, String collectionID) throws PermissionStoreException {
CertificateID certificateID = new CertificateID(signer.getIssuer(), signer.getSerialNumber());
CertificateID certificateID = CertificateID.of(signer.getIssuer(), signer.getSerialNumber());
CertificatePermission certificatePermission = permissionMap.get(certificateID);
if (certificatePermission == null) {
throw new PermissionStoreException("Failed to find certificate and permissions for the requested signer: " + certificateID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ void rejectsNegativeDuration() {
@Tag("regressiontest")
void convertsDurationToCountAndTimeUnit() {
CountAndTimeUnit expectedZero = TimeUtils.durationToCountAndTimeUnit(Duration.ZERO);
Assertions.assertEquals(0, expectedZero.getCount());
Assertions.assertNotNull(expectedZero.getUnit());
Assertions.assertEquals(0, expectedZero.count());
Assertions.assertNotNull(expectedZero.unit());

Assertions.assertEquals(new CountAndTimeUnit(1, TimeUnit.NANOSECONDS),
TimeUtils.durationToCountAndTimeUnit(Duration.ofNanos(1)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void positiveCertificateIdentificationTest() throws Exception {
CMSSignedData s = new CMSSignedData(new CMSProcessableByteArray(
SecurityTestConstants.getTestData().getBytes(SecurityModuleConstants.defaultEncodingType)), decodeSig);
SignerInformation signer = s.getSignerInfos().getSigners().iterator().next();
CertificateID certificateIDFromSignature = new CertificateID(signer.getSID().getIssuer(), signer.getSID().getSerialNumber());
CertificateID certificateIDFromSignature = CertificateID.of(signer.getSID().getIssuer(), signer.getSID().getSerialNumber());

addStep("Assert that the two CertificateID objects are equal", "Assert succeeds");
Assertions.assertEquals(certificateIDfromCertificate, certificateIDFromSignature);
Expand All @@ -81,7 +81,7 @@ void negativeCertificateIdentificationTest() throws Exception {
CMSSignedData s = new CMSSignedData(new CMSProcessableByteArray(
SecurityTestConstants.getTestData().getBytes(SecurityModuleConstants.defaultEncodingType)), decodeSig);
SignerInformation signer = s.getSignerInfos().getSigners().iterator().next();
CertificateID certificateIDFromSignature = new CertificateID(signer.getSID().getIssuer(), signer.getSID().getSerialNumber());
CertificateID certificateIDFromSignature = CertificateID.of(signer.getSID().getIssuer(), signer.getSID().getSerialNumber());

addStep("Assert that the two CertificateID objects are not equal", "Assert succeeds");
Assertions.assertNotSame(certificateIDFromCertificate, certificateIDFromSignature);
Expand All @@ -100,8 +100,8 @@ void equalTest() throws Exception {
CertificateID certificateID1 = new CertificateID(issuer, serial);

addStep("Validate the content of the certificateID", "Should be same as x509Certificate");
Assertions.assertEquals(issuer, certificateID1.getIssuer());
Assertions.assertEquals(serial, certificateID1.getSerial());
Assertions.assertEquals(issuer, certificateID1.issuer());
Assertions.assertEquals(serial, certificateID1.serial());

addStep("Test whether it equals it self", "should give positive result");
Assertions.assertEquals(certificateID1, certificateID1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,18 @@
import java.time.Instant;

/**
* Class to carry information of collection specific pillar metrics.
* The class exists as java is not able to handle simple tuples,
* so the class is meant to carry data in a specific context.
* Carries collection-specific pillar metrics.
*
* @see org.bitrepository.integrityservice.cache.database.IntegrityDAO#getPillarCollectionMetrics(String)
*/
public class PillarCollectionMetric {

/**
* The summed size of the files in a collection on the pillar.
*/
private final long pillarCollectionSize;

/**
* The count of files present in a collection on a pillar
*/
private final long pillarFileCount;

/** Timestamp of the oldest checksum on the pillar or null if no checksums yet */
private final Instant oldestChecksumTimestamp;
public record PillarCollectionMetric(long pillarCollectionSize, long pillarFileCount, Instant oldestChecksumTimestamp) {

/** Convenience constructor that treats null sizes/counts as zero. */
public PillarCollectionMetric(Long pillarCollectionSize, Long pillarFileCount, Instant oldestChecksumTimestamp) {
this.pillarCollectionSize = pillarCollectionSize == null ? 0 : pillarCollectionSize;
this.pillarFileCount = pillarFileCount == null ? 0 : pillarFileCount;
this.oldestChecksumTimestamp = oldestChecksumTimestamp;
}

public long getPillarCollectionSize() {
return pillarCollectionSize;
}

public long getPillarFileCount() {
return pillarFileCount;
}

public Instant getOldestChecksumTimestamp() {
return oldestChecksumTimestamp;
this(
pillarCollectionSize == null ? 0L : pillarCollectionSize,
pillarFileCount == null ? 0L : pillarFileCount,
oldestChecksumTimestamp
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
/**
* Provide easy access to the MaxChecksumAge for individual pillars.
*/
public class MaxChecksumAgeProvider {
private final Duration defaultMaxAge;
private final ObsoleteChecksumSettings settings;
public record MaxChecksumAgeProvider(Duration defaultMaxAge, ObsoleteChecksumSettings settings) {

public MaxChecksumAgeProvider(Duration defaultMaxAge, ObsoleteChecksumSettings settings) {
this.defaultMaxAge = Objects.requireNonNull(defaultMaxAge, "defaultMaxAge");
this.settings = settings;
public MaxChecksumAgeProvider {
Objects.requireNonNull(defaultMaxAge, "defaultMaxAge");
}

/**
Expand Down
Loading