|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2020-2022 the original author or authors. |
|
|
|
* Copyright 2020-2023 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -18,7 +18,6 @@ package org.springframework.security.oauth2.server.authorization.web; |
|
|
|
import java.time.Duration; |
|
|
|
import java.time.Duration; |
|
|
|
import java.time.Instant; |
|
|
|
import java.time.Instant; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
@ -242,10 +241,9 @@ public class OAuth2TokenEndpointFilterTests { |
|
|
|
new HashSet<>(Arrays.asList("scope1", "scope2"))); |
|
|
|
new HashSet<>(Arrays.asList("scope1", "scope2"))); |
|
|
|
OAuth2RefreshToken refreshToken = new OAuth2RefreshToken( |
|
|
|
OAuth2RefreshToken refreshToken = new OAuth2RefreshToken( |
|
|
|
"refresh-token", Instant.now(), Instant.now().plus(Duration.ofDays(1))); |
|
|
|
"refresh-token", Instant.now(), Instant.now().plus(Duration.ofDays(1))); |
|
|
|
Map<String, Object> additionalParameters = Collections.singletonMap("custom-param", "custom-value"); |
|
|
|
|
|
|
|
OAuth2AccessTokenAuthenticationToken accessTokenAuthentication = |
|
|
|
OAuth2AccessTokenAuthenticationToken accessTokenAuthentication = |
|
|
|
new OAuth2AccessTokenAuthenticationToken( |
|
|
|
new OAuth2AccessTokenAuthenticationToken( |
|
|
|
registeredClient, clientPrincipal, accessToken, refreshToken, additionalParameters); |
|
|
|
registeredClient, clientPrincipal, accessToken, refreshToken); |
|
|
|
|
|
|
|
|
|
|
|
when(this.authenticationManager.authenticate(any())).thenReturn(accessTokenAuthentication); |
|
|
|
when(this.authenticationManager.authenticate(any())).thenReturn(accessTokenAuthentication); |
|
|
|
|
|
|
|
|
|
|
|
@ -274,7 +272,7 @@ public class OAuth2TokenEndpointFilterTests { |
|
|
|
request.getParameter(OAuth2ParameterNames.REDIRECT_URI)); |
|
|
|
request.getParameter(OAuth2ParameterNames.REDIRECT_URI)); |
|
|
|
assertThat(authorizationCodeAuthentication.getAdditionalParameters()) |
|
|
|
assertThat(authorizationCodeAuthentication.getAdditionalParameters()) |
|
|
|
.containsExactly(entry("custom-param-1", "custom-value-1"), |
|
|
|
.containsExactly(entry("custom-param-1", "custom-value-1"), |
|
|
|
entry("custom-param-2", new String[]{ "custom-value-2a", "custom-value-2b" })); |
|
|
|
entry("custom-param-2", new String[] { "custom-value-1", "custom-value-2" })); |
|
|
|
assertThat(authorizationCodeAuthentication.getDetails()) |
|
|
|
assertThat(authorizationCodeAuthentication.getDetails()) |
|
|
|
.asInstanceOf(type(WebAuthenticationDetails.class)) |
|
|
|
.asInstanceOf(type(WebAuthenticationDetails.class)) |
|
|
|
.extracting(WebAuthenticationDetails::getRemoteAddress) |
|
|
|
.extracting(WebAuthenticationDetails::getRemoteAddress) |
|
|
|
@ -292,7 +290,6 @@ public class OAuth2TokenEndpointFilterTests { |
|
|
|
accessToken.getExpiresAt().minusSeconds(1), accessToken.getExpiresAt().plusSeconds(1)); |
|
|
|
accessToken.getExpiresAt().minusSeconds(1), accessToken.getExpiresAt().plusSeconds(1)); |
|
|
|
assertThat(accessTokenResult.getScopes()).isEqualTo(accessToken.getScopes()); |
|
|
|
assertThat(accessTokenResult.getScopes()).isEqualTo(accessToken.getScopes()); |
|
|
|
assertThat(accessTokenResponse.getRefreshToken().getTokenValue()).isEqualTo(refreshToken.getTokenValue()); |
|
|
|
assertThat(accessTokenResponse.getRefreshToken().getTokenValue()).isEqualTo(refreshToken.getTokenValue()); |
|
|
|
assertThat(accessTokenResponse.getAdditionalParameters()).containsExactly(entry("custom-param", "custom-value")); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -342,7 +339,7 @@ public class OAuth2TokenEndpointFilterTests { |
|
|
|
assertThat(clientCredentialsAuthentication.getScopes()).isEqualTo(registeredClient.getScopes()); |
|
|
|
assertThat(clientCredentialsAuthentication.getScopes()).isEqualTo(registeredClient.getScopes()); |
|
|
|
assertThat(clientCredentialsAuthentication.getAdditionalParameters()) |
|
|
|
assertThat(clientCredentialsAuthentication.getAdditionalParameters()) |
|
|
|
.containsExactly(entry("custom-param-1", "custom-value-1"), |
|
|
|
.containsExactly(entry("custom-param-1", "custom-value-1"), |
|
|
|
entry("custom-param-2", new String[]{ "custom-value-2a", "custom-value-2b" })); |
|
|
|
entry("custom-param-2", new String[] { "custom-value-1", "custom-value-2" })); |
|
|
|
assertThat(clientCredentialsAuthentication.getDetails()) |
|
|
|
assertThat(clientCredentialsAuthentication.getDetails()) |
|
|
|
.asInstanceOf(type(WebAuthenticationDetails.class)) |
|
|
|
.asInstanceOf(type(WebAuthenticationDetails.class)) |
|
|
|
.extracting(WebAuthenticationDetails::getRemoteAddress) |
|
|
|
.extracting(WebAuthenticationDetails::getRemoteAddress) |
|
|
|
@ -433,7 +430,7 @@ public class OAuth2TokenEndpointFilterTests { |
|
|
|
assertThat(refreshTokenAuthenticationToken.getScopes()).isEqualTo(registeredClient.getScopes()); |
|
|
|
assertThat(refreshTokenAuthenticationToken.getScopes()).isEqualTo(registeredClient.getScopes()); |
|
|
|
assertThat(refreshTokenAuthenticationToken.getAdditionalParameters()) |
|
|
|
assertThat(refreshTokenAuthenticationToken.getAdditionalParameters()) |
|
|
|
.containsExactly(entry("custom-param-1", "custom-value-1"), |
|
|
|
.containsExactly(entry("custom-param-1", "custom-value-1"), |
|
|
|
entry("custom-param-2", new String[]{ "custom-value-2a", "custom-value-2b" })); |
|
|
|
entry("custom-param-2", new String[] { "custom-value-1", "custom-value-2" })); |
|
|
|
assertThat(refreshTokenAuthenticationToken.getDetails()) |
|
|
|
assertThat(refreshTokenAuthenticationToken.getDetails()) |
|
|
|
.asInstanceOf(type(WebAuthenticationDetails.class)) |
|
|
|
.asInstanceOf(type(WebAuthenticationDetails.class)) |
|
|
|
.extracting(WebAuthenticationDetails::getRemoteAddress) |
|
|
|
.extracting(WebAuthenticationDetails::getRemoteAddress) |
|
|
|
@ -616,7 +613,7 @@ public class OAuth2TokenEndpointFilterTests { |
|
|
|
// The client does not need to send the client ID param, but we are resilient in case they do
|
|
|
|
// The client does not need to send the client ID param, but we are resilient in case they do
|
|
|
|
request.addParameter(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId()); |
|
|
|
request.addParameter(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId()); |
|
|
|
request.addParameter("custom-param-1", "custom-value-1"); |
|
|
|
request.addParameter("custom-param-1", "custom-value-1"); |
|
|
|
request.addParameter("custom-param-2", "custom-value-2a", "custom-value-2b"); |
|
|
|
request.addParameter("custom-param-2", "custom-value-1", "custom-value-2"); |
|
|
|
|
|
|
|
|
|
|
|
return request; |
|
|
|
return request; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -631,7 +628,7 @@ public class OAuth2TokenEndpointFilterTests { |
|
|
|
request.addParameter(OAuth2ParameterNames.SCOPE, |
|
|
|
request.addParameter(OAuth2ParameterNames.SCOPE, |
|
|
|
StringUtils.collectionToDelimitedString(registeredClient.getScopes(), " ")); |
|
|
|
StringUtils.collectionToDelimitedString(registeredClient.getScopes(), " ")); |
|
|
|
request.addParameter("custom-param-1", "custom-value-1"); |
|
|
|
request.addParameter("custom-param-1", "custom-value-1"); |
|
|
|
request.addParameter("custom-param-2", "custom-value-2a", "custom-value-2b"); |
|
|
|
request.addParameter("custom-param-2", "custom-value-1", "custom-value-2"); |
|
|
|
|
|
|
|
|
|
|
|
return request; |
|
|
|
return request; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -647,7 +644,7 @@ public class OAuth2TokenEndpointFilterTests { |
|
|
|
request.addParameter(OAuth2ParameterNames.SCOPE, |
|
|
|
request.addParameter(OAuth2ParameterNames.SCOPE, |
|
|
|
StringUtils.collectionToDelimitedString(registeredClient.getScopes(), " ")); |
|
|
|
StringUtils.collectionToDelimitedString(registeredClient.getScopes(), " ")); |
|
|
|
request.addParameter("custom-param-1", "custom-value-1"); |
|
|
|
request.addParameter("custom-param-1", "custom-value-1"); |
|
|
|
request.addParameter("custom-param-2", "custom-value-2a", "custom-value-2b"); |
|
|
|
request.addParameter("custom-param-2", "custom-value-1", "custom-value-2"); |
|
|
|
|
|
|
|
|
|
|
|
return request; |
|
|
|
return request; |
|
|
|
} |
|
|
|
} |
|
|
|
|