Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

ADAL4j proxy issue for java #71

Closed
mathewvino opened this issue Nov 6, 2015 · 6 comments
Closed

ADAL4j proxy issue for java #71

mathewvino opened this issue Nov 6, 2015 · 6 comments

Comments

@mathewvino
Copy link

Hi there,

I am trying to connect azure using adal4j1.1 library for java.But i have to connect through the proxy.Following is the snippet of code

String url = "https://login.microsoftonline.com/tenant_id/oauth2/authorize";
authContext = new AuthenticationContext(url,false,
service);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyhostname", 443));
authContext.setProxy(proxy);
ClientCredential clientCred = new ClientCredential(XXXX, xxxx);
Future future = authContext.acquireToken(
clientCred,
null);
authResult = future.get();
Also i have tried with

        System.setProperty("http.proxyPort", "80");
        System.setProperty("http.proxyUser", "xxxx");
        System.setProperty("http.proxyPassword", "xxxx");
        System.setProperty("http.proxyHost", "xxxxxxx");

And all the time i am getting this following error

the error is.....java.net.ConnectException: Connection timed out: connect
java.util.concurrent.ExecutionException: java.net.ConnectException: Connection timed out: connect
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at com.toyota.eap.auth.Test.main(Test.java:76)
Caused by: java.net.ConnectException: Connection timed out: connect

Note: This error is only if we have proxy within the office. From outside the office If I ran thisprogramme there is no issue.

Any Thought on this.

Thanks

@RandalliLama
Copy link

@mathewvino Do you have an issue when ADAL is not involved. i.e. can you reach other internet endpoints through the proxy outside of ADAL?

@mathewvino
Copy link
Author

Yes I can if i use the HTTPConnection call I am getting the output.

Please find the code snippet

import java.io.DataInputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;

public class Proxy5 {

public static void main(String[] args) {
    try {
        DataInputStream di = null;
       byte [] b = new byte[1];
       Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy url", 80));
       URL u = new URL("https://login.microsoftonline.com/tenanntid/oauth2/authorize?grant_type=client_credentials&client_id=xxxxx&client_secret=xxxxxxx");
        HttpURLConnection con = (HttpURLConnection) u.openConnection(proxy);
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
       di = new DataInputStream(con.getInputStream());
        while(-1 != di.read(b,0,1)) {
           System.out.print(new String(b));
        }
      }
      catch (Exception e) {
              e.printStackTrace();
      }

}

}

@RandalliLama
Copy link

@mathewvino Does it make a difference that the port you specify in your code snippet at the top of this issue is port 443, which fails, but the port you put in your last snippet is port 80?

@mathewvino
Copy link
Author

Nope i have tried with 80 and then change it to 443. The exception throwing is Connection time out

the error is.....java.net.ConnectException: Connection timed out: connect
java.util.concurrent.ExecutionException: java.net.ConnectException: Connection timed out: connect
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at com.toyota.eap.auth.Test.main(Test.java:76)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)

@brandwe
Copy link
Contributor

brandwe commented Nov 9, 2015

@mathewvino Is there any way you can run a Fiddler or Charles trace so we can see the actual responses back and forth? I have a feeling your proxy and our setProxy() aren't playing nice together. Knowing where in the hop it stops is always helpful. You can send the log to our email thread if it's sensitive.

@mathewvino
Copy link
Author

I am using windows machine and running java within eclipse.just download the fiddler and do the exact steps mentioned in http://dharampal.in/2013/07/03/capture-https-traffic-from-java-applications-with-fiddler/

  1. export the certifcate

  2. run the key tool

  3. In eclipse for that java programme set the following as VM arguments
    -DproxySet=true
    -DproxyHost=127.0.0.1
    -DproxyPort=8888
    -Djavax.net.ssl.trustStore=C:\Java\jdk1.7.0_79\bin\FiddlerKeystore
    -Djavax.net.ssl.trustStorePassword=xxxx123

  4. start the fiddler

I can see its fetching the token without any issue. But I think its using Fiddler as proxy but not the company proxy setting. probably there is a way we can set fiddler to go through the proxy. i am not sure.if i run the code with the following setting as mentioned with fiddler up and running we dont need to mention the proxy url like below.Either way its not using it.

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy url", 80));

please share your thought on this.

@kpanwar kpanwar closed this as completed Jun 10, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants