Skip to content

Commit

Permalink
IntelliJ warnings + migration aids resolved.
Browse files Browse the repository at this point in the history
  • Loading branch information
leeN committed Sep 3, 2024
1 parent 8b55851 commit 263e448
Show file tree
Hide file tree
Showing 59 changed files with 262 additions and 318 deletions.
7 changes: 1 addition & 6 deletions fontus/src/main/java/com/sap/fontus/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ public final class Main implements Callable<Void> {
)
private File outputFile;

@CommandLine.Option(
names = {"--instrumented-classes"},
required = true,
paramLabel = "Instrumented Classes",
description = "Output file which contains a list of all instrumented classes"
)
@CommandLine.Option(names = "--instrumented-classes", required = true, paramLabel = "Instrumented Classes", description = "Output file which contains a list of all instrumented classes")
private File instrumentedClasses;

@CommandLine.Option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@

/**
* AgentClassResolvers have been split into the following hierarchy:
*
* <p>
* IClassResolver
* |-AgentClassResolver
* |-CachingAgentClassResolver
* |-CallingThreadAgentClassResolver
* |-BackgroundAgentClassResolver
* |-SingleThreadAgentClassResolver
* |-ParallelAgentClassResolver
*
* <p>
* The AgentClassResolver is simple and keeps a single cache to itself for resolvedClasses.
* No pre-loading is performed.
*
* <p>
* The CachingAgentClassResolver attempts to pre-load classes from the classloader into
* the BytecodeRegistry during the initialize() method. This can be performed either
* on the calling thread or in the background.
*
* <p>
* The CallingThreadAgentClassResolver pre-caches all classes using the calling thread during
* initialization, which may block execution if there are a lot of classes to load or some
* are unreachable.
*
* <p>
* The BackgroundAgentClassResolver pre-caches classes using executors in two ways:
*
* <p>
* The SingleThreadAgentClassResolver pre-loads classes using a single thread in the background,
* but then wait for the thread to terminate, with a timeout. The behaviour should be similar to
* that of the CallingThreadAgentClassResolver, except with a timeout. This resolver in some cases
* caused execution to hang (until the timeout) which needs invesitgation.
*
* <p>
* The ParallelAgentClassResolver loads classes using a thread pool, and does not wait for pre-caching
* to complete before exiting the initialize method.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public DataProtection() {
}

public DataProtection(List<String> vendors, List<String> purposes, List<String> aborts) {
this.vendors = vendors.stream().map(vendor -> vendor.trim()).collect(Collectors.toList());
this.purposes = purposes.stream().map(purpose -> purpose.trim()).collect(Collectors.toList());
this.aborts = aborts.stream().map(abort -> abort.trim()).collect(Collectors.toList());
this.vendors = vendors.stream().map(String::trim).toList();
this.purposes = purposes.stream().map(String::trim).toList();
this.aborts = aborts.stream().map(String::trim).toList();
}

public List<String> getVendors() {
Expand Down
16 changes: 7 additions & 9 deletions fontus/src/main/java/com/sap/fontus/gdpr/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ private static <A> A processGdprMetaData(IASTaintInformationable taintInformatio

for(IASTaintRange range: taintRanges) {
IASTaintMetadata meta = range.getMetadata();
if(meta instanceof GdprTaintMetadata) {
GdprTaintMetadata gdprTaintMetadata = (GdprTaintMetadata) meta;
if(meta instanceof GdprTaintMetadata gdprTaintMetadata) {
GdprMetadata gdprMetadata = gdprTaintMetadata.getMetadata();
accumulator = function.apply(accumulator, gdprMetadata);
}
Expand All @@ -73,8 +72,7 @@ public static boolean checkPolicyViolation(RequiredPurposes required, IASString
PurposePolicy policy = new SimplePurposePolicy();
for (IASTaintRange range : tainted.getTaintInformation().getTaintRanges(tainted.getString().length())) {
// Check policy for each range
if (range.getMetadata() instanceof GdprTaintMetadata) {
GdprTaintMetadata taintMetadata = (GdprTaintMetadata) range.getMetadata();
if (range.getMetadata() instanceof GdprTaintMetadata taintMetadata) {
GdprMetadata metadata = taintMetadata.getMetadata();
if (!policy.areRequiredPurposesAllowed(required, metadata.getAllowedPurposes())) {
return true;
Expand Down Expand Up @@ -125,13 +123,13 @@ public static boolean updateExpiryDatesAndProtectionLevel(IASTaintAware taintAwa
gdprData.setProtectionLevel(protectionLevel);
for(AllowedPurpose purpose : gdprData.getAllowedPurposes()) {
purpose.setExpiryDate(expiryDate);
acc = true;

}
return acc;
return true;
});
}

private static final Cache<String,Collection<AllowedPurpose>> cookieCache = Caffeine.newBuilder().build();;
private static final Cache<String,Collection<AllowedPurpose>> cookieCache = Caffeine.newBuilder().build();

public static Collection<AllowedPurpose> getPurposesFromRequest(ReflectedHttpServletRequest servlet) {
ReflectedCookie[] cookies = servlet.getCookies();
Expand Down Expand Up @@ -159,8 +157,8 @@ public static Pair<IASTaintAware, Boolean> censorContestedParts(IASTaintAware ta
StringBuilder sb = new StringBuilder(s.getString());
for (IASTaintRange range : s.getTaintInformation().getTaintRanges(s.length())) {
IASTaintMetadata meta = range.getMetadata();
if(meta instanceof GdprTaintMetadata) {
GdprMetadata gdprMetadata = ((GdprTaintMetadata) meta).getMetadata();
if(meta instanceof GdprTaintMetadata gdprTaintMetadata) {
GdprMetadata gdprMetadata = gdprTaintMetadata.getMetadata();
if(!gdprMetadata.isProcessingUnrestricted()) {
contested = true;
for (int i = range.getStart(); i < range.getEnd(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private static IASTaintAware setTaint(IASTaintAware taintAware, Object parent, O
* @param object The object to be tainted
* @param sourceId The ID of the taint source function
* @return The tainted object
*
* <p>
* This snippet of XML can be added to the source:
* <pre>
* {@code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ConsentCookie() {
this.created = Instant.now().getEpochSecond();

}
private static final Cache<String,ConsentCookie> cookieCache = Caffeine.newBuilder().build();;
private static final Cache<String,ConsentCookie> cookieCache = Caffeine.newBuilder().build();

@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class ConsentCookieMetadata {

private ConsentCookieMetadata() {
}
private static final Cache<ConsentCookie,Collection<AllowedPurpose>> purposeCache = Caffeine.newBuilder().build();;
private static final Cache<ConsentCookie,Collection<AllowedPurpose>> purposeCache = Caffeine.newBuilder().build();

public static Collection<AllowedPurpose> getAllowedPurposesFromConsentCookie(ConsentCookie cookie) {
return purposeCache.get(cookie, (ignored)-> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

class Purpose {
public class Purpose {
private String id;
private List<Vendor> vendors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ public IASTaintAware abort(IASTaintAware taintAware, Object instance, String sin
boolean policyViolation = false;
for (IASTaintRange range : taintedString.getTaintInformation().getTaintRanges(taintedString.getString().length())) {
// Check policy for each range
if (range.getMetadata() instanceof GdprTaintMetadata) {
GdprTaintMetadata taintMetadata = (GdprTaintMetadata) range.getMetadata();
GdprMetadata metadata = taintMetadata.getMetadata();
if (range.getMetadata() instanceof GdprTaintMetadata gdprTaintMetadata) {
GdprMetadata metadata = gdprTaintMetadata.getMetadata();
if (!policy.areRequiredPurposesAllowed(requiredPurposes, metadata.getAllowedPurposes())) {
policyViolation = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static IASTaintAware setTaint(IASTaintAware taintAware, Object parent, O
* @param object The object to be tainted
* @param sourceId The ID of the taint source function
* @return The tainted object
*
* <p>
* This snippet of XML can be added to the source:
*
* <pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.sap.fontus.gdpr.jforum2;

import com.sap.fontus.config.Configuration;
import com.sap.fontus.config.DataProtection;
import com.sap.fontus.config.Sink;
import com.sap.fontus.config.Source;
import com.sap.fontus.config.abort.Abort;
import com.sap.fontus.gdpr.Utils;
import com.sap.fontus.gdpr.metadata.*;
import com.sap.fontus.gdpr.metadata.registry.RequiredPurposeRegistry;
import com.sap.fontus.gdpr.metadata.simple.SimpleDataId;
import com.sap.fontus.gdpr.metadata.simple.SimpleDataSubject;
import com.sap.fontus.gdpr.metadata.simple.SimpleGdprMetadata;
import com.sap.fontus.gdpr.metadata.simple.SimplePurposePolicy;
import com.sap.fontus.gdpr.openmrs.OpenMrsTaintHandler;
import com.sap.fontus.gdpr.servlet.ReflectedCookie;
import com.sap.fontus.gdpr.servlet.ReflectedHttpServletRequest;
import com.sap.fontus.gdpr.servlet.ReflectedSession;
Expand All @@ -24,7 +21,6 @@
import com.sap.fontus.taintaware.unified.IASString;
import com.sap.fontus.taintaware.unified.IASTaintHandler;

import java.lang.reflect.InvocationTargetException;
import java.util.*;

public class JForum2TaintHandler extends IASTaintHandler {
Expand Down Expand Up @@ -84,16 +80,15 @@ public static IASTaintAware handleEmailTaint(IASTaintAware taintAware, Object in
IASString tainted = taintAware.toIASString();
for (IASTaintRange range : tainted.getTaintInformation().getTaintRanges(tainted.length())) {
// Check policy for each range
if (range.getMetadata() instanceof GdprTaintMetadata) {
GdprTaintMetadata taintMetadata = (GdprTaintMetadata) range.getMetadata();
if (range.getMetadata() instanceof GdprTaintMetadata taintMetadata) {
GdprMetadata metadata = taintMetadata.getMetadata();
if (!policy.areRequiredPurposesAllowed(rp, metadata.getAllowedPurposes())) {
StringBuilder sb = new StringBuilder(50);
for(AllowedPurpose ap : metadata.getAllowedPurposes()) {
sb.append(ap);
sb.append(", ");
}
System.out.printf("Policy violation for %s!%nRequired: %s, got %s", tainted.getString(), rp, sb.toString());
System.out.printf("Policy violation for %s!%nRequired: %s, got %s", tainted.getString(), rp, sb);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public interface AllowedPurpose {

public ExpiryDate getExpiryDate();
public void setExpiryDate(ExpiryDate expiryDate);
public Purpose getAllowedPurpose();
ExpiryDate getExpiryDate();
void setExpiryDate(ExpiryDate expiryDate);
Purpose getAllowedPurpose();

public Set<Vendor> getAllowedVendors();
Set<Vendor> getAllowedVendors();

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public interface DataId {

public UUID getUUID();
UUID getUUID();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

public interface DataSubject {

public String getIdentifier();
String getIdentifier();

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public interface ExpiryDate extends Comparable<ExpiryDate> {

public Instant getDate();
Instant getDate();

public boolean hasExpiry();
boolean hasExpiry();

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ public interface GdprMetadata {
// List of allowed purposes for a given receiver, together with expiry information
// Metadatum 1
// TCF - getAllowedPurposes and getAllowedVendorIds
public Collection<AllowedPurpose> getAllowedPurposes();
Collection<AllowedPurpose> getAllowedPurposes();

// Level of protection required, e.g. sensitive medical data
// Metadatum 2
public ProtectionLevel getProtectionLevel();
ProtectionLevel getProtectionLevel();

// The data subject needs to be identified
// Metadatum 3
// Enables Subject Access Request as per GDPR Article 15
public Collection<DataSubject> getSubjects();
Collection<DataSubject> getSubjects();

// Unique ID to uniquely identify this piece of data
// Metadatum 4
// Allows e.g. logging of which data has been sent to whom
public DataId getId();
DataId getId();

// Is the data portable?
// Metadatum 5
// Maps to GDPR Article 20
// Data requested to be shared by the data subject with a third party
// All data which is directly input by the user (not those which have been processed)
public boolean isQualifiedForPortability();
boolean isQualifiedForPortability();

// Is processing restricted?
// Metadatum 6
// Is unrestricted processing allowed on this data?
// Processing might be restricted e.g. due to inaccurate data, which needs to be corrected.
// Maps to GDPR Article 18
public boolean isProcessingUnrestricted();
boolean isProcessingUnrestricted();

// Can the data be used to directly identify a person?
// Explicit / not explicit
// Metadatum 7
public Identifiability isIdentifiable();
Identifiability isIdentifiable();

// Switches Metadatum 6 to true
public void restrictProcessing();
void restrictProcessing();

public void setProtectionLevel(ProtectionLevel protectionLevel);
void setProtectionLevel(ProtectionLevel protectionLevel);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/
public interface GdprMetadataConflictResolverInterface {

public GdprMetadata resolveConflicts(GdprMetadata first, GdprMetadata second);
GdprMetadata resolveConflicts(GdprMetadata first, GdprMetadata second);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

public interface RequiredPurposes {

public Collection<Purpose> getPurposes();
Collection<Purpose> getPurposes();

public Collection<Vendor> getVendors();
Collection<Vendor> getVendors();

public static class EmptyRequiredPurposes implements RequiredPurposes {
class EmptyRequiredPurposes implements RequiredPurposes {
@Override
public Collection<Purpose> getPurposes() {
return Collections.emptyList();
Expand Down
4 changes: 2 additions & 2 deletions fontus/src/main/java/com/sap/fontus/gdpr/metadata/Vendor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public interface Vendor extends NamedObject {

public int getId();
int getId();

public String getName();
String getName();

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static IASTaintAware setTaint(IASTaintAware taintAware, Object parent, O
* @param object The object to be tainted
* @param sourceId The ID of the taint source function
* @return The tainted object
*
* <p>
* This snippet of XML can be added to the source:
*
* <pre>
Expand Down Expand Up @@ -186,8 +186,7 @@ public static IASTaintAware applyPolicy(IASTaintAware taintAware, Object instanc
boolean policyViolation = false;
for (IASTaintRange range : taintedString.getTaintInformation().getTaintRanges(taintedString.getString().length())) {
// Check policy for each range
if (range.getMetadata() instanceof GdprTaintMetadata) {
GdprTaintMetadata taintMetadata = (GdprTaintMetadata) range.getMetadata();
if (range.getMetadata() instanceof GdprTaintMetadata taintMetadata) {
GdprMetadata metadata = taintMetadata.getMetadata();
if (!policy.areRequiredPurposesAllowed(requiredPurposes, metadata.getAllowedPurposes())) {
policyViolation = true;
Expand Down
Loading

0 comments on commit 263e448

Please sign in to comment.