Commit af94f97
fix(authserver): canonical Spring Security 7.x filter chain + Jackson modules on custom repo (#128)
* fix(authserver): adopt canonical Spring Security 7.x filter chain pattern
Closes #124.
The authorizationServerSecurityFilterChain bean used a non-canonical DSL
combination — .oauth2AuthorizationServer(...) plus .oauth2ResourceServer().jwt()
on the same chain with .anyRequest().authenticated() and no securityMatcher.
Result: the resource-server bearer-token filter intercepted POST /oauth2/token
requests before the token-endpoint filter could authenticate them via basic
auth, returning 401 with WWW-Authenticate: Bearer.
The canonical pattern in Spring Security 7.x manually installs the
OAuth2AuthorizationServerConfigurer via http.with(...) and scopes the chain
to the auth-server endpoints via http.securityMatcher(configurer.getEndpointsMatcher()).
With the chain scoped to OAuth2 endpoints only, the bearer-token filter never
sees them and the token endpoint's own basic-auth filter handles client
authentication correctly.
Note: Spring Security 7.x removed the
OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http) static
method that Spring Authorization Server 1.x used; the http.with() pattern
plus manual securityMatcher is the replacement.
A second SecurityFilterChain @order(2) defaultSecurityFilterChain bean now
handles everything NOT claimed by the auth-server endpoints matcher: login
form, static resources, /.well-known/*, actuator endpoints. The previously
commented-out defaultSecurityFilterChain stub has been replaced with a real
implementation.
Verified end-to-end: with this filter chain plus the Jackson modules fix
landed in the next commit, POST /oauth2/token returns 200 with a 128-char
opaque access token, and POST /oauth2/introspect returns the RFC 7662
response shape (active, sub, aud, scope, iss, exp, iat, jti, client_id,
token_type).
Refs: #122
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(authserver): register Spring Authorization Server Jackson modules on custom repo
The custom JdbcRegisteredClientRepository constructed its ObjectMapper as
new ObjectMapper() with no modules registered. Spring Authorization Server
stores typed values (OAuth2TokenFormat, ClientAuthenticationMethod, etc.)
inside ClientSettings and TokenSettings; Jackson serializes them correctly
on write but cannot reconstruct the typed objects on read without the
provider's type-info modules.
Symptom: with a client configured accessTokenFormat(OAuth2TokenFormat.REFERENCE),
the round-tripped setting came back as a LinkedHashMap. Later
TokenSettings.getAccessTokenFormat() ClassCast the LinkedHashMap to
OAuth2TokenFormat — and worse, because the cast failed silently in the
DelegatingOAuth2TokenGenerator, the JwtGenerator ran for clients configured
as opaque, throwing HTTP 500 on every POST /oauth2/token request.
Fix: register SecurityJacksonModules + OAuth2AuthorizationServerJacksonModule
on the existing ObjectMapper at repo construction. Use Jackson 3's
JsonMapper.builder() pattern since the codebase is already on
tools.jackson.databind.ObjectMapper (Jackson 3 immutable mapper).
This is the minimum fix that unblocks #124's acceptance criteria
(POST /oauth2/token returns opaque token; introspection returns RFC 7662
response). The custom repo retains other architectural issues — auto-encoding
of clientSecret on save, non-interface findAll/deleteById extensions, and
the broader build-vs-buy question of why we're reimplementing Spring's
stock JdbcRegisteredClientRepository at all. Those are scoped to follow-up
issue #127.
Verified locally against a fresh MySQL container:
$ curl -u 'data_custodian_admin:{bcrypt}secret' \
-d 'grant_type=client_credentials&scope=DataCustodian_Admin_Access' \
http://localhost:9999/oauth2/token
{"access_token":"7b_HlXgKfi7V-phbFWODTJW_...","token_type":"Bearer",
"expires_in":3599,"scope":"DataCustodian_Admin_Access"}
$ curl -u 'data_custodian_admin:{bcrypt}secret' \
-d "token=$T" \
http://localhost:9999/oauth2/introspect
{"active":true,"sub":"data_custodian_admin","aud":["data_custodian_admin"],
"scope":"DataCustodian_Admin_Access","iss":"http://localhost:9999",...}
Refs: #122 #124 #127
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent a7e66a5 commit af94f97
2 files changed
Lines changed: 70 additions & 81 deletions
File tree
- openespi-authserver/src/main/java/org/greenbuttonalliance/espi/authserver
- config
- repository
Lines changed: 54 additions & 80 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
121 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
122 | 142 | | |
123 | 143 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 144 | + | |
130 | 145 | | |
131 | | - | |
132 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
133 | 150 | | |
134 | 151 | | |
135 | 152 | | |
136 | 153 | | |
137 | 154 | | |
138 | 155 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
145 | 160 | | |
146 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
147 | 184 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 185 | + | |
| 186 | + | |
157 | 187 | | |
158 | 188 | | |
159 | 189 | | |
| |||
175 | 205 | | |
176 | 206 | | |
177 | 207 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | 208 | | |
235 | 209 | | |
236 | 210 | | |
| |||
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
39 | 42 | | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
101 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
102 | 117 | | |
103 | 118 | | |
104 | 119 | | |
| |||
0 commit comments