差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| study:java:sharepointonline:implement4 [2021/07/20 08:21] – [RestTemplateWithCookies] banana | study:java:sharepointonline:implement4 [2025/08/23 13:01] (現在) – [認証クーキー取得の実装] banana | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| - | ====== 認証クーキー取得の実装 ====== | + | ====== 認証クッキー取得の実装 ====== |
| 本稿では、[[study: | 本稿では、[[study: | ||
| - | ===== Mainコード ===== | + | {{keywords> |
| + | |||
| + | ====== Mainコード | ||
| 実装Mainコードを以下に示します。 | 実装Mainコードを以下に示します。 | ||
| <code java> | <code java> | ||
| 行 39: | 行 41: | ||
| Binary tokenをPOST送信するため、Bodyに追加します。 | Binary tokenをPOST送信するため、Bodyに追加します。 | ||
| - | ===== RestTemplateWithCookies ===== | + | ====== RestTemplateWithCookies |
| RestTemplate拡張クラスを以下に示します。 | RestTemplate拡張クラスを以下に示します。 | ||
| <code java> | <code java> | ||
| 行 61: | 行 63: | ||
| } | } | ||
| - | public boolean isAuthenticated() { | + | public boolean isAuthenticated() { |
| int _count = 0; | int _count = 0; | ||
| for (HttpCookie _cookie : getCookies()) { | for (HttpCookie _cookie : getCookies()) { | ||
| 行 74: | 行 76: | ||
| /* (non-Javadoc) | /* (non-Javadoc) | ||
| - | * @see org.springframework.web.client.RestTemplate# | + | * @see org.springframework.web.client.RestTemplate# |
| + | | ||
| */ | */ | ||
| @Override | @Override | ||
| 行 85: | 行 88: | ||
| @Override | @Override | ||
| public void doWithRequest(ClientHttpRequest chr) throws IOException { | public void doWithRequest(ClientHttpRequest chr) throws IOException { | ||
| - | if (_cookies != null && _cookies.size() > 0) { | + | if (_cookies != null && _cookies.size() > 0) { |
| StringBuilder _sb = new StringBuilder(); | StringBuilder _sb = new StringBuilder(); | ||
| for (HttpCookie _cookie : _cookies) { | for (HttpCookie _cookie : _cookies) { | ||
| 行 106: | 行 109: | ||
| // ***** private method ***** | // ***** private method ***** | ||
| - | private void processHeaders(HttpHeaders headers) { | + | private void processHeaders(HttpHeaders headers) { |
| final List< | final List< | ||
| if (_rawCookies != null && !_rawCookies.isEmpty()) { | if (_rawCookies != null && !_rawCookies.isEmpty()) { | ||
| 行 138: | 行 141: | ||
| </ | </ | ||
| - | ===== Reference ===== | + | ★ポイント1\\ |
| + | cookiesリストにrtFaクッキー((このクッキーは、**「認証済みフォーム」を表す「Ready to Form authentication」の略です。Microsoft 365の認証基盤であるAzure Active Directory (Azure AD)**でユーザーが認証された際に発行されます。これは、ユーザーがシングルサインオン (SSO) セッションを確立したことを示します。))とFedAuthクッキー((このクッキーは、**「フェデレーション認証」**を表す「Federated Authentication」の略です。rtFaクッキーを使ってSharePoint Onlineにアクセスする際に、SharePoint Onlineが独自に発行するセッションクッキーです。このクッキーによって、ユーザーはSharePoint Onlineのサイトやファイルへのアクセス権を維持できます。))が存在するか確認するメソッドです。\\ | ||
| + | 既に認証済みの場合、処理を軽減させるために使われます。 | ||
| + | |||
| + | ★ポイント2\\ | ||
| + | リクエストヘッダーCookieにrtFaクッキーとFedAuthクッキーを追加します。 | ||
| + | |||
| + | ★ポイント3\\ | ||
| + | レスポンスヘッダーSet-CookieからrtFaクッキーとFedAuthクッキーを取り出して、cookiesリストに追加するメソッドです。 | ||
| + | |||
| + | |||
| + | |||
| + | ====== Reference | ||
| * [[https:// | * [[https:// | ||