Skip to content

Commit 544f635

Browse files
committed
Polish gh-17246
1 parent e4dcffa commit 544f635

2 files changed

Lines changed: 48 additions & 47 deletions

File tree

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
*
6161
* @author Evgeniy Cheban
6262
* @since 7.1
63+
* @see RefreshTokenReactiveOAuth2AuthorizedClientProvider
6364
*/
6465
public final class RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler
6566
implements ReactiveOAuth2AuthorizationSuccessHandler {
@@ -158,16 +159,6 @@ public void setJwtDecoderFactory(ReactiveJwtDecoderFactory<ClientRegistration> j
158159
this.jwtDecoderFactory = jwtDecoderFactory;
159160
}
160161

161-
/**
162-
* Sets a {@link GrantedAuthoritiesMapper} to use for mapping
163-
* {@link GrantedAuthority}s, defaults to no-op implementation.
164-
* @param authoritiesMapper the {@link GrantedAuthoritiesMapper} to use
165-
*/
166-
public void setAuthoritiesMapper(GrantedAuthoritiesMapper authoritiesMapper) {
167-
Assert.notNull(authoritiesMapper, "authoritiesMapper cannot be null");
168-
this.authoritiesMapper = authoritiesMapper;
169-
}
170-
171162
/**
172163
* Sets a {@link ReactiveOAuth2UserService} to use for loading an {@link OidcUser}
173164
* from refreshed oidc id-token, defaults to {@link OidcReactiveOAuth2UserService}.
@@ -178,6 +169,16 @@ public void setUserService(ReactiveOAuth2UserService<OidcUserRequest, OidcUser>
178169
this.userService = userService;
179170
}
180171

172+
/**
173+
* Sets a {@link GrantedAuthoritiesMapper} to use for mapping
174+
* {@link GrantedAuthority}s, defaults to no-op implementation.
175+
* @param authoritiesMapper the {@link GrantedAuthoritiesMapper} to use
176+
*/
177+
public void setAuthoritiesMapper(GrantedAuthoritiesMapper authoritiesMapper) {
178+
Assert.notNull(authoritiesMapper, "authoritiesMapper cannot be null");
179+
this.authoritiesMapper = authoritiesMapper;
180+
}
181+
181182
/**
182183
* Sets the maximum acceptable clock skew, which is used when checking the
183184
* {@link OidcIdToken#getIssuedAt()} to match the existing
@@ -297,7 +298,7 @@ private Mono<Void> refreshSecurityContext(ServerWebExchange exchange, ClientRegi
297298
OAuth2AuthenticationToken authenticationResult = new OAuth2AuthenticationToken(oidcUser, mappedAuthorities,
298299
clientRegistration.getRegistrationId());
299300
authenticationResult.setDetails(authenticationToken.getDetails());
300-
SecurityContextImpl securityContext = new SecurityContextImpl(authenticationResult);
301+
SecurityContext securityContext = new SecurityContextImpl(authenticationResult);
301302
return this.serverSecurityContextRepository.save(exchange, securityContext);
302303
}
303304

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandlerTests.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,42 @@
6060
*/
6161
class RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandlerTests {
6262

63+
@Test
64+
void setServerSecurityContextRepositoryWhenNullThenException() {
65+
assertThatException()
66+
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler()
67+
.setServerSecurityContextRepository(null))
68+
.withMessage("serverSecurityContextRepository cannot be null");
69+
}
70+
71+
@Test
72+
void setJwtDecoderFactoryWhenNullThenException() {
73+
assertThatException()
74+
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler().setJwtDecoderFactory(null))
75+
.withMessage("jwtDecoderFactory cannot be null");
76+
}
77+
78+
@Test
79+
void setAuthoritiesMapperWhenNullThenException() {
80+
assertThatException()
81+
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler().setAuthoritiesMapper(null))
82+
.withMessage("authoritiesMapper cannot be null");
83+
}
84+
85+
@Test
86+
void setUserServiceWhenNullThenException() {
87+
assertThatException()
88+
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler().setUserService(null))
89+
.withMessage("userService cannot be null");
90+
}
91+
92+
@Test
93+
void setClockSkewWhenNullThenException() {
94+
assertThatException()
95+
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler().setClockSkew(null))
96+
.withMessage("clockSkew cannot be null");
97+
}
98+
6399
@Test
64100
void onAuthorizationSuccessWhenIdTokenValidThenSecurityContextRefreshed() {
65101
ClientRegistration clientRegistration = TestClientRegistrations.clientRegistration().build();
@@ -352,42 +388,6 @@ void onAuthorizationSuccessWhenIdTokenNonceNotSameThenException() {
352388
.verifyErrorMessage("[invalid_nonce] Invalid nonce");
353389
}
354390

355-
@Test
356-
void setServerSecurityContextRepositoryWhenNullThenException() {
357-
assertThatException()
358-
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler()
359-
.setServerSecurityContextRepository(null))
360-
.withMessage("serverSecurityContextRepository cannot be null");
361-
}
362-
363-
@Test
364-
void setJwtDecoderFactoryWhenNullThenException() {
365-
assertThatException()
366-
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler().setJwtDecoderFactory(null))
367-
.withMessage("jwtDecoderFactory cannot be null");
368-
}
369-
370-
@Test
371-
void setAuthoritiesMapperWhenNullThenException() {
372-
assertThatException()
373-
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler().setAuthoritiesMapper(null))
374-
.withMessage("authoritiesMapper cannot be null");
375-
}
376-
377-
@Test
378-
void setUserServiceWhenNullThenException() {
379-
assertThatException()
380-
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler().setUserService(null))
381-
.withMessage("userService cannot be null");
382-
}
383-
384-
@Test
385-
void setClockSkewWhenNullThenException() {
386-
assertThatException()
387-
.isThrownBy(() -> new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler().setClockSkew(null))
388-
.withMessage("clockSkew cannot be null");
389-
}
390-
391391
private static OAuth2AccessToken createAccessToken() {
392392
Instant issuedAt = Instant.now().minus(Duration.ofDays(1));
393393
Instant expiresAt = issuedAt.plus(Duration.ofMinutes(60));

0 commit comments

Comments
 (0)