Skip to content

Commit 34ad5fc

Browse files
committed
Rename JwtEncodingContext.getHeaders() to getJwsHeader()
Closes spring-projectsgh-826
1 parent f112183 commit 34ad5fc

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/token/JwtEncodingContext.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public boolean hasKey(Object key) {
5858
}
5959

6060
/**
61-
* Returns the {@link JwsHeader.Builder headers}
61+
* Returns the {@link JwsHeader.Builder JWS headers}
6262
* allowing the ability to add, replace, or remove.
6363
*
6464
* @return the {@link JwsHeader.Builder}
6565
*/
66-
public JwsHeader.Builder getHeaders() {
66+
public JwsHeader.Builder getJwsHeader() {
6767
return get(JwsHeader.Builder.class);
6868
}
6969

@@ -78,25 +78,25 @@ public JwtClaimsSet.Builder getClaims() {
7878
}
7979

8080
/**
81-
* Constructs a new {@link Builder} with the provided headers and claims.
81+
* Constructs a new {@link Builder} with the provided JWS headers and claims.
8282
*
83-
* @param headersBuilder the headers to initialize the builder
83+
* @param jwsHeaderBuilder the JWS headers to initialize the builder
8484
* @param claimsBuilder the claims to initialize the builder
8585
* @return the {@link Builder}
8686
*/
87-
public static Builder with(JwsHeader.Builder headersBuilder, JwtClaimsSet.Builder claimsBuilder) {
88-
return new Builder(headersBuilder, claimsBuilder);
87+
public static Builder with(JwsHeader.Builder jwsHeaderBuilder, JwtClaimsSet.Builder claimsBuilder) {
88+
return new Builder(jwsHeaderBuilder, claimsBuilder);
8989
}
9090

9191
/**
9292
* A builder for {@link JwtEncodingContext}.
9393
*/
9494
public static final class Builder extends AbstractBuilder<JwtEncodingContext, Builder> {
9595

96-
private Builder(JwsHeader.Builder headersBuilder, JwtClaimsSet.Builder claimsBuilder) {
97-
Assert.notNull(headersBuilder, "headersBuilder cannot be null");
96+
private Builder(JwsHeader.Builder jwsHeaderBuilder, JwtClaimsSet.Builder claimsBuilder) {
97+
Assert.notNull(jwsHeaderBuilder, "jwsHeaderBuilder cannot be null");
9898
Assert.notNull(claimsBuilder, "claimsBuilder cannot be null");
99-
put(JwsHeader.Builder.class, headersBuilder);
99+
put(JwsHeader.Builder.class, jwsHeaderBuilder);
100100
put(JwtClaimsSet.Builder.class, claimsBuilder);
101101
}
102102

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/token/JwtGenerator.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ public Jwt generate(OAuth2TokenContext context) {
125125
}
126126
// @formatter:on
127127

128-
JwsHeader.Builder headersBuilder = JwsHeader.with(SignatureAlgorithm.RS256);
128+
JwsHeader.Builder jwsHeaderBuilder = JwsHeader.with(SignatureAlgorithm.RS256);
129129

130130
if (this.jwtCustomizer != null) {
131131
// @formatter:off
132-
JwtEncodingContext.Builder jwtContextBuilder = JwtEncodingContext.with(headersBuilder, claimsBuilder)
132+
JwtEncodingContext.Builder jwtContextBuilder = JwtEncodingContext.with(jwsHeaderBuilder, claimsBuilder)
133133
.registeredClient(context.getRegisteredClient())
134134
.principal(context.getPrincipal())
135135
.providerContext(context.getProviderContext())
@@ -148,17 +148,17 @@ public Jwt generate(OAuth2TokenContext context) {
148148
this.jwtCustomizer.customize(jwtContext);
149149
}
150150

151-
JwsHeader headers = headersBuilder.build();
151+
JwsHeader jwsHeader = jwsHeaderBuilder.build();
152152
JwtClaimsSet claims = claimsBuilder.build();
153153

154-
Jwt jwt = this.jwtEncoder.encode(JwtEncoderParameters.from(headers, claims));
154+
Jwt jwt = this.jwtEncoder.encode(JwtEncoderParameters.from(jwsHeader, claims));
155155

156156
return jwt;
157157
}
158158

159159
/**
160160
* Sets the {@link OAuth2TokenCustomizer} that customizes the
161-
* {@link JwtEncodingContext#getHeaders() headers} and/or
161+
* {@link JwtEncodingContext#getJwsHeader() JWS headers} and/or
162162
* {@link JwtEncodingContext#getClaims() claims} for the generated {@link Jwt}.
163163
*
164164
* @param jwtCustomizer the {@link OAuth2TokenCustomizer} that customizes the headers and/or claims for the generated {@code Jwt}

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2AuthorizationCodeAuthenticationProviderTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public void authenticateWhenValidCodeThenReturnAccessToken() {
414414
assertThat(jwtEncodingContext.getTokenType()).isEqualTo(OAuth2TokenType.ACCESS_TOKEN);
415415
assertThat(jwtEncodingContext.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
416416
assertThat(jwtEncodingContext.<OAuth2AuthorizationGrantAuthenticationToken>getAuthorizationGrant()).isEqualTo(authentication);
417-
assertThat(jwtEncodingContext.getHeaders()).isNotNull();
417+
assertThat(jwtEncodingContext.getJwsHeader()).isNotNull();
418418
assertThat(jwtEncodingContext.getClaims()).isNotNull();
419419

420420
ArgumentCaptor<JwtEncoderParameters> jwtEncoderParametersCaptor = ArgumentCaptor.forClass(JwtEncoderParameters.class);
@@ -474,7 +474,7 @@ public void authenticateWhenValidCodeAndAuthenticationRequestThenReturnIdToken()
474474
assertThat(accessTokenContext.getTokenType()).isEqualTo(OAuth2TokenType.ACCESS_TOKEN);
475475
assertThat(accessTokenContext.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
476476
assertThat(accessTokenContext.<OAuth2AuthorizationGrantAuthenticationToken>getAuthorizationGrant()).isEqualTo(authentication);
477-
assertThat(accessTokenContext.getHeaders()).isNotNull();
477+
assertThat(accessTokenContext.getJwsHeader()).isNotNull();
478478
assertThat(accessTokenContext.getClaims()).isNotNull();
479479
Map<String, Object> claims = new HashMap<>();
480480
accessTokenContext.getClaims().claims(claims::putAll);
@@ -491,7 +491,7 @@ public void authenticateWhenValidCodeAndAuthenticationRequestThenReturnIdToken()
491491
assertThat(idTokenContext.getTokenType().getValue()).isEqualTo(OidcParameterNames.ID_TOKEN);
492492
assertThat(idTokenContext.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
493493
assertThat(idTokenContext.<OAuth2AuthorizationGrantAuthenticationToken>getAuthorizationGrant()).isEqualTo(authentication);
494-
assertThat(idTokenContext.getHeaders()).isNotNull();
494+
assertThat(idTokenContext.getJwsHeader()).isNotNull();
495495
assertThat(idTokenContext.getClaims()).isNotNull();
496496

497497
verify(this.jwtEncoder, times(2)).encode(any()); // Access token and ID Token
@@ -548,7 +548,7 @@ public void authenticateWhenPublicClientThenRefreshTokenNotIssued() {
548548
assertThat(jwtEncodingContext.getTokenType()).isEqualTo(OAuth2TokenType.ACCESS_TOKEN);
549549
assertThat(jwtEncodingContext.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
550550
assertThat(jwtEncodingContext.<OAuth2AuthorizationGrantAuthenticationToken>getAuthorizationGrant()).isEqualTo(authentication);
551-
assertThat(jwtEncodingContext.getHeaders()).isNotNull();
551+
assertThat(jwtEncodingContext.getJwsHeader()).isNotNull();
552552
assertThat(jwtEncodingContext.getClaims()).isNotNull();
553553

554554
ArgumentCaptor<JwtEncoderParameters> jwtEncoderParametersCaptor = ArgumentCaptor.forClass(JwtEncoderParameters.class);

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2ClientCredentialsAuthenticationProviderTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public void authenticateWhenValidAuthenticationThenReturnAccessToken() {
252252
assertThat(jwtEncodingContext.getTokenType()).isEqualTo(OAuth2TokenType.ACCESS_TOKEN);
253253
assertThat(jwtEncodingContext.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.CLIENT_CREDENTIALS);
254254
assertThat(jwtEncodingContext.<OAuth2AuthorizationGrantAuthenticationToken>getAuthorizationGrant()).isEqualTo(authentication);
255-
assertThat(jwtEncodingContext.getHeaders()).isNotNull();
255+
assertThat(jwtEncodingContext.getJwsHeader()).isNotNull();
256256
assertThat(jwtEncodingContext.getClaims()).isNotNull();
257257

258258
ArgumentCaptor<OAuth2Authorization> authorizationCaptor = ArgumentCaptor.forClass(OAuth2Authorization.class);

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2RefreshTokenAuthenticationProviderTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void authenticateWhenValidRefreshTokenThenReturnAccessToken() {
178178
assertThat(jwtEncodingContext.getTokenType()).isEqualTo(OAuth2TokenType.ACCESS_TOKEN);
179179
assertThat(jwtEncodingContext.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.REFRESH_TOKEN);
180180
assertThat(jwtEncodingContext.<OAuth2AuthorizationGrantAuthenticationToken>getAuthorizationGrant()).isEqualTo(authentication);
181-
assertThat(jwtEncodingContext.getHeaders()).isNotNull();
181+
assertThat(jwtEncodingContext.getJwsHeader()).isNotNull();
182182
assertThat(jwtEncodingContext.getClaims()).isNotNull();
183183

184184
ArgumentCaptor<OAuth2Authorization> authorizationCaptor = ArgumentCaptor.forClass(OAuth2Authorization.class);
@@ -223,7 +223,7 @@ public void authenticateWhenValidRefreshTokenThenReturnIdToken() {
223223
assertThat(accessTokenContext.getTokenType()).isEqualTo(OAuth2TokenType.ACCESS_TOKEN);
224224
assertThat(accessTokenContext.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.REFRESH_TOKEN);
225225
assertThat(accessTokenContext.<OAuth2AuthorizationGrantAuthenticationToken>getAuthorizationGrant()).isEqualTo(authentication);
226-
assertThat(accessTokenContext.getHeaders()).isNotNull();
226+
assertThat(accessTokenContext.getJwsHeader()).isNotNull();
227227
assertThat(accessTokenContext.getClaims()).isNotNull();
228228
Map<String, Object> claims = new HashMap<>();
229229
accessTokenContext.getClaims().claims(claims::putAll);
@@ -240,7 +240,7 @@ public void authenticateWhenValidRefreshTokenThenReturnIdToken() {
240240
assertThat(idTokenContext.getTokenType().getValue()).isEqualTo(OidcParameterNames.ID_TOKEN);
241241
assertThat(idTokenContext.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.REFRESH_TOKEN);
242242
assertThat(idTokenContext.<OAuth2AuthorizationGrantAuthenticationToken>getAuthorizationGrant()).isEqualTo(authentication);
243-
assertThat(idTokenContext.getHeaders()).isNotNull();
243+
assertThat(idTokenContext.getJwsHeader()).isNotNull();
244244
assertThat(idTokenContext.getClaims()).isNotNull();
245245

246246
verify(this.jwtEncoder, times(2)).encode(any()); // Access token and ID Token

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/token/JwtEncodingContextTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
public class JwtEncodingContextTests {
4747

4848
@Test
49-
public void withWhenHeadersNullThenThrowIllegalArgumentException() {
49+
public void withWhenJwsHeaderNullThenThrowIllegalArgumentException() {
5050
assertThatThrownBy(() -> JwtEncodingContext.with(null, TestJwtClaimsSets.jwtClaimsSet()))
5151
.isInstanceOf(IllegalArgumentException.class)
52-
.hasMessage("headersBuilder cannot be null");
52+
.hasMessage("jwsHeaderBuilder cannot be null");
5353
}
5454

5555
@Test
@@ -105,7 +105,7 @@ public void buildWhenAllValuesProvidedThenAllValuesAreSet() {
105105
.context(ctx -> ctx.put("custom-key-2", "custom-value-2"))
106106
.build();
107107

108-
assertThat(context.getHeaders()).isEqualTo(headers);
108+
assertThat(context.getJwsHeader()).isEqualTo(headers);
109109
assertThat(context.getClaims()).isEqualTo(claims);
110110
assertThat(context.getRegisteredClient()).isEqualTo(registeredClient);
111111
assertThat(context.<Authentication>getPrincipal()).isEqualTo(principal);

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/token/JwtGeneratorTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void assertGeneratedTokenType(OAuth2TokenContext tokenContext) {
187187
verify(this.jwtCustomizer).customize(jwtEncodingContextCaptor.capture());
188188

189189
JwtEncodingContext jwtEncodingContext = jwtEncodingContextCaptor.getValue();
190-
assertThat(jwtEncodingContext.getHeaders()).isNotNull();
190+
assertThat(jwtEncodingContext.getJwsHeader()).isNotNull();
191191
assertThat(jwtEncodingContext.getClaims()).isNotNull();
192192
assertThat(jwtEncodingContext.getRegisteredClient()).isEqualTo(tokenContext.getRegisteredClient());
193193
assertThat(jwtEncodingContext.<Authentication>getPrincipal()).isEqualTo(tokenContext.getPrincipal());

0 commit comments

Comments
 (0)