|
|
|
@ -1401,6 +1401,7 @@ public final class SecurityMockMvcRequestPostProcessors { |
|
|
|
request = new AuthenticationRequestPostProcessor(token).postProcessRequest(request); |
|
|
|
request = new AuthenticationRequestPostProcessor(token).postProcessRequest(request); |
|
|
|
return new OAuth2ClientRequestPostProcessor() |
|
|
|
return new OAuth2ClientRequestPostProcessor() |
|
|
|
.clientRegistration(this.clientRegistration) |
|
|
|
.clientRegistration(this.clientRegistration) |
|
|
|
|
|
|
|
.principalName(oauth2User.getName()) |
|
|
|
.accessToken(this.accessToken) |
|
|
|
.accessToken(this.accessToken) |
|
|
|
.postProcessRequest(request); |
|
|
|
.postProcessRequest(request); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1587,6 +1588,7 @@ public final class SecurityMockMvcRequestPostProcessors { |
|
|
|
public final static class OAuth2ClientRequestPostProcessor implements RequestPostProcessor { |
|
|
|
public final static class OAuth2ClientRequestPostProcessor implements RequestPostProcessor { |
|
|
|
private String registrationId = "test"; |
|
|
|
private String registrationId = "test"; |
|
|
|
private ClientRegistration clientRegistration; |
|
|
|
private ClientRegistration clientRegistration; |
|
|
|
|
|
|
|
private String principalName = "user"; |
|
|
|
private OAuth2AccessToken accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, |
|
|
|
private OAuth2AccessToken accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, |
|
|
|
"access-token", null, null, Collections.singleton("read")); |
|
|
|
"access-token", null, null, Collections.singleton("read")); |
|
|
|
|
|
|
|
|
|
|
|
@ -1624,6 +1626,18 @@ public final class SecurityMockMvcRequestPostProcessors { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Use this as the resource owner's principal name |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param principalName the resource owner's principal name |
|
|
|
|
|
|
|
* @return the {@link OAuth2ClientRequestPostProcessor} for further configuration |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public OAuth2ClientRequestPostProcessor principalName(String principalName) { |
|
|
|
|
|
|
|
Assert.notNull(principalName, "principalName cannot be null"); |
|
|
|
|
|
|
|
this.principalName = principalName; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Use this {@link OAuth2AccessToken} |
|
|
|
* Use this {@link OAuth2AccessToken} |
|
|
|
* |
|
|
|
* |
|
|
|
@ -1642,7 +1656,7 @@ public final class SecurityMockMvcRequestPostProcessors { |
|
|
|
"of the clientRegistration methods"); |
|
|
|
"of the clientRegistration methods"); |
|
|
|
} |
|
|
|
} |
|
|
|
OAuth2AuthorizedClient client = new OAuth2AuthorizedClient |
|
|
|
OAuth2AuthorizedClient client = new OAuth2AuthorizedClient |
|
|
|
(this.clientRegistration, "user", this.accessToken); |
|
|
|
(this.clientRegistration, this.principalName, this.accessToken); |
|
|
|
OAuth2AuthorizedClientRepository authorizedClientRepository = |
|
|
|
OAuth2AuthorizedClientRepository authorizedClientRepository = |
|
|
|
new HttpSessionOAuth2AuthorizedClientRepository(); |
|
|
|
new HttpSessionOAuth2AuthorizedClientRepository(); |
|
|
|
authorizedClientRepository.saveAuthorizedClient(client, null, request, new MockHttpServletResponse()); |
|
|
|
authorizedClientRepository.saveAuthorizedClient(client, null, request, new MockHttpServletResponse()); |
|
|
|
|