Skip to content

Commit 886d12b

Browse files
committed
Update Turnstile service configuration, dependencies, and checkstyle rules
1 parent 13446a7 commit 886d12b

6 files changed

Lines changed: 27 additions & 28 deletions

File tree

.claude/settings.local.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
"Bash(git push:*)",
2222
"Bash(ls:*)",
2323
"Bash(find:*)",
24-
"Bash(git restore:*)"
24+
"Bash(git restore:*)",
25+
"Bash(gradle clean:*)",
26+
"Bash(gradle build:*)",
27+
"Bash(gradle checkstyle:*)",
28+
"mcp__zen__codereview",
29+
"Bash(xargs ls:*)",
30+
"Bash(gradle:*)"
2531
],
2632
"deny": []
2733
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Add the following dependency to your `pom.xml`:
4343
<dependency>
4444
<groupId>com.digitalsanctuary</groupId>
4545
<artifactId>ds-spring-cf-turnstile</artifactId>
46-
<version>1.1.8</version>
46+
<version>1.2.0</version>
4747
</dependency>
4848
```
4949

@@ -53,7 +53,7 @@ Add the following dependency to your `build.gradle`:
5353

5454
```groovy
5555
dependencies {
56-
implementation 'com.digitalsanctuary:ds-spring-cf-turnstile:1.1.8'
56+
implementation 'com.digitalsanctuary:ds-spring-cf-turnstile:1.2.0'
5757
}
5858
```
5959

config/checkstyle/checkstyle.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
<module name="JavadocType">
3737
<property name="scope" value="public"/>
3838
</module>
39-
<module name="JavadocVariable">
40-
<property name="scope" value="public"/>
41-
</module>
4239
<module name="JavadocStyle"/>
4340

4441
<!-- Naming Conventions -->

config/pmd/ruleset.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<!-- Best Practices -->
1010
<rule ref="category/java/bestpractices.xml">
1111
<exclude name="GuardLogStatement"/>
12-
<exclude name="JUnitTestContainsTooManyAsserts"/>
13-
<exclude name="JUnitTestsShouldIncludeAssert"/>
14-
<exclude name="JUnitAssertionsShouldIncludeMessage"/>
12+
<exclude name="UnitTestContainsTooManyAsserts"/>
13+
<exclude name="UnitTestAssertionsShouldIncludeMessage"/>
1514
<exclude name="JUnit5TestShouldBePackagePrivate"/>
15+
<exclude name="AvoidUsingHardCodedIP"/>
1616
</rule>
1717

1818

@@ -26,9 +26,9 @@
2626
<exclude name="LongVariable"/>
2727
<exclude name="ShortClassName"/>
2828
<exclude name="CommentDefaultAccessModifier"/>
29-
<exclude name="DefaultPackage"/>
3029
<exclude name="CallSuperInConstructor"/>
3130
<exclude name="UselessParentheses"/>
31+
<exclude name="TooManyStaticImports"/>
3232
</rule>
3333

3434
<!-- Design -->
@@ -38,21 +38,29 @@
3838
<exclude name="UseUtilityClass"/>
3939
<exclude name="DataClass"/>
4040
<exclude name="TooManyMethods"/>
41+
<exclude name="CognitiveComplexity"/>
42+
<exclude name="CyclomaticComplexity"/>
43+
<exclude name="NPathComplexity"/>
44+
<exclude name="NcssCount"/>
45+
<exclude name="GodClass"/>
46+
<exclude name="AvoidCatchingGenericException"/>
4147
</rule>
4248

4349
<!-- Documentation -->
4450
<rule ref="category/java/documentation.xml">
4551
<exclude name="CommentSize"/>
52+
<exclude name="CommentRequired"/>
4653
</rule>
4754

4855
<!-- Error Prone -->
4956
<rule ref="category/java/errorprone.xml">
50-
<exclude name="DataflowAnomalyAnalysis"/>
5157
<exclude name="AvoidFieldNameMatchingMethodName"/>
5258
<exclude name="AvoidLiteralsInIfCondition"/>
5359
<exclude name="NullAssignment"/>
5460
<exclude name="MissingSerialVersionUID"/>
5561
<exclude name="AssignmentInOperand"/>
62+
<exclude name="AvoidDuplicateLiterals"/>
63+
<exclude name="TestClassWithoutTestCases"/>
5664
</rule>
5765

5866
<!-- Multithreading -->
@@ -64,7 +72,6 @@
6472
<!-- Performance -->
6573
<rule ref="category/java/performance.xml">
6674
<exclude name="AvoidInstantiatingObjectsInLoops"/>
67-
<exclude name="SimplifyStartsWith"/>
6875
</rule>
6976

7077

src/main/java/com/digitalsanctuary/cf/turnstile/config/TurnstileServiceConfig.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import java.util.Optional;
44
import org.springframework.beans.factory.ObjectProvider;
55
import org.springframework.beans.factory.annotation.Qualifier;
6-
import org.springframework.boot.web.client.RestTemplateBuilder;
76
import org.springframework.context.annotation.Bean;
87
import org.springframework.context.annotation.Configuration;
98
import org.springframework.http.HttpHeaders;
109
import org.springframework.http.MediaType;
1110
import org.springframework.web.client.RestClient;
12-
import org.springframework.web.client.RestTemplate;
1311
import com.digitalsanctuary.cf.turnstile.service.TurnstileValidationService;
1412
import io.micrometer.core.instrument.MeterRegistry;
1513
import lombok.RequiredArgsConstructor;
@@ -27,17 +25,6 @@ public class TurnstileServiceConfig {
2725
private final TurnstileConfigProperties properties;
2826
private final ObjectProvider<MeterRegistry> meterRegistryProvider;
2927

30-
/**
31-
* Creates a RestTemplate bean for Turnstile API interactions.
32-
*
33-
* @param builder the RestTemplateBuilder used to build the RestTemplate
34-
* @return a configured RestTemplate instance
35-
*/
36-
@Bean
37-
public RestTemplate turnstileRestTemplate(RestTemplateBuilder builder) {
38-
return builder.build();
39-
}
40-
4128
/**
4229
* Creates a TurnstileValidationService bean.
4330
*

src/main/java/com/digitalsanctuary/cf/turnstile/service/TurnstileValidationService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public void onStartup() {
138138
log.info("TurnstileValidationService started");
139139
log.info("Turnstile URL: {}", properties.getUrl());
140140
log.info("Turnstile Sitekey: {}", properties.getSitekey());
141+
log.info("Turnstile Secret: {}", properties.getSecret() != null && !properties.getSecret().isBlank() ? "[CONFIGURED]" : "[NOT CONFIGURED]");
141142
log.info("Turnstile Metrics enabled: {}", properties.getMetrics().isEnabled());
142143
log.info("Turnstile Health Check enabled: {}", properties.getMetrics().isHealthCheckEnabled());
143144

@@ -237,9 +238,10 @@ public ValidationResult validateTurnstileResponseDetailed(String token, String r
237238
}
238239

239240
// Validate remoteIp if provided
240-
if (remoteIp != null && (remoteIp.isEmpty() || remoteIp.isBlank())) {
241+
String cleanRemoteIp = remoteIp;
242+
if (cleanRemoteIp != null && (cleanRemoteIp.isEmpty() || cleanRemoteIp.isBlank())) {
241243
log.warn("Turnstile validation: ignoring empty or blank remoteIp");
242-
remoteIp = null;
244+
cleanRemoteIp = null;
243245
}
244246

245247
// Validate that we have the required configuration
@@ -261,7 +263,7 @@ public ValidationResult validateTurnstileResponseDetailed(String token, String r
261263
Map<String, String> requestBody = new HashMap<>();
262264
requestBody.put("secret", properties.getSecret());
263265
requestBody.put("response", token);
264-
Optional.ofNullable(remoteIp).ifPresent(ip -> requestBody.put("remoteip", ip));
266+
Optional.ofNullable(cleanRemoteIp).ifPresent(ip -> requestBody.put("remoteip", ip));
265267

266268
log.trace("Making request to Cloudflare Turnstile API at: {}", properties.getUrl());
267269

0 commit comments

Comments
 (0)