次のコードが与えられた場合、アプリケーションランナーでクライアント資格情報で保護されたAPIを呼び出すことは可能ですか?
@Bean
public ApplicationRunner test(
WebClient.Builder builder,
ClientRegistrationRepository clientRegistrationRepo,
OAuth2AuthorizedClientRepository authorizedClient) {
return args -> {
try {
var oauth2 =
new ServletOAuth2AuthorizedClientExchangeFilterFunction(
clientRegistrationRepo,
authorizedClient);
oauth2.setDefaultClientRegistrationId("test");
var response = builder
.apply(oauth2.oauth2Configuration())
.build()
.get()
.uri("test")
.retrieve()
.bodyToMono(String.class)
.block();
log.info("Response - {}", response);
} catch (Exception e) {
log.error("Failed to call test.", e);
}
};
}
次の理由でコードが失敗します。
java.lang.IllegalArgumentException: request cannot be null
フルスタック、
java.lang.IllegalArgumentException: request cannot be null
at org.springframework.util.Assert.notNull(Assert.java:198) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizedClientRepository.loadAuthorizedClient(HttpSessionOAuth2AuthorizedClientRepository.java:47) ~[spring-security-oauth2-client-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction.populateDefaultOAuth2AuthorizedClient(ServletOAuth2AuthorizedClientExchangeFilterFunction.java:364) ~[spring-security-oauth2-client-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction.lambda$null$2(ServletOAuth2AuthorizedClientExchangeFilterFunction.java:209) ~[spring-security-oauth2-client-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.attributes(DefaultWebClient.java:234) ~[spring-webflux-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.attributes(DefaultWebClient.java:153) ~[spring-webflux-5.1.5.RELEASE.jar:5.1.5.RELEASE]
失敗したメソッドは次のようになります。
public <T extends OAuth2AuthorizedClient> T loadAuthorizedClient(
String clientRegistrationId, Authentication principal, HttpServletRequest request){
Assert.hasText(clientRegistrationId, "clientRegistrationId cannot be empty");
Assert.notNull(request, "request cannot be null");
return (OAuth2AuthorizedClient)this
.getAuthorizedClients(request)
.get(clientRegistrationId);
}
HttpServletRequest
アプリケーションの起動時に呼び出されるため、使用する必要がないため、これは理にかなっています。
自分でno-opを作成する以外の回避策はありますOAuth2AuthorizedClientRepository
か?
//編集、
これは完全にリアクティブなスタックではありません。これは、WebClientが使用されているSpringWebスタックです。
私は、ServerOAuth2AuthorizedClientExchangeFilterFunction
これが完全にリアクティブなスタックに適用され、必要でありReactiveClientRegistrationRepository
、ReactiveOauth2AuthorizedClient
これがサーブレットスタック上に構築されたアプリケーションにあり、リアクティブではないために利用できないことをよく知っています。
私もこの問題に遭遇したので、他の人が見つけやすくするために、DarrenForsytheの更新された回答について少し詳しく説明します。
OPによって提出された問題は、次のOAuth2AuthorizedClientManager
ことが可能な実装をもたらしました。
HttpServletRequestコンテキストの外部、たとえばスケジュールされた/バックグラウンドスレッドおよび/またはサービス層での操作
(公式ドキュメントから)
上記の実装であるAuthorizedClientServiceOAuth2AuthorizedClientManager
、はServletOAuth2AuthorizedClientExchangeFilterFunction
、デフォルトの実装を置き換えるためにに渡されます。
私の例では、これは次のようになります。
@Bean
public OAuth2AuthorizedClientManager authorizedClientManager(
ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientService clientService)
{
OAuth2AuthorizedClientProvider authorizedClientProvider =
OAuth2AuthorizedClientProviderBuilder.builder()
.clientCredentials()
.build();
AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager =
new AuthorizedClientServiceOAuth2AuthorizedClientManager(
clientRegistrationRepository, clientService);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
return authorizedClientManager;
}
@Bean
WebClient webClient(OAuth2AuthorizedClientManager authorizedClientManager)
{
ServletOAuth2AuthorizedClientExchangeFilterFunction oauth2 =
new ServletOAuth2AuthorizedClientExchangeFilterFunction(
authorizedClientManager);
oauth2.setDefaultClientRegistrationId("keycloak");
return WebClient.builder().apply(oauth2.oauth2Configuration()).build();
}
私はこれをSpringSecurityチームに尋ねることになりました。
https://github.com/spring-projects/spring-security/issues/6683
残念ながら、サーブレットスタックを使用していて、バックグラウンドスレッドで純粋なSpring Security 5 APIを使用してOAuth2リソースを呼び出す場合、OAuth2AuthorizedClientRepository
利用できるものはありません。
現実的には2つのオプションがあります。
var oauth2 = new ServletOAuth2AuthorizedClientExchangeFilterFunction(clientRegistrationRepo,
new OAuth2AuthorizedClientRepository() {
@Override
public <T extends OAuth2AuthorizedClient> T loadAuthorizedClient(String s,
Authentication authentication, HttpServletRequest httpServletRequest) {
return null;
}
@Override
public void saveAuthorizedClient(OAuth2AuthorizedClient oAuth2AuthorizedClient,
Authentication authentication, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
}
@Override
public void removeAuthorizedClient(String s, Authentication authentication,
HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
}
});
UnAuthenticatedServerOAuth2AuthorizedClientRepository
ます。UnAuthenticatedServerOAuth2AuthorizedClientRepositoryGitHubソース。純粋なno-opよりもいくつかの基本的な機能があります。
GitHubの問題に関するフィードバックを提供することで、SpringSecurityチームがPRの受け入れとサーブレットバージョンの維持を評価するのに役立つ可能性があります。
UnAuthenticatedServerOAuth2AuthorizedClientRepository
Spring SecurityTeamのSpringSecurity Issue 6683に連絡しました。その裏側で、サーブレットバージョンがServerOAuth2AuthorizedClientExchangeFilterFunction
Spring Security 5.2に追加され、http以外のスレッドで使用できるようになります。
Reba McEntire が息子の Shelby Blackstock と共有しているクリスマスの伝統について学びましょう。
メーガン・マークルとマライア・キャリーが自然な髪の上でどのように結合したかについて、メーガンの「アーキタイプ」ポッドキャストのエピソードで学びましょう.
ハリー王子が家族、特にチャールズ王とウィリアム王子との関係について望んでいると主張したある情報源を発見してください。
ワイノナ・ジャッドが、母親のナオミ・ジャッドが亡くなってから初めての感謝祭のお祝いを主催しているときに、彼女が今では家長であることをどのように認識したかを学びましょう.
Air travel is far more than getting from point A to point B safely. How much do you know about the million little details that go into flying on airplanes?
The world is a huge place, yet some GeoGuessr players know locations in mere seconds. Are you one of GeoGuessr's gifted elite? Take our quiz to find out!
深夜のアンバー・ラフィンとジェニー・ヘーゲルが繰り返し「ジョーク・セス・カント・テル」で戻ってきました。これらのジョークの多くは観客をがっかりさせますが、最初から最後まで素晴らしいです。ルフィンとヘーゲルは黒人女性として自己紹介します。とゲイの女性、それぞれ、したがって、セスマイヤーズが10フィートのポールで触れることができない主題について賢明にクラックすることができます。
(写真:ライオンズゲート)この「キアヌ・リーブスはダッパースーツを着て人々を殺害する」というモチーフ全体が手元にあることをはっきりと知っているライオンズゲートは、スタイリッシュで復讐に燃えるジョン・ウィックのフランチャイズで3回目のリリース日を設定しました。犬をベースにした復讐のためのババ・ヤガの果てしない十字軍を支えるバットシット神話をより深く掘り下げることを約束する3番目のジョン・ウィック映画は、2019年5月17日に設定されました。これまでのところ、それはその日に上陸した唯一の映画です。
写真:NBCパイロットは良すぎるのでしょうか?ありそうもないようですが、This IsUsのファンの場合はそうかもしれません。クレイジー、バカ、ラブライターのダン・フォーゲルマンからの待望の新シリーズは、ツイストエンディングを中心に展開しています。シリーズを適切に設定しますが、非常に巧妙に行われているため、改善の余地はあまりありません。
ここにいくつかのニュースがあります:あなたは今FacebookにGIFを埋め込むことができます。まあ、技術的には、GIFへのリンクを投稿することができ、Facebookは、他のほとんどすべてのソーシャルネットワークが何年も行ってきたようにアニメーションを作成します。
ロシアのフィギュアスケーター、カミラ・バリエバが関与したドーピング事件が整理されているため、チームは2022年北京冬季オリンピックで獲得したメダルを待っています。
何千人ものAmazonの買い物客がMulberry Silk Pillowcaseを推奨しており、現在販売中. シルクの枕カバーにはいくつかの色があり、髪を柔らかく肌を透明に保ちます。Amazonで最大46%オフになっている間にシルクの枕カバーを購入してください
ラファイエット警察署は、「不審な男性が女性に近づいた」という複数の苦情を受けて、12 月にパデュー大学の教授の捜査を開始しました。
私たちの周りの世界と同じように、言語は常に変化しています。以前の時代では、言語の変化は数年または数十年にわたって発生していましたが、現在では数日または数時間で変化する可能性があります。
認知症を患っている 91 歳のアジア人女性が最近、47 番街のアウター サンセット地区でロメオ ロレンゾ パーハムに襲われました。伝えられるところによると、被害者はサンフランシスコの通りを歩いていたところ、容疑者に近づき、攻撃を受け、暴行を受けました。
Cómo mejoramos la accesibilidad de nuestro componente de precio, y cómo nos marcó el camino hacia nuevos saberes para nuestro sistema de diseño. Por Ana Calderon y Laura Sarmiento Leer esta historia en inglés.
“And a river went out of Eden to water the garden, and from thence it was parted and became into four heads” Genesis 2:10. ? The heart is located in the middle of the thoracic cavity, pointing eastward.