๐ Understanding Proxy, Bypass & Calling Azure Token URL from Private Network
1️⃣ What is a Proxy? ๐ค
A proxy server acts as an intermediary between your computer (or app) and the internet. It forwards your requests and responses to control or monitor network traffic, improve security, or cache content.
- In private networks (like company intranets), direct internet access might be blocked.
- All outgoing calls must go through a proxy to access external services (e.g., Azure token endpoint).
2️⃣ Why do we need to configure or bypass Proxy? ๐
When your app tries to call https://login.microsoftonline.com/{tenant}/oauth2/token
,
but you are inside a private network, the call may fail if proxy is not configured properly.
Depending on your company's network setup, you might:
- Configure proxy in your Java app so the call goes through proxy.
- Bypass proxy for certain URLs if proxy blocks or slows down calls.
- Set proxy globally in the container or JVM environment (like in your
build.gradle
or Jib configuration).
3️⃣ How do we configure Proxy in Java apps? ๐ง
๐น JVM System Properties
Java uses system properties to configure proxies for HTTP/HTTPS:
-Dhttp.proxyHost=proxy.company.com -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxy.company.com -Dhttps.proxyPort=8080 -Dhttp.nonProxyHosts="localhost|127.0.0.1|*.company.local"
These are usually set via:
- Command line when starting the JVM
- In Docker container environment variables
- In
build.gradle
(for Jib builds, setting environment variables)
๐น Programmatically Setting Proxy
System.setProperty("https.proxyHost", "proxy.company.com");4️⃣ How does Java internally handle the proxy call? ๐ง
When your Java code calls HttpURLConnection
or uses libraries (RestTemplate, WebClient, etc),
- The JVM checks these proxy system properties.
- JDK classes involved:
java.net.Proxy
: represents proxy settings.java.net.InetSocketAddress
: proxy host and port.sun.net.www.protocol.http.HttpURLConnection
: opens connection via proxy if set.- The networking stack routes traffic through the proxy server.
5️⃣ What happens when you call the Azure Token Endpoint? ๐
Sequence flow:
- Your Java method calls
HttpURLConnection.openConnection()
or usesRestTemplate
. - The JVM checks if proxy is set (system properties or programmatically).
- If proxy is configured, the call is routed via proxy server (
proxy.company.com:8080
). - Proxy forwards the request to
https://login.microsoftonline.com/
. - Response from Azure comes back via proxy to your app.
6️⃣ Diagram: Proxy Call Flow Architecture ๐
Your Java Application (calls Azure Token URL) | JVM Networking Stack ( HttpURLConnection , java.net.Proxy ) | Proxy Server ( proxy.company.com:8080 ) | Azure OAuth Token Endpointlogin.microsoftonline.com |
1️⃣ Call made | 2️⃣ Check proxy settings | 3️⃣ Forward request | 4️⃣ Response sent back |
7️⃣ How we configure Proxy in Gradle/Jib build? ๐ ️
In your build.gradle
or Docker build using Jib, you set environment variables so the JVM inside the container uses the proxy:
These environment variables are picked by the JVM or HTTP client libraries at runtime to route traffic accordingly.
8️⃣ Summary ๐ก
- Proxy is a gateway between your app and the internet, often mandatory in private networks.
- Java uses
java.net.Proxy
and system properties to configure proxy settings. - You can configure proxy globally via JVM args, environment variables, or programmatically.
- When calling Azure Token URL, your request flows through proxy if configured.
- Gradle Jib plugin helps you set environment variables inside container builds.
๐ Developer Humor
Proxy servers are like your office receptionist — making sure every call goes through the right gate, sometimes making you wait but keeping things safe! ๐
Comments
Post a Comment