Skip to content

Commit ad01779

Browse files
committed
Polish gh-1105
1 parent 0255a24 commit ad01779

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/ClientSecretAuthenticationProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,7 +126,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
126126
registeredClient = RegisteredClient.from(registeredClient)
127127
.clientSecret(this.passwordEncoder.encode(clientSecret))
128128
.build();
129-
registeredClientRepository.save(registeredClient);
129+
this.registeredClientRepository.save(registeredClient);
130130
}
131131

132132
if (this.logger.isTraceEnabled()) {

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/client/InMemoryRegisteredClientRepository.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,14 +72,11 @@ public InMemoryRegisteredClientRepository(List<RegisteredClient> registrations)
7272
@Override
7373
public void save(RegisteredClient registeredClient) {
7474
Assert.notNull(registeredClient, "registeredClient cannot be null");
75-
if (this.idRegistrationMap.containsKey(registeredClient.getId())) {
76-
this.idRegistrationMap.put(registeredClient.getId(), registeredClient);
77-
this.clientIdRegistrationMap.put(registeredClient.getClientId(), registeredClient);
78-
} else {
75+
if (!this.idRegistrationMap.containsKey(registeredClient.getId())) {
7976
assertUniqueIdentifiers(registeredClient, this.idRegistrationMap);
80-
this.idRegistrationMap.put(registeredClient.getId(), registeredClient);
81-
this.clientIdRegistrationMap.put(registeredClient.getClientId(), registeredClient);
8277
}
78+
this.idRegistrationMap.put(registeredClient.getId(), registeredClient);
79+
this.clientIdRegistrationMap.put(registeredClient.getClientId(), registeredClient);
8380
}
8481

8582
@Nullable

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -228,7 +228,7 @@ public void authenticateWhenValidCredentialsThenAuthenticated() {
228228
}
229229

230230
@Test
231-
public void authenticateWhenValidCredentialsAndNonExpiredThenPasswordUpgraded() {
231+
public void authenticateWhenValidCredentialsAndRequiresUpgradingThenClientSecretUpgraded() {
232232
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
233233
when(this.registeredClientRepository.findByClientId(eq(registeredClient.getClientId())))
234234
.thenReturn(registeredClient);
@@ -243,10 +243,9 @@ public void authenticateWhenValidCredentialsAndNonExpiredThenPasswordUpgraded()
243243
verify(this.passwordEncoder).encode(any());
244244
verify(this.registeredClientRepository).save(any());
245245
assertThat(authenticationResult.isAuthenticated()).isTrue();
246-
assertThat(registeredClient).isNotSameAs(authenticationResult.getPrincipal());
247246
assertThat(authenticationResult.getPrincipal().toString()).isEqualTo(registeredClient.getClientId());
248247
assertThat(authenticationResult.getCredentials().toString()).isEqualTo(registeredClient.getClientSecret());
249-
assertThat(authenticationResult.getRegisteredClient()).isEqualTo(registeredClient);
248+
assertThat(authenticationResult.getRegisteredClient()).isNotSameAs(registeredClient);
250249
}
251250

252251
@Test

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/client/InMemoryRegisteredClientRepositoryTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -155,10 +155,10 @@ public void saveWhenNullThenThrowIllegalArgumentException() {
155155
@Test
156156
public void saveWhenExistingIdThenUpdate() {
157157
RegisteredClient registeredClient = createRegisteredClient(
158-
this.registration.getId(), "client-id", "client-secret-2");
158+
this.registration.getId(), "client-id-2", "client-secret-2");
159159
this.clients.save(registeredClient);
160160
RegisteredClient savedClient = this.clients.findByClientId(registeredClient.getClientId());
161-
assertThat(savedClient.getClientSecret()).isEqualTo("client-secret-2");
161+
assertThat(savedClient).isEqualTo(registeredClient);
162162
}
163163

164164
@Test

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/config/annotation/web/configurers/OAuth2ClientCredentialsGrantTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -233,7 +233,7 @@ public void requestWhenTokenRequestPostsClientCredentialsThenTokenResponse() thr
233233
}
234234

235235
@Test
236-
public void requestWhenTokenRequestPostsClientCredentialsThenTokenResponseAndSecretUpgraded() throws Exception {
236+
public void requestWhenTokenRequestPostsClientCredentialsAndRequiresUpgradingThenClientSecretUpgraded() throws Exception {
237237
this.spring.register(AuthorizationServerConfigurationCustomPasswordEncoder.class).autowire();
238238

239239
String clientSecret = "secret-2";
@@ -250,7 +250,8 @@ public void requestWhenTokenRequestPostsClientCredentialsThenTokenResponseAndSec
250250
.andExpect(jsonPath("$.scope").value("scope1 scope2"));
251251

252252
verify(jwtCustomizer).customize(any());
253-
assertThat(this.registeredClientRepository.findByClientId(registeredClient.getClientId()).getClientSecret()).startsWith("{bcrypt}");
253+
RegisteredClient updatedRegisteredClient = this.registeredClientRepository.findByClientId(registeredClient.getClientId());
254+
assertThat(updatedRegisteredClient.getClientSecret()).startsWith("{bcrypt}");
254255
}
255256

256257
@Test

0 commit comments

Comments
 (0)