Commit af638d2
fix(authserver): six pre-existing defects blocking dev-mysql boot (#125)
Discovered during Phase 2.0 auth-server bring-up (#122). The auth-server
had not been booted clean against a fresh MySQL in living memory; static
audit only surfaced these defects under actual runtime. Six independent
blockers patched here; one more (filter chain canonical pattern) tracked
as #124, and ApplicationInformation schema repair as #123.
Patch 1 — MySQL V1 FK uniqueness
V1_0_0__create_oauth2_schema.sql declared an FK from
espi_application_info.client_id to oauth2_registered_client.client_id,
but the referenced column had no unique constraint (only PRIMARY KEY
on id). MySQL rejected the CREATE TABLE. Added UNIQUE KEY on
oauth2_registered_client.client_id and removed the now-redundant
non-unique CREATE INDEX. PostgreSQL V1 was already correct.
Patch 2 — Flyway location config / source layout mismatch
Source files live at db/vendor/{h2,mysql,postgresql}/ but 4 profile
YAMLs plus base application.yml plus docker-compose env vars pointed at
classpath:db/migration/{mysql,postgresql,h2}/. Boot only "worked"
historically because of stale target/classes/db/migration/ artifacts
from a prior layout; mvn clean exposed the gap. Updated all 6 config
references to classpath:db/vendor/... per the user's preference to
keep the current vendor-organized source layout.
Patch 3 — Flyway target=2.0.0 (workaround for #123)
V3+ migrations INSERT into espi_application_info columns that don't
exist in MySQL V1 (client_description, contact_name, contact_email,
scope, grant_types, response_types). Root cause is schema drift from
the ESPI 4.0 XSD; full repair tracked as #123. Set
spring.flyway.target: "2.0.0" in application-dev-mysql.yml so boot
succeeds with V1+V2 schema (sufficient for OAuth2 grant + introspect;
V3+ is seed/demo data).
Patch 4 — JWT-only resource server filter chain
AuthorizationServerConfig.authorizationServerSecurityFilterChain
declared both .opaqueToken(Customizer.withDefaults()) and OIDC
(which auto-wires JWT validation) on the same chain. Spring Security
7.x refuses by design: "Spring Security only supports JWTs or Opaque
Tokens, not both at the same time." Removed .opaqueToken; the chain
now uses .jwt(Customizer.withDefaults()). Outbound tokens to ESPI
clients remain opaque — controlled per-RegisteredClient via
accessTokenFormat(OAuth2TokenFormat.REFERENCE), unaffected by this
filter-chain change.
Patch 5 — Disabled @order(0) header-injection chains
HttpsEnforcementConfig declared two SecurityFilterChain @order(0)
beans (httpsEnforcementFilterChain for prod, developmentSecurityFilterChain
for dev profiles) with securityMatcher("/**") that monopolized every
request, preempting the auth-server's @order(1) chain. Result: every
OAuth2 endpoint returned 404. Header injection should be a
HeaderWriter or Filter, not a SecurityFilterChain claiming /**.
Disabled both @bean annotations; AuthorizationServerConfig's own
chain already configures equivalent security headers. Re-introducing
the dev-friendly cache-control headers via a proper mechanism is a
follow-up cleanup item.
Patch 6 — HikariCP auto-commit
application-dev-mysql.yml had auto-commit: false but
JdbcRegisteredClientRepository.save() (and likely other repository
methods) declares no @transactional. With auto-commit off and no
declared transaction, INSERTs execute against an uncommitted
connection and silently roll back when the connection returns to the
pool. Boot logged "Inserted registered client: 1" three times while
the DB had 0 rows. Set auto-commit: true to make the seed flow work.
Architectural fix (proper @transactional throughout the repository)
deferred — tracked as part of #122 / Phase 2.0 cleanup.
What works after these six patches
- mvn clean install of openespi-authserver succeeds
- mvn -pl openespi-authserver spring-boot:run reaches Started state
in ~35-42s
- Flyway V1+V2 apply cleanly to a fresh MySQL 8.4
- Tomcat listens on port 9999
- Three default ESPI clients persist correctly:
data_custodian_admin, third_party, third_party_admin
- Discovery endpoints return 200:
/.well-known/oauth-authorization-server
/.well-known/openid-configuration
/oauth2/jwks
/login
What does NOT work yet (tracked separately)
- POST /oauth2/token returns 401 — resource-server bearer filter
preempts the token endpoint. Fix tracked as #124 (filter chain
needs the canonical OAuth2AuthorizationServerConfiguration
.applyDefaultSecurity pattern with a second @order(2) chain).
- JdbcRegisteredClientRepository.findAll() returns empty list even
when rows exist. Boot logs "Default ESPI Clients: 0" while DB has
3 rows. Defect #8 from the #122 audit; not yet diagnosed.
- V3-V6 Flyway migrations skipped via target=2.0.0 pending #123.
Refs: #122 #123 #124
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent 7fa7243 commit af638d2
9 files changed
Lines changed: 32 additions & 15 deletions
File tree
- openespi-authserver
- docker
- src/main
- java/org/greenbuttonalliance/espi/authserver/config
- resources
- db/vendor/mysql
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
140 | 145 | | |
141 | | - | |
142 | | - | |
143 | | - | |
| 146 | + | |
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| |||
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
| |||
151 | 156 | | |
152 | 157 | | |
153 | 158 | | |
154 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
155 | 162 | | |
156 | 163 | | |
157 | 164 | | |
| |||
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | | - | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | | - | |
113 | 113 | | |
0 commit comments