From 69c6ad760cac20df53d84148401a4f8a23db1806 Mon Sep 17 00:00:00 2001 From: Matthias Cullmann Date: Wed, 20 Dec 2023 10:02:48 +0100 Subject: [PATCH] Replace deprecated URL constructor --- msal-client-credential-certificate/README.md | 2 +- .../src/main/java/ClientCredentialGrant.java | 6 ++++-- msal-client-credential-secret/README.md | 2 +- .../src/main/java/ClientCredentialGrant.java | 6 ++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/msal-client-credential-certificate/README.md b/msal-client-credential-certificate/README.md index 8313ea6..f4b506e 100644 --- a/msal-client-credential-certificate/README.md +++ b/msal-client-credential-certificate/README.md @@ -184,7 +184,7 @@ The relevant code for this sample is in the `ClientCredentialGrant.java` file. In this case calling "https://graph.microsoft.com/v1.0/users" with the access token as a bearer token. ```Java - URL url = new URL("https://graph.microsoft.com/v1.0/users"); + URL url = new URI("https://graph.microsoft.com/v1.0/users").toURL(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //... diff --git a/msal-client-credential-certificate/src/main/java/ClientCredentialGrant.java b/msal-client-credential-certificate/src/main/java/ClientCredentialGrant.java index 03d1bf2..571ca98 100644 --- a/msal-client-credential-certificate/src/main/java/ClientCredentialGrant.java +++ b/msal-client-credential-certificate/src/main/java/ClientCredentialGrant.java @@ -13,6 +13,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; @@ -82,8 +84,8 @@ private static IAuthenticationResult getAccessTokenByClientCredentialGrant() thr return future.get(); } - private static String getUsersListFromGraph(String accessToken) throws IOException { - URL url = new URL("https://graph.microsoft.com/v1.0/users"); + private static String getUsersListFromGraph(String accessToken) throws IOException, URISyntaxException { + URL url = new URI("https://graph.microsoft.com/v1.0/users").toURL(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); diff --git a/msal-client-credential-secret/README.md b/msal-client-credential-secret/README.md index f65d2bf..90e590f 100644 --- a/msal-client-credential-secret/README.md +++ b/msal-client-credential-secret/README.md @@ -171,7 +171,7 @@ The relevant code for this sample is in the `ClientCredentialGrant.java` file. In this case calling "https://graph.microsoft.com/v1.0/users" with the access token as a bearer token. ```Java - URL url = new URL("https://graph.microsoft.com/v1.0/users"); + URL url = new URI("https://graph.microsoft.com/v1.0/users").toURL(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //... diff --git a/msal-client-credential-secret/src/main/java/ClientCredentialGrant.java b/msal-client-credential-secret/src/main/java/ClientCredentialGrant.java index fe0d586..3a7afff 100644 --- a/msal-client-credential-secret/src/main/java/ClientCredentialGrant.java +++ b/msal-client-credential-secret/src/main/java/ClientCredentialGrant.java @@ -11,6 +11,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.Collections; import java.util.Properties; @@ -65,8 +67,8 @@ private static IAuthenticationResult getAccessTokenByClientCredentialGrant() thr return future.get(); } - private static String getUsersListFromGraph(String accessToken) throws IOException { - URL url = new URL("https://graph.microsoft.com/v1.0/users"); + private static String getUsersListFromGraph(String accessToken) throws IOException, URISyntaxException { + URL url = new URI("https://graph.microsoft.com/v1.0/users").toURL(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET");