Skip to content

style(autoconfig): optimize auto configuration code style#3

Merged
fudaiyf merged 4 commits into
mainfrom
feature/optimize-autoconfig-code-style
Feb 26, 2026
Merged

style(autoconfig): optimize auto configuration code style#3
fudaiyf merged 4 commits into
mainfrom
feature/optimize-autoconfig-code-style

Conversation

@fudaiyf
Copy link
Copy Markdown
Collaborator

@fudaiyf fudaiyf commented Feb 26, 2026

Description

Optimize code readability across AutoConfiguration classes by applying the Facade pattern to OpenAgentAuthProperties, reducing deeply nested chain calls (4-6 levels) to simple one-level convenience method calls. This follows the Law of Demeter (Least Knowledge Principle) and keeps all lines within the 120-character best practice.

Additionally, this PR fixes the CI test report summary trimming warning, removes the noisy auto-update coverage badge mechanism, and fixes incorrect build status badge links in README.

Type of Change

  • Code refactoring
  • Bug fix
  • Documentation update
  • Test additions or updates

Changes Made

Code Refactoring — Convenience Methods on OpenAgentAuthProperties

Added 7 Facade-style convenience methods to OpenAgentAuthProperties to eliminate repetitive deep chain calls:

Method Replaces Depth Reduction
getTrustDomain() getInfrastructures().getTrustDomain() 3→1
getKeyDefinition(name) getInfrastructures().getKeyManagement().getKeys().get(name) 5→1
getServiceDefinition(name) getInfrastructures().getServiceDiscovery().getServices().get(name) 5→1
getServiceUrl(name) getInfrastructures().getServiceDiscovery().getServices().get(name).getBaseUrl() 6→1
getJwksConsumer(name) getInfrastructures().getJwks().getConsumers().get(name) 5→1
getRole(name) getRoles().get(name) 2→1
getRoleIssuer(name) getRoles().get(name).getIssuer() (with null safety) 3→1

Refactored 10 source files (70+ call sites):

  • CoreAutoConfiguration.java
  • AgentAutoConfiguration.java
  • AgentIdpAutoConfiguration.java
  • AuthorizationServerAutoConfiguration.java
  • ResourceServerAutoConfiguration.java
  • JweEncryptionAutoConfiguration.java
  • SharedCapabilityAutoConfiguration.java
  • DiscoveryController.java
  • OaaConfigurationController.java
  • RoleAwareEnvironmentPostProcessor.java

CI Improvements

  • Fixed test report trimming warning: Added only-summary: 'true' and list-tests: 'failed' to dorny/test-reporter@v1 to resolve the "Test report summary exceeded limit of 65535 bytes" warning
  • Removed noisy coverage badge auto-update: Removed the "Extract coverage percentage" and "Update coverage badge in README" CI steps that produced extra chore: update coverage badge commits on every push to main

Documentation

  • Fixed build status badge links in README.md and README.zh-CN.md
  • Updated coverage badge to 83%

Test Fixes

  • AuthorizationServerAutoConfigurationTest: Updated assertion to match the refined error message "AS User IDP issuer configuration not found" (more precise than the previous "AS User IDP configuration not found")
  • DiscoveryControllerTest: Updated all 11 test methods to stub properties.getRole() convenience method instead of manipulating properties.getRoles() map directly, aligning with the refactored DiscoveryController

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing completed
  • All existing tests pass

Test Instructions:

# Run all AutoConfiguration tests (201 tests)
mvn test -pl open-agent-auth-spring-boot-starter -Dtest="*AutoConfiguration*Test"

# Run DiscoveryController tests (13 tests)
mvn test -pl open-agent-auth-spring-boot-starter -Dtest="DiscoveryControllerTest"

# Run full test suite
mvn test -pl open-agent-auth-spring-boot-starter

Checklist

  • Code follows coding standards
  • Self-review performed
  • Documentation updated
  • No new warnings
  • Tests added/updated
  • All tests pass locally
  • CHANGELOG.md updated

Breaking Changes

No breaking changes. All modifications are internal refactoring — the public API and configuration schema remain unchanged.

Additional Context

Design Rationale

This refactoring applies the Facade pattern from GoF to OpenAgentAuthProperties:

  • The convenience methods act as a simplified interface over the deeply nested configuration tree
  • Each method includes null-safety (e.g., getServiceUrl() returns null instead of throwing NPE when the service is not configured)
  • The approach follows Effective Java Item 15: minimize the accessibility of classes and members — callers no longer need to know the internal structure of the properties hierarchy

Files Changed Summary

 16 files changed, 246 insertions(+), 290 deletions(-)

Net reduction of 44 lines while improving readability across the codebase.

@github-actions
Copy link
Copy Markdown

Code Coverage Report

Overall Project 83.15% -0.16% 🍏
Files changed 85.57% 🍏

Module Coverage
open-agent-auth-spring-boot-starter 85.22% -0.57% 🍏
open-agent-auth-spring-boot-starter 85.22% -0.57% 🍏
open-agent-auth-spring-boot-starter 85.22% -0.57% 🍏
open-agent-auth-spring-boot-starter 85.22% -0.57% 🍏
open-agent-auth-spring-boot-starter 85.22% -0.57% 🍏
open-agent-auth-spring-boot-starter 85.22% -0.57% 🍏
Files
Module File Coverage
open-agent-auth-spring-boot-starter OpenAgentAuthProperties.java 99.41% -0.59% 🍏
RoleAwareEnvironmentPostProcessor.java 97.81% 🍏
DiscoveryController.java 96.32% -3.68% 🍏
SharedCapabilityAutoConfiguration.java 93.44% 🍏
JweEncryptionAutoConfiguration.java 90.79% 🍏
CoreAutoConfiguration.java 87.93% 🍏
AgentIdpAutoConfiguration.java 80.77% -6.41% 🍏
AuthorizationServerAutoConfiguration.java 80.75% -1.8% 🍏
AgentAutoConfiguration.java 65.94% -1.09% 🍏
ResourceServerAutoConfiguration.java 65.07% -15.07%
OaaConfigurationController.java 0% -1.62%
open-agent-auth-spring-boot-starter OpenAgentAuthProperties.java 99.41% -0.59% 🍏
RoleAwareEnvironmentPostProcessor.java 97.81% 🍏
DiscoveryController.java 96.32% -3.68% 🍏
SharedCapabilityAutoConfiguration.java 93.44% 🍏
JweEncryptionAutoConfiguration.java 90.79% 🍏
CoreAutoConfiguration.java 87.93% 🍏
AgentIdpAutoConfiguration.java 80.77% -6.41% 🍏
AuthorizationServerAutoConfiguration.java 80.75% -1.8% 🍏
AgentAutoConfiguration.java 65.94% -1.09% 🍏
ResourceServerAutoConfiguration.java 65.07% -15.07%
OaaConfigurationController.java 0% -1.62%
open-agent-auth-spring-boot-starter OpenAgentAuthProperties.java 99.41% -0.59% 🍏
RoleAwareEnvironmentPostProcessor.java 97.81% 🍏
DiscoveryController.java 96.32% -3.68% 🍏
SharedCapabilityAutoConfiguration.java 93.44% 🍏
JweEncryptionAutoConfiguration.java 90.79% 🍏
CoreAutoConfiguration.java 87.93% 🍏
AgentIdpAutoConfiguration.java 80.77% -6.41% 🍏
AuthorizationServerAutoConfiguration.java 80.75% -1.8% 🍏
AgentAutoConfiguration.java 65.94% -1.09% 🍏
ResourceServerAutoConfiguration.java 65.07% -15.07%
OaaConfigurationController.java 0% -1.62%
open-agent-auth-spring-boot-starter OpenAgentAuthProperties.java 99.41% -0.59% 🍏
RoleAwareEnvironmentPostProcessor.java 97.81% 🍏
DiscoveryController.java 96.32% -3.68% 🍏
SharedCapabilityAutoConfiguration.java 93.44% 🍏
JweEncryptionAutoConfiguration.java 90.79% 🍏
CoreAutoConfiguration.java 87.93% 🍏
AgentIdpAutoConfiguration.java 80.77% -6.41% 🍏
AuthorizationServerAutoConfiguration.java 80.75% -1.8% 🍏
AgentAutoConfiguration.java 65.94% -1.09% 🍏
ResourceServerAutoConfiguration.java 65.07% -15.07%
OaaConfigurationController.java 0% -1.62%
open-agent-auth-spring-boot-starter OpenAgentAuthProperties.java 99.41% -0.59% 🍏
RoleAwareEnvironmentPostProcessor.java 97.81% 🍏
DiscoveryController.java 96.32% -3.68% 🍏
SharedCapabilityAutoConfiguration.java 93.44% 🍏
JweEncryptionAutoConfiguration.java 90.79% 🍏
CoreAutoConfiguration.java 87.93% 🍏
AgentIdpAutoConfiguration.java 80.77% -6.41% 🍏
AuthorizationServerAutoConfiguration.java 80.75% -1.8% 🍏
AgentAutoConfiguration.java 65.94% -1.09% 🍏
ResourceServerAutoConfiguration.java 65.07% -15.07%
OaaConfigurationController.java 0% -1.62%
open-agent-auth-spring-boot-starter OpenAgentAuthProperties.java 99.41% -0.59% 🍏
RoleAwareEnvironmentPostProcessor.java 97.81% 🍏
DiscoveryController.java 96.32% -3.68% 🍏
SharedCapabilityAutoConfiguration.java 93.44% 🍏
JweEncryptionAutoConfiguration.java 90.79% 🍏
CoreAutoConfiguration.java 87.93% 🍏
AgentIdpAutoConfiguration.java 80.77% -6.41% 🍏
AuthorizationServerAutoConfiguration.java 80.75% -1.8% 🍏
AgentAutoConfiguration.java 65.94% -1.09% 🍏
ResourceServerAutoConfiguration.java 65.07% -15.07%
OaaConfigurationController.java 0% -1.62%

@fudaiyf fudaiyf merged commit fb3c126 into main Feb 26, 2026
7 checks passed
@fudaiyf fudaiyf deleted the feature/optimize-autoconfig-code-style branch February 26, 2026 01:38
cyyever added a commit to cyyever/aap-resource-server that referenced this pull request May 25, 2026
Mark hot spots alibaba#2-5 done. alibaba#2 (WptValidator.convertToJWK cache) was
already in place when the doc was last updated — corrected. alibaba#3
(JWKS) had TTL + single-flight + not-found throttle already; only
the SWR addition landed this session. alibaba#4 and alibaba#5 are this session's
work. Only the M1-renames-pending items remain in the list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cyyever added a commit to cyyever/aap-resource-server that referenced this pull request May 25, 2026
… → CT/DPoP

Lands the rename half of M1 alibaba#3 (DPoP semantic claims htm/htu/iat/jti/ath
deferred). Aligns the codebase with the AAP spec's wire-message vocabulary:
two wire messages CT (credential token) and DPoP (proof of possession).

Package + class renames (git mv preserves history):
- protocol/wimse/wit/  → protocol/ct/
- protocol/wimse/wpt/  → protocol/dpop/
- WitParser            → CtParser
- WitValidator         → CtValidator
- WptParser            → DpopParser
- WptValidator         → DpopValidator
- WorkloadIdentityToken → CredentialToken
- WorkloadProofToken   → DpopToken
- Empty protocol/wimse parent dir removed.

Identifier + wire-format updates:
- JOSE typ values: "wit+jwt" → "ct+jwt", "wpt+jwt" → "dpop+jwt"
- DefaultResourceServer log/error strings: WIT/WPT → CT/DPoP
- ResourceRequest fields + JSON properties: wit/wpt → ct/dpop (and
  getWit/getWpt → getCt/getDpop, builder methods .wit()/.wpt() →
  .ct()/.dpop()).
- Internal var/method renames: witParser→ctParser, wptValidator→
  dpopValidator, buildWorkloadIdentityToken→buildCredentialToken, etc.

wimse:// URI scheme stripped:
- TrustDomain: dropped getDomainName() + the startsWith("wimse://")
  prefix-strip. The class now stores domainId verbatim and compares it
  against the iss claim as-is — no scheme is implied.
- TrustDomainTest: dropped getDomainName test nest, fixture switched
  from "wimse://example.com" to "example.com".
- All protocol test fixtures: wimse://example.com → example.com.

KEY_WIT_VERIFICATION + Workload-Identity-Token HTTP header from
CLAUDE.md's M1 alibaba#3 list were already gone in earlier trims.

mvn -B test: 290 / 290 pass (was 293; -3 deleted getDomainName tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cyyever added a commit to cyyever/aap-resource-server that referenced this pull request May 25, 2026
Sweep matching the post-rename / post-trim state of the repo. No code
changes — javadoc and prose only.

CLAUDE.md:
  - "trim phase is mostly done" → "trim phase is done"; record that
    M1 alibaba#1alibaba#3 (alg=EdDSA lock, JOSE header whitelist, CT/DPoP rename)
    have landed; remaining work is the M1 retrofit tail.
  - Mark items 1, 2, 3 in the M1 list as done with their commits.
  - Drop the "After M1, also rename" list entries that have shipped
    (package rename, class renames, KEY_WIT_VERIFICATION).
  - Update perf hot spots wording for accuracy (no stale class refs).

READMEs (en + zh-CN):
  - Reference the new ai.shao.openagentauth.core.server.* package path.
  - Drop "WIT/WPT" references in favour of CT/DPoP wherever they
    described the current code (kept upstream-WIMSE-history context).

In-source javadoc:
  - Strip @SInCE 1.0 tags throughout — bit-rot during the trim, no
    consumers track @SInCE here.
  - Drop the "Workload" / WIT-era language where it described current
    types: DpopToken talks about CT (not WIT); CtValidator talks about
    Credential Tokens; ResourceServer's @OverRide javadoc references
    CT/DPoP.
  - Update @link / @see references that pointed at removed types.

mvn -B test: 293 / 293 pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cyyever added a commit to cyyever/aap-resource-server that referenced this pull request May 25, 2026
Reframe the project description around what it IS (the RP-side Java
reference implementation of AAP) rather than what it WAS (a fork
baseline being trimmed). Both en + zh-CN.

- Title: "Open Agent Auth — AAP fork baseline" → "AAP Resource Server (Java)".
- Lead paragraph describes the actual surface — parses + verifies CT
  and DPoP, returns a typed TokenValidationResult ADT.
- Scope section keeps the spec's hard rules verbatim (EdDSA, two wire
  messages, JOSE header whitelist, HTTPS-only, no AuthZ/OIDC/X.509/VC).
- Module section drops the "Spring Boot was removed" framing — that
  context belongs in git history, not the README.
- New "Build & quality gates" section documents the four mvn profiles
  + their current state (293/293, 0 NullAway, 0 SpotBugs) so contributors
  see at a glance what runs on each push.
- Status section refreshed: M1 alibaba#1alibaba#3 marked done; M1 tail re-scoped to
  ~330–390 LoC (post spec v0.9.4/v0.9.5) with the actual remaining
  items (DPoP claims, keyset+trust-set, CRL, PIC, blacklist, JSONL,
  HTTP header enforcer).
- License footer unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant