|
|
|
|
@ -45,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired;
@@ -45,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
import org.springframework.context.annotation.Import; |
|
|
|
|
import org.springframework.context.annotation.Primary; |
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
|
import org.springframework.jdbc.core.JdbcOperations; |
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
|
@ -158,6 +159,8 @@ public class OAuth2ClientCredentialsGrantTests {
@@ -158,6 +159,8 @@ public class OAuth2ClientCredentialsGrantTests {
|
|
|
|
|
|
|
|
|
|
private static AuthenticationFailureHandler authenticationFailureHandler; |
|
|
|
|
|
|
|
|
|
private static PasswordEncoder passwordEncoder; |
|
|
|
|
|
|
|
|
|
public final SpringTestContext spring = new SpringTestContext(this); |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
@ -183,6 +186,9 @@ public class OAuth2ClientCredentialsGrantTests {
@@ -183,6 +186,9 @@ public class OAuth2ClientCredentialsGrantTests {
|
|
|
|
|
authenticationProvidersConsumer = mock(Consumer.class); |
|
|
|
|
authenticationSuccessHandler = mock(AuthenticationSuccessHandler.class); |
|
|
|
|
authenticationFailureHandler = mock(AuthenticationFailureHandler.class); |
|
|
|
|
passwordEncoder = mock(PasswordEncoder.class); |
|
|
|
|
given(passwordEncoder.matches(any(), any())).willReturn(true); |
|
|
|
|
given(passwordEncoder.upgradeEncoding(any())).willReturn(false); |
|
|
|
|
db = new EmbeddedDatabaseBuilder().generateUniqueName(true) |
|
|
|
|
.setType(EmbeddedDatabaseType.HSQL) |
|
|
|
|
.setScriptEncoding("UTF-8") |
|
|
|
|
@ -496,6 +502,26 @@ public class OAuth2ClientCredentialsGrantTests {
@@ -496,6 +502,26 @@ public class OAuth2ClientCredentialsGrantTests {
|
|
|
|
|
.andExpect(jsonPath("$.token_type").value(OAuth2AccessToken.TokenType.DPOP.getValue())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void requestWhenTokenRequestWithMultiplePasswordEncodersThenPrimaryPasswordEncoderUsed() throws Exception { |
|
|
|
|
this.spring.register(AuthorizationServerConfigurationWithMultiplePasswordEncoders.class).autowire(); |
|
|
|
|
|
|
|
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient2().build(); |
|
|
|
|
this.registeredClientRepository.save(registeredClient); |
|
|
|
|
|
|
|
|
|
this.mvc |
|
|
|
|
.perform(post(DEFAULT_TOKEN_ENDPOINT_URI) |
|
|
|
|
.param(OAuth2ParameterNames.GRANT_TYPE, AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()) |
|
|
|
|
.param(OAuth2ParameterNames.SCOPE, "scope1 scope2") |
|
|
|
|
.header(HttpHeaders.AUTHORIZATION, |
|
|
|
|
"Basic " + encodeBasicAuth(registeredClient.getClientId(), registeredClient.getClientSecret()))) |
|
|
|
|
.andExpect(status().isOk()) |
|
|
|
|
.andExpect(jsonPath("$.access_token").isNotEmpty()) |
|
|
|
|
.andExpect(jsonPath("$.scope").value("scope1 scope2")); |
|
|
|
|
|
|
|
|
|
verify(passwordEncoder).matches(any(), any()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String generateDPoPProof(String tokenEndpointUri) { |
|
|
|
|
// @formatter:off
|
|
|
|
|
Map<String, Object> publicJwk = TestJwks.DEFAULT_EC_JWK |
|
|
|
|
@ -658,4 +684,16 @@ public class OAuth2ClientCredentialsGrantTests {
@@ -658,4 +684,16 @@ public class OAuth2ClientCredentialsGrantTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EnableWebSecurity |
|
|
|
|
@Configuration(proxyBeanMethods = false) |
|
|
|
|
static class AuthorizationServerConfigurationWithMultiplePasswordEncoders extends AuthorizationServerConfiguration { |
|
|
|
|
|
|
|
|
|
@Primary |
|
|
|
|
@Bean |
|
|
|
|
PasswordEncoder primaryPasswordEncoder() { |
|
|
|
|
return passwordEncoder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|