Skip to content

Commit

Permalink
Check for missing javadocs using checkstyle
Browse files Browse the repository at this point in the history
Adds checkstyle:check within CircleCI building process that will check
for missing javadoc comments from public method. The configuration is
stored in checkstyle/*
  • Loading branch information
ajvb committed Apr 7, 2020
1 parent 73f99b9 commit 5f3b209
Show file tree
Hide file tree
Showing 34 changed files with 157 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
- run:
name: Spotless check
command: bin/m spotless:check
- run:
name: Javadoc (checkstyle) check
command: bin/m checkstyle:check
- run:
name: Generate version.json
command: bin/write_version_json.sh
Expand Down
22 changes: 22 additions & 0 deletions checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">

<suppressions>
<suppress checks="InvalidJavadocPosition"
files="KinesisIO.java" />
<suppress checks="MissingJavadocMethod"
files="KinesisRecord.java" />
<suppress checks="JavadocParagraph"
files="ShardCheckpoint.java" />
<suppress checks="MissingJavadocMethod"
files="MemcachedStateInterface.java" />
<suppress checks="MissingJavadocMethod"
files="DatastoreStateInterface.java" />
<suppress checks="MissingJavadocMethod"
files="UserIdentity.java" />
<suppress checks="MissingJavadocMethod"
files="CloudtrailEvent.java" />
</suppressions>
51 changes: 51 additions & 0 deletions checkstyle/foxsec_checks.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<!--
Checkstyle configuration specific to the foxsec-pipeline. This is lacking as we rely
heavily on spotless for the majority of linting.
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.
-->

<module name = "Checker">
<property name="charset" value="UTF-8"/>

<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/checkstyle-suppressions.xml" />
<property name="optional" value="true"/>
</module>

<module name="TreeWalker">
<module name="InvalidJavadocPosition"/>
<module name="JavadocTagContinuationIndentation"/>
<module name="JavadocParagraph"/>
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="allowedAnnotations" value="Override, Test, Setup, Teardown, ProcessElement, OnTimer, OnStale"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
</module>
<module name="MissingJavadocMethod">
<property name="scope" value="public"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test, Setup, Teardown, ProcessElement, OnTimer, OnStale"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
</module>
</module>
</module>
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
</java>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<configLocation>checkstyle/foxsec_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mozilla/secops/SourceCorrelation.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public SourceCorrelator(HTTPRequestToggles toggles) {
this.monitoredResource = toggles.getMonitoredResource();
}

/** Transform documentation for users - see {@link DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Source address alerting correlation, ISP analysis on minimum %d "
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mozilla/secops/amo/AddonMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public AddonMatcher(String monitoredResource, Integer suppressRecovery, String[]
this.matchCriteria = matchCriteria;
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Match abusive addon uploads using these patterns %s and generate alerts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public AddonMultiIpLogin(
this.aggMatchers = aggMatchers;
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Detect multiple account logins for the same account from different source addresses associated with different country codes. Alert on %s different countries and %s different IPs. Regex for account exceptions: %s",
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mozilla/secops/amo/AddonMultiMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public AddonMultiMatch(String monitoredResource, Integer suppressRecovery, Integ
this.matchAlertOn = matchAlertOn;
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Detect distributed AMO submissions with the same file name. Alert on %s submissions of the same file name.",
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mozilla/secops/amo/AddonMultiSubmit.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public AddonMultiSubmit(
this.matchAlertOn = matchAlertOn;
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Detect distributed submissions based on file size intervals. Alert on %s submissions of the same rounded interval.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public FxaAccountAbuseAlias(
this.maxAliases = maxAliases;
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Alerts on aliased FxA accounts usage. A max of %s are allowed for one account in a given session.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public FxaAccountAbuseNewVersion(
this.project = project;
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Correlates AMO addon submissions with abusive FxA account creation alerts via iprepd. Also includes blacklisted accounts regex: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ReportRestriction(String monitoredResource) {
this.monitoredResource = monitoredResource;
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return "Reports on request restrictions from AMO";
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/mozilla/secops/authprofile/AuthProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public CritObjectAnalyze(AuthProfileOptions options) {
useEventTimestampForAlert = options.getUseEventTimestampForAlert();
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Alert via %s immediately on auth events to specified objects: %s",
Expand Down Expand Up @@ -545,6 +546,7 @@ public StateAnalyze(AuthProfileOptions options) {
useEventTimestampForAlert = options.getUseEventTimestampForAlert();
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return "Alert if an identity (can be thought of as a user) authenticates from a new IP";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public void setEntryAgePruningSeconds(long entryAgePruningSeconds) {
this.entryAgePruningSeconds = entryAgePruningSeconds;
}

/**
* Implementation of method of {@link PruningStrategyEntryAge}
*
* <p>See {@link PruningStrategy}
*/
public void pruneState(AuthStateModel s) {
Map<String, AuthStateModel.ModelEntry> entries = s.getEntries();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
* All entries are removed from the model with the exception of the entry with the latest timestamp.
*/
public class PruningStrategyLatest implements PruningStrategy {
/**
* Implementation of method of {@link PruningStrategyLatest}
*
* <p>See {@link PruningStrategy}
*/
public void pruneState(AuthStateModel s) {
ArrayList<AbstractMap.SimpleEntry<String, AuthStateModel.ModelEntry>> sorted =
s.timeSortedEntries();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/mozilla/secops/awsbehavior/AwsBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static class Matcher extends PTransform<PCollection<Event>, PCollection<A

private Logger log;

/** Initialize new Matcher with a {@link CloudtrailMatcher} */
public Matcher(CloudtrailMatcher cm) {
this.cm = cm;
log = LoggerFactory.getLogger(Matcher.class);
Expand Down Expand Up @@ -147,6 +148,7 @@ public static class Matchers extends PTransform<PCollection<Event>, PCollection<
private CloudtrailMatcherManager cmmanager;
private Logger log;

/** Initialize new Matchers with {@link AwsBehaviorOptions} */
public Matchers(AwsBehaviorOptions options) throws IOException {
log = LoggerFactory.getLogger(Matchers.class);
cmmanagerPath = options.getCloudtrailMatcherManagerPath();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mozilla/secops/customs/Customs.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public CustomsSummary(CustomsOptions options) {
monitoredResource = options.getMonitoredResourceIndicator();
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return "Summarizes various event counts over 15 minute period.";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public CustomsAccountCreation(CustomsOptions options) {
this.escalate = options.getEscalateAccountCreation();
}

/** Transform documentation for users - see {@link CustomsDocumentingTransform} */
public String getTransformDocDescription() {
return String.format(
"Alert if single source address creates %d or more accounts within 10 minute"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public CustomsAccountCreationDist(CustomsOptions options) {
this.escalate = options.getEscalateAccountCreationDistributed();
}

/** Transform documentation for users - see {@link CustomsDocumentingTransform} */
public String getTransformDocDescription() {
return String.format(
"Alert if at least %d accounts are created from different source addresses in a 10 "
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/mozilla/secops/customs/CustomsAlert.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ private static CustomsAlert baseAlert(Alert a) {
return ret;
}

/**
* Convert source login failure alert into a list of customs alerts.
*
* @param a Alert to convert
* @return ArrayList of CustomsAlert created
*/
public static ArrayList<CustomsAlert> convertSourceLoginFailure(Alert a) {
ArrayList<CustomsAlert> ret = new ArrayList<>();

Expand All @@ -170,6 +176,12 @@ public static ArrayList<CustomsAlert> convertSourceLoginFailure(Alert a) {
return ret;
}

/**
* Convert a distributed source login failure alert into a list of customs alerts.
*
* @param a Alert to convert
* @return ArrayList of CustomsAlert created
*/
public static ArrayList<CustomsAlert> convertSourceLoginFailureDist(Alert a) {
ArrayList<CustomsAlert> ret = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class CustomsPasswordResetAbuse

private final Logger log = LoggerFactory.getLogger(CustomsAccountCreation.class);

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDocDescription() {
return String.format(
"Alert if single source requests password reset for at least %d distinct accounts "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class CustomsVelocity extends PTransform<PCollection<Event>, PCollection<
private final String maxmindCityDbPath;
private final String maxmindIspDbPath;

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDocDescription() {
return String.format(
"Alert based on applying location velocity analysis to FxA events,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public SourceLoginFailure(Customs.CustomsOptions options) {
escalate = options.getEscalateSourceLoginFailure();
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDocDescription() {
return String.format(
"Alert on %d login failures from a single source in a 10 minute window.", threshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public SourceLoginFailureDist(Customs.CustomsOptions options) {
escalate = options.getEscalateSourceLoginFailureDistributed();
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDocDescription() {
return String.format(
"Alert on login failures for a particular account from %d different source addresses "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public GenerateETDAlerts(Options opts) {
}
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return "Alerts are generated based on events sent from GCP's Event Threat Detection.";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public GenerateGDAlerts(Options opts) {
}
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return "Alerts are generated based on events sent from AWS's Guardduty.";
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/mozilla/secops/httprequest/HTTPRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public ErrorRateAnalysis(
log = LoggerFactory.getLogger(ErrorRateAnalysis.class);
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Alert if a single source address generates more than %d 4xx errors in a "
Expand Down Expand Up @@ -305,6 +306,7 @@ public HardLimitAnalysis(
log = LoggerFactory.getLogger(HardLimitAnalysis.class);
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Alert if single source address makes more than %d requests in a 1 minute window.",
Expand Down Expand Up @@ -425,6 +427,7 @@ public UserAgentBlacklistAnalysis(
log = LoggerFactory.getLogger(UserAgentBlacklistAnalysis.class);
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return new String(
"Alert if client makes request with user agent that matches entry in blacklist.");
Expand Down Expand Up @@ -613,6 +616,7 @@ public EndpointAbuseAnalysis(
}
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
String buf = null;
for (int i = 0; i < endpoints.length; i++) {
Expand Down Expand Up @@ -845,6 +849,7 @@ public ThresholdAnalysis(
log = LoggerFactory.getLogger(ThresholdAnalysis.class);
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
return String.format(
"Alert if a single source address makes more than %.2f times the calculated"
Expand Down Expand Up @@ -1009,6 +1014,7 @@ public static class EndpointSequenceAbuseTimingInfo implements Serializable {
public String secondMethod;
public String secondPath;

/** Convert configuration to String */
public String toString() {
return String.format(
"%d:%s:%s:%d:%s:%s",
Expand Down Expand Up @@ -1055,6 +1061,7 @@ public EndpointSequenceAbuse(
}
}

/** Transform documentation for users - see {@link com.mozilla.secops.DocumentingTransform} */
public String getTransformDoc() {
String buf = null;
for (int i = 0; i < endpointPatterns.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void mergeData(HashMap<String, String> in) {
/**
* Add documentation about a transform to the configuration tick
*
* @param t {@link DocumentingTransform}
* @param t {@link com.mozilla.secops.DocumentingTransform}
*/
public void withTransformDoc(DocumentingTransform t) {
cfgData.put(String.format("heuristic_%s", t.getClass().getSimpleName()), t.getTransformDoc());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mozilla/secops/parser/FxaAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ private Boolean discernPasswordForgotSendCode() {
return false;
}

/**
* Check if the auth event contained a successful certifcate signing
*
* @return Boolean
*/
public Boolean discernCertificateSignSuccess() {
if (!(fxaAuthData.getPath().equals("/v1/certificate/sign"))) {
return false;
Expand Down
Loading

0 comments on commit 5f3b209

Please sign in to comment.