Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.34k stars 1.98k forks source link

reactor.core.Exceptions$ReactiveException: javax.net.ssl.SSLHandshakeException: Unsupported curveId: 29 #12799

Closed ajaiswal595 closed 4 years ago

ajaiswal595 commented 4 years ago

I have integrated the code in my product but it throwing error at this line and I'm using open jdk8. AccessToken accesstoken=clientSecretCredential.getToken(request).block();

Any reason why I'm getting this error. reactor.core.Exceptions$ReactiveException: javax.net.ssl.SSLHandshakeException: Unsupported curveId: 29

After multiple executions, I started getting error

reactor.core.Exceptions$ReactiveException: java.net.SocketException: Connection reset at reactor.core.Exceptions.propagate(Exceptions.java:393) at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:97) at reactor.core.publisher.Mono.block(Mono.java:1678) at com.itko.lisa.jdbc.JDBCNode.GetAccessToken(JDBCNode.java:733) at com.itko.lisa.jdbc.JDBCNode.getConnection(JDBCNode.java:685) at com.itko.lisa.jdbc.JDBCNode.executeSQL(JDBCNode.java:381) at com.itko.lisa.jdbc.JDBCNodeEditor.doExec(JDBCNodeEditor.java:483) at com.itko.lisa.jdbc.JDBCNodeEditor$6.doCallback(JDBCNodeEditor.java:417) at com.itko.util.swing.panels.ProcessingDialog$2.run(ProcessingDialog.java:195) at java.lang.Thread.run(Thread.java:748) Suppressed: java.lang.Exception: #block terminated with an error at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99) ... 8 more Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:210) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) at sun.security.ssl.InputRecord.read(InputRecord.java:503) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:933) at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) at java.io.BufferedInputStream.read(BufferedInputStream.java:345) at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:706) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1593) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352) at com.microsoft.aad.msal4j.HttpHelper.readResponseFromConnection(HttpHelper.java:154) at com.microsoft.aad.msal4j.HttpHelper.getResponse(HttpHelper.java:91) at com.microsoft.aad.msal4j.HttpHelper.executeHttpGet(HttpHelper.java:60) at com.microsoft.aad.msal4j.HttpHelper.executeHttpRequest(HttpHelper.java:44) at com.microsoft.aad.msal4j.AadInstanceDiscovery.sendInstanceDiscoveryRequest(AadInstanceDiscovery.java:62) at com.microsoft.aad.msal4j.AadInstanceDiscovery.doInstanceDiscoveryAndCache(AadInstanceDiscovery.java:78) at com.microsoft.aad.msal4j.AadInstanceDiscovery.GetMetadataEntry(AadInstanceDiscovery.java:93) at com.microsoft.aad.msal4j.AuthenticationResultSupplier.getAuthorityWithPrefNetworkHost(AuthenticationResultSupplier.java:33) at com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier.execute(AcquireTokenByAuthorizationGrantSupplier.java:49) at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:57) at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:17) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1596) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

joshfree commented 4 years ago

@jianghaolu can you please take a look?

ajaiswal595 commented 4 years ago

I have written the code like

    ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
            .clientId("Some id")
            .clientSecret("secret")
            .tenantId("tenentid")
            .build();

    TokenRequestContext request = new TokenRequestContext();
    System.out.println("444");
    request.addScopes("https://database.windows.net//.default");
    String token;
    AccessToken accesstoken=clientSecretCredential.getToken(request).block(Duration.ofMinutes(1));

    return accesstoken;

It's failing over AccessToken accesstoken=clientSecretCredential.getToken(request).block(Duration.ofMinutes(1));

While executing standalone program it's working but when I'm integrating this with my application same code failing

reactor.core.Exceptions$ReactiveException: java.net.SocketException: Connection reset

even I put some duration in the block method but it does not help.

jianghaolu commented 4 years ago

Hi @ajaiswal595 Without knowing more details about your application it's difficult to tell what may be going on. If you can help answer the following questions I may be able to find out more what's going on: 1) Which version of azure-identity you are using? Our latest stable 1.0.8 uses HttpUrlConnection to authenticate and the preview 1.1.0-beta.5 uses Netty. They have different SSL implementations so using the other might fix your problem. 2) It could also be because of the exhaustion of the fork join pool. You can try adding .executorService(Executors.newCachedThreadPool()) to the builder to avoid using the fork join pool. 3) It could also be the conflict of a dependency. If you could share the classpath your application is running on, I can check if there might be a dependency that's not compatible with the azure identity library.

ajaiswal595 commented 4 years ago

Here is the list of jars being used in my application. and azure identity is 1.0.7.

accessors-smart-1.2.jar activation-1.1.1.jar addressing-1.0.1.jar alpn-boot-8.1.13.v20181017.jar amf-aml_2.12-4.0.51.jar amf-core_2.12-4.0.42.jar amf-validation_2.12-3.2.2.jar amf-webapi_2.12-3.2.2.jar animal-sniffer-annotations-1.14.jar annotation-detector-3.0.4.jar annotations-2.0.1.jar ant-launcher-1.9.3.jar antlr-runtime-3.5.jar aopalliance-1.0.jar AppleJavaExtensions-1.0.0.jar asc-1.5.jar asm-5.0.4.jar asm-commons-5.0.1.jar asm-tree-5.0.1.jar aspectjrt-1.8.9.jar aspectjweaver-1.8.9.jar autocomplete-2.5.3.jar automaton-1.0.0.jar axiom-api-1.2.8.jar axiom-impl-1.2.8.jar axis-1.4a.jar axis-jaxrpc-1.4.jar axis-saaj-1.4.jar azure-core-1.5.1.jar azure-identity-1.0.7.jar balloontip-1.2.4.1.jar bcpkix-jdk15on-1.56.jar bcpkix-jdk15to18-1.64.jar bcprov-ext-jdk15to18-1.64.jar bcprov-jdk15on-1.56.jar bcprov-jdk15on-1.59.jar bcprov-jdk15to18-1.64.jar boot-6.5.jar bsh-2.1.8.jar btf-1.2.jar builder-annotations-0.18.0.jar c3p0-0.9.5.jar cal10n-api-0.7.4.jar cglib-nodep-2.2.2.jar checker-qual-2.0.0.jar classmate-1.3.1.jar client-java-5.0.0.jar client-java-api-5.0.0.jar client-java-proto-5.0.0.jar collection-0.7.jar comfyj-2.10.jar common-22.0.jar commons-beanutils-1.9.3.jar commons-cli-1.2.jar commons-cli-1.4.jar commons-codec-1.11.jar commons-collections-3.2.2.jar commons-collections4-4.1.jar commons-compress-1.18.jar commons-configuration-1.6.jar commons-csv-1.5.jar commons-digester-1.8.1.jar commons-digester-1.8.jar commons-discovery-0.2.jar commons-email-1.5.jar commons-exec-1.3.jar commons-fileupload-1.3.3.jar commons-httpclient-3.0.jar commons-io-2.4.jar commons-lang-2.6.jar commons-lang3-3.9.jar commons-logging-1.2.jar commons-net-3.3.jar commons-pool-1.5.4.jar commons-text-1.3.jar commons-validator-1.4.0.jar commons-validator-1.4.1.jar concurrentlinkedhashmap-lru-1.4.jar core-6.5.jar curvesapi-1.04.jar darcula-1.0.0-SNAPSHOT.jar db2jcc4-10.5.0.4.jar ddmlib-22.0.jar derby-10.12.1.1.jar derbyclient-10.12.1.1.jar derbynet-10.12.1.1.jar dom4j-1.6.1.jar ecj-4.4.1.jar eclipselink-2.3.2.jar edireader-4.9.4.jar ediwriter-4.9.4.jar engine-gecko-3.4.18.jar engine-gecko15-3.4.18.jar engine-ie-3.4.18.jar engine-webkit-3.4.18.jar error_prone_annotations-2.1.3.jar ezmorph-1.0.6.jar flyway-core-3.1.jar forms-1.0.7.jar ftp-1.0.0.jar Generex-1.0.jar geronimo-ejb_3.1_spec-1.0.2.jar geronimo-interceptor_1.1_spec-1.0.jar geronimo-j2ee-connector_1.5_spec-1.0.1.jar geronimo-jaxrpc_1.1_spec-2.1.jar geronimo-jms_1.1_spec-1.1.1.jar geronimo-jsp_2.2_spec-1.2.jar geronimo-jta_1.0.1B_spec-1.0.1.jar geronimo-servlet_3.0_spec-1.0.jar geronimo-stax-api_1.0_spec-1.0.1.jar google-api-client-1.18.0-rc.jar google-http-client-1.19.0.jar google-http-client-jackson2-1.19.0.jar google-oauth-client-1.18.0-rc.jar grammatica-1.5.jar groovy-all-2.4.7.jar groovy-jsr223-2.4.7.jar gson-2.8.5.jar guava-25.1-jre.jar guice-3.0.jar hadoop-annotations-2.6.0.jar hadoop-auth-2.6.0.jar hadoop-common-2.6.0.jar hadoop-hdfs-2.6.0.jar hamcrest-all-1.3.jar handy-uri-templates-2.1.6.jar hibernate-validator-5.3.6.Final.jar hppc-0.5.2.jar htrace-core-3.0.4.jar http-client-5.0.0.14.jar httpasyncclient-4.0.2.jar httpclient-4.5.jar httpclient-cache-4.5.5.jar httpcore-4.4.1.jar httpcore-nio-4.3.2.jar httpmime-4.3.3.jar i4jruntime-4.0.5.jar iam-client-1.3.2.jar icu4j-56.1.jar itko-activemq-1.0.0.jar itko-javassist-3.20.0-GA.jar itko-procyon-0.5.26.jar itko-velocity-engine-1.7.jar itko.xstream-1.3.1.jar j2objc-annotations-1.1.jar jackson-annotations-2.10.1.jar jackson-core-2.10.1.jar jackson-core-asl-1.9.13.jar jackson-coreutils-1.8.jar jackson-databind-2.10.1.jar jackson-dataformat-xml-2.10.1.jar jackson-datatype-jsr310-2.10.1.jar jackson-mapper-asl-1.9.13.jar jackson-module-jaxb-annotations-2.10.1.jar jai_codec-1.1.3.jar jai_core-1.1.3.jar jakarta.activation-api-1.2.1.jar jakarta.xml.bind-api-2.3.2.jar jargs-1.0.jar java-client-3.3.0.jar java-uuid-generator-3.1.3.jar javahelp-2.0.05.jar javax.annotation-api-1.2.jar javax.el-api-2.2.4.jar javax.inject-2.2.0-b21.jar javax.mail-1.6.1.jar jaxen-1.1.1.jar jboss-logging-3.3.1.Final.jar jcip-annotations-1.0-1.jar jcl-over-slf4j-1.7.25.jar jcommon-1.0.16.jar jdbi-2.51.jar jdom-legacy-1.1.3.jar jdom2-2.0.6.jar jena-arq-3.8.0.jar jena-base-3.8.0.jar jena-core-3.8.0.jar jena-iri-3.8.0.jar jena-shaded-guava-3.8.0.jar jetty-all-9.3.11.v20160721-uber.jar jfreechart-1.0.13.jar jgraph-5.13.0.3.jar Jhrome-2.0.jar jjwt-0.9.0.jar jline-0.9.94.jar jmf-2.1.1e.jar jmock-1.0.0.jar jms-1.0.0.jar jna-5.4.0.jar jna-platform-5.4.0.jar jnetpcap-1.3.0.jar jniwrap-3.8.4.jar joda-convert-1.2.jar joda-time-2.8.2.jar joda-time-2.9.7.jar jopt-simple-4.6.jar jopt-simple-5.0.3.jar json-20140107.jar json-20180130.jar json-lib-2.4-jdk15.jar json-patch-1.6.jar json-path-1.2.0.jar json-schema-core-1.2.4.jar json-schema-core-1.2.5.jar json-schema-core-1.2.8.jar json-schema-validator-2.2.5.jar json-schema-validator-2.2.6.jar json-schema-validator-2.2.8.jar json-smart-2.3.jar json4s-ast_2.12-3.5.4.jar json4s-core_2.12-3.5.4.jar json4s-native_2.12-3.5.4.jar json4s-scalap_2.12-3.5.4.jar jsonassert-1.2.3.jar jsonld-java-0.12.0.jar jsqlparser-0.9.3.jar jsr305-3.0.2.jar junit-4.11.jar jxbrowser-3.4.18.jar keycloak-authz-client-3.4.3.Final.jar keycloak-client-registration-api-3.4.3.Final.jar keycloak-common-3.4.3.Final.jar keycloak-core-3.4.3.Final.jar kxml2-2.3.0.jar lang-tag-1.5.jar language_support-2.5.3.jar libphonenumber-6.0.jar libphonenumber-6.2.jar libphonenumber-8.0.0.jar libthrift-0.10.0.jar license-3.4.18.jar lisa-cb2xml-1.0.0.jar lisa-sv-odp-10.6.0.jar lisa-xstream-1.0.0.jar log4j-1.2.17.jar logging-interceptor-2.7.5.jar lombok-1.18.6.jar lucene-analyzers-common-5.1.0.jar lucene-analyzers-kuromoji-5.1.0.jar lucene-analyzers-phonetic-5.1.0.jar lucene-backward-codecs-5.1.0.jar lucene-codecs-5.1.0.jar lucene-core-5.1.0.jar lucene-expressions-5.1.0.jar lucene-grouping-5.1.0.jar lucene-highlighter-5.1.0.jar lucene-join-5.1.0.jar lucene-memory-5.1.0.jar lucene-misc-5.1.0.jar lucene-queries-5.1.0.jar lucene-queryparser-5.1.0.jar lucene-spatial-5.1.0.jar lucene-suggest-5.1.0.jar lz4-java-1.4.jar mail-1.4.7.jar mailapi-1.4.3.jar mandileschneider-1.1.jar mapdb-2.0-beta7.jar mchange-commons-java-0.2.9.jar metrics-core-3.0.1.jar mibble-commercial-mibs-2.9.2.jar mibble-commercial-parser-2.9.2.jar mockrunner-jdk1.4-j2ee1.3-0.4.jar msal4j-0.5.0-preview.jar msg-simple-1.1.jar mssql-jdbc-8.2.0.jre8.jar mx-18.0.0.jar nanohttpd-2.3.1.jar nb-darcula-1.5.jar nekohtml-1.9.21.jar netty-3.7.0.Final.jar netty-all-4.1.44.Final.jar netty-tcnative-boringssl-static-2.0.29.Final.jar nimbus-jose-jwt-8.19.jar noggit-0.6.jar not-yet-commons-ssl-0.3.11.jar oauth2-oidc-sdk-6.14.jar ojdbc7-12.1.0.2.jar okhttp-2.7.5.jar okhttp-urlconnection-2.7.5.jar okhttp-ws-2.7.5.jar okio-1.6.0.jar opensaml-1.1.jar opensaml-2.2.3.jar openws-1.2.2.jar org-mozilla-rhino-patched-6.5.jar org-netbeans-api-java-classpath-6.5.jar org-netbeans-api-progress-6.5.jar org-netbeans-api-xml-6.5.jar org-netbeans-core-6.5.jar org-netbeans-modules-css-editor-6.5.jar org-netbeans-modules-diff-6.5-itko.jar org-netbeans-modules-editor-6.5-itko.jar org-netbeans-modules-editor-bracesmatching-6.5.jar org-netbeans-modules-editor-codetemplates-6.5.jar org-netbeans-modules-editor-completion-6.5.jar org-netbeans-modules-editor-deprecated-pre61completion-6.5.jar org-netbeans-modules-editor-deprecated-pre61settings-6.5.jar org-netbeans-modules-editor-errorstripe-6.5.jar org-netbeans-modules-editor-errorstripe-api-6.5.jar org-netbeans-modules-editor-fold-6.5.jar org-netbeans-modules-editor-guards-6.5.jar org-netbeans-modules-editor-highlights-6.5.jar org-netbeans-modules-editor-indent-6.5.jar org-netbeans-modules-editor-kit-6.5.jar org-netbeans-modules-editor-lib-6.5.jar org-netbeans-modules-editor-lib2-6.5.jar org-netbeans-modules-editor-mimelookup-6.5.jar org-netbeans-modules-editor-mimelookup-impl-6.5.jar org-netbeans-modules-editor-plain-6.5.jar org-netbeans-modules-editor-plain-lib-6.5.jar org-netbeans-modules-editor-settings-6.5.jar org-netbeans-modules-editor-settings-storage-6.5.jar org-netbeans-modules-editor-structure-6.5.jar org-netbeans-modules-editor-supplemental-6.5.jar org-netbeans-modules-editor-util-6.5.jar org-netbeans-modules-extbrowser-6.5.jar org-netbeans-modules-gsf-6.5.jar org-netbeans-modules-gsf-api-6.5.jar org-netbeans-modules-gsfpath-api-6.5.jar org-netbeans-modules-html-6.5.jar org-netbeans-modules-html-editor-6.5-itko.jar org-netbeans-modules-html-editor-lib-6.5.jar org-netbeans-modules-html-lexer-6.5.jar org-netbeans-modules-javascript-editing-6.5.jar org-netbeans-modules-javascript-hints-6.5.jar org-netbeans-modules-javascript-kit-6.5.jar org-netbeans-modules-javascript-refactoring-6.5.jar org-netbeans-modules-lexer-6.5.jar org-netbeans-modules-lexer-editorbridge-6.5.jar org-netbeans-modules-lexer-nbbridge-6.5.jar org-netbeans-modules-masterfs-6.5.jar org-netbeans-modules-options-api-6.5.jar org-netbeans-modules-project-libraries-6.5.jar org-netbeans-modules-projectapi-6.5.jar org-netbeans-modules-projectuiapi-6.5.jar org-netbeans-modules-queries-6.5.jar org-netbeans-modules-refactoring-api-6.5.jar org-netbeans-modules-xml-6.5.jar org-netbeans-modules-xml-core-6.5.jar org-netbeans-modules-xml-lexer-6.5.jar org-netbeans-modules-xml-text-6.5-itko.jar org-netbeans-spi-editor-hints-6.5.jar org-netbeans-spi-navigator-6.5.jar org-netbeans-spi-palette-6.5.jar org-openide-actions-6.5.jar org-openide-awt-6.5.jar org-openide-dialogs-6.5.jar org-openide-explorer-6.5.jar org-openide-filesystems-6.5.jar org-openide-loaders-6.5.jar org-openide-modules-6.5.jar org-openide-nodes-6.5.jar org-openide-options-6.5.jar org-openide-text-6.5.jar org-openide-util-6.5.jar org-openide-windows-6.5.jar org.everit.json.schema-1.9.2.jar org.restlet-2.1.1.jar org.restlet.ext.servlet-2.1.1.jar oro-2.0.8.jar owner-1.0.6.jar paranamer-2.8.jar pcap-reconst-itko-1.0.0.jar persistence-api-2.0.3.v201010191057.jar plugin-1.0.0.jar pm-webdriver-5.0.0.006.jar poi-3.17.jar poi-ooxml-3.17.jar poi-ooxml-schemas-3.17.jar postgresql-42.2.5.jar protobuf-java-2.5.0.jar protobuf-java-3.4.0.jar pw-swift-core-SRU2018-7.10.3.jar qdox-1.6.2.jar quartz-1.6.5.jar re2j-1.1.jar reactive-streams-1.0.3.jar reactor-core-3.3.5.RELEASE.jar relaxngDatatype-2011.1.jar resourcecify-annotations-0.18.0.jar retrofit-1.9.0.jar rhino-1.7R4.jar rolevat-1.2.jar rstaui-2.5.3.jar rsyntaxtextarea-2.5.3.jar saxon-9.jar scala-common_2.12-0.5.60.jar scala-java8-compat_2.12-0.8.0.jar scala-library-2.12.8.jar scala-xml_2.12-1.0.6.jar scopt_2.12-3.7.0.jar selenium-api-2.53.0.jar selenium-chrome-driver-2.53.0.jar selenium-edge-driver-2.53.0.jar selenium-firefox-driver-2.53.0.jar selenium-ie-driver-2.53.0.jar selenium-java-2.53.0.jar selenium-leg-rc-2.53.0.jar selenium-remote-driver-2.53.0.jar selenium-safari-driver-2.53.0.jar selenium-support-2.53.0.jar sepa-core-jaxb-18.0.1.jar servlet-api-2.5.jar shacl-1.2.0-INTERNAL.jar slf4j-api-1.7.28.jar slf4j-ext-1.6.3.jar slf4j-log4j12-1.7.7.jar slf4j-simple-1.7.12.jar smv-18.0.22.jar snakeyaml-1.19.jar snappy-java-1.1.7.1.jar snmp4j-1.11.3.jar solr-core-5.1.0.jar solr-dataimporthandler-5.1.0.jar solr-solrj-5.1.0.jar spatial4j-0.4.1.jar spi-0.2.4.jar splunk-1.5.0.0.jar spring-aop-4.3.22.RELEASE.jar spring-beans-4.3.22.RELEASE.jar spring-context-4.3.22.RELEASE.jar spring-core-4.3.22.RELEASE.jar spring-expression-4.3.22.RELEASE.jar spring-ldap-core-2.3.2.RELEASE.jar spring-security-core-4.2.12.RELEASE.jar spring-security-ldap-4.2.12.RELEASE.jar spring-tx-4.3.22.RELEASE.jar stax2-api-4.2.jar sundr-codegen-0.18.0.jar sundr-core-0.18.0.jar sunidlcompiler-1.0.0.jar sv-config-client-0.0.2.jar swagger-annotations-1.5.20.jar swagger-annotations-2.0.1.jar swagger-compat-spec-parser-1.0.36.jar swagger-core-1.5.20.jar swagger-core-2.0.1.jar swagger-models-1.5.20.jar swagger-models-2.0.1.jar swagger-parser-1.0.22a.jar swagger-parser-1.0.36.jar swagger-parser-2.0.1.jar swagger-parser-core-2.0.1.jar swagger-parser-v2-converter-2.0.1.jar swagger-parser-v3-2.0.1.jar swing-layout-1.0.3.jar swingx-all-1.6.4.jar syaml_2.12-0.7.240.jar t-digest-3.0.jar test-tools-1.0.0.jar testdroid-api-2.0.jar trilead-ssh2-build213-1.0.0.jar uddi4j-2.0.5.jar uri-template-0.9.jar validation-api-2.0.1.Final.jar velocity-1.7.jar webapi-parser-0.2.0.jar winpack-3.8.4.jar woodstox-core-6.0.2.jar woodstox-core-asl-4.4.1.jar wsdl4j-1.6.2.jar wsi-common-1.1.jar wsi-test-tools-1.1.jar wss4j-lisa-1.5.4.6.4.jar wstx-asl-3.2.9.jar xdb6-12.1.0.1.jar xml-resolver-1.2.jar xmlbeans-2.6.0.jar xmlbeans-xpath-2.6.0.jar xmlpull-1.1.3.1.jar XmlSchema-1.4.6.jar xmlsec-1.4.2.jar xmltooling-1.2.0.jar xmlunit-1.0.jar xom-1.2.10.jar xpp3_min-1.1.4c.jar xsom-20110809.jar xstream-1.4.8.jar xulrunner-mac-3.4.18.jar xulrunner15-mac-3.4.18.jar xz-1.5.jar zip4j-1.3.1.jar zookeeper-3.4.6.jar

ajaiswal595 commented 4 years ago

Hi @jianghaolu,

I have added here a list of dependencies in my Build Path. Could you please see it.

For this It could also be because of the exhaustion of the fork join pool. You can try adding .executorService(Executors.newCachedThreadPool()) to the builder to avoid using the fork join pool.

Can you provide a piece of logic I have to place instead of the one I have added?

jianghaolu commented 4 years ago

It will be like

    ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
            .clientId("Some id")
            .clientSecret("secret")
            .tenantId("tenentid")
            .executorService(Executors.newCachedThreadPool())
            .build();
ajaiswal595 commented 4 years ago

There is no such method executorService() applicable in ClientSecretCredential which takes input as Executors and return ClientSecretCredential.

I checked with 1.0.7 as well as 1.0.8

jianghaolu commented 4 years ago

@ajaiswal595 Sorry I forgot to mention - you will need the preview version like 1.1.0-beta.6: https://repo1.maven.org/maven2/com/azure/azure-identity/1.1.0-beta.6/

ajaiswal595 commented 4 years ago

Hi Even after using executerservice i'm getting error

com.microsoft.aad.msal4j.MsalClientException: java.net.SocketException: Connection reset at com.microsoft.aad.msal4j.HttpHelper.executeHttpRequest(HttpHelper.java:36) at com.microsoft.aad.msal4j.AadInstanceDiscoveryProvider.sendInstanceDiscoveryRequest(AadInstanceDiscoveryProvider.java:117) at com.microsoft.aad.msal4j.AadInstanceDiscoveryProvider.doInstanceDiscoveryAndCache(AadInstanceDiscoveryProvider.java:131) at com.microsoft.aad.msal4j.AadInstanceDiscoveryProvider.getMetadataEntry(AadInstanceDiscoveryProvider.java:42) at com.microsoft.aad.msal4j.AuthenticationResultSupplier.getAuthorityWithPrefNetworkHost(AuthenticationResultSupplier.java:32) at com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier.execute(AcquireTokenByAuthorizationGrantSupplier.java:49) at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:59) at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:17) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Suppressed: java.lang.Exception: #block terminated with an error at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:139) at reactor.core.publisher.Mono.block(Mono.java:1702) at com.itko.lisa.jdbc.JDBCNode.GetAccessToken(JDBCNode.java:948) at com.itko.lisa.jdbc.JDBCNode.getIMDSConnection(JDBCNode.java:906) at com.itko.lisa.jdbc.JDBCNode.getConnection(JDBCNode.java:668) at com.itko.lisa.jdbc.JDBCNode.executeSQL(JDBCNode.java:373) at com.itko.lisa.jdbc.JDBCNodeEditor.doExec(JDBCNodeEditor.java:483) at com.itko.lisa.jdbc.JDBCNodeEditor$6.doCallback(JDBCNodeEditor.java:417) at com.itko.util.swing.panels.ProcessingDialog$2.run(ProcessingDialog.java:195) ... 1 more Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:210) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) at sun.security.ssl.InputRecord.read(InputRecord.java:503) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:933) at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) at java.io.BufferedInputStream.read(BufferedInputStream.java:345) at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:706) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1593) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352) at com.microsoft.aad.msal4j.DefaultHttpClient.readResponseFromConnection(DefaultHttpClient.java:97) at com.microsoft.aad.msal4j.DefaultHttpClient.executeHttpGet(DefaultHttpClient.java:40) at com.microsoft.aad.msal4j.DefaultHttpClient.send(DefaultHttpClient.java:28) at com.microsoft.aad.msal4j.HttpHelper.executeHttpRequest(HttpHelper.java:33) ... 11 more

What is causing these errors still unknown for me?

Can we get access token using Postman so I can write my custom code using httpclient and set it in datasource.

ajaiswal595 commented 4 years ago

public static String getAccessToken() throws IOException {

    String result = "";

    HttpPost post = new HttpPost("https://login.microsoftonline.com/{{tenent_Id}}/oauth2/token");
    List<NameValuePair> urlParameters = new ArrayList<>();
    urlParameters.add(new BasicNameValuePair("grant_type", "client_credentials"));
    urlParameters.add(new BasicNameValuePair("client_id", "client_id"));
    urlParameters.add(new BasicNameValuePair("client_secret", "Jclient_secret"));
    urlParameters.add(new BasicNameValuePair("resource", "https://database.windows.net"));

    post.setEntity(new UrlEncodedFormEntity(urlParameters));

    try (CloseableHttpClient httpClient = HttpClients.createDefault();
         CloseableHttpResponse response = httpClient.execute(post)){

        result = EntityUtils.toString(response.getEntity());
    }

    ObjectNode node = new ObjectMapper().readValue(result, ObjectNode.class);

    System.out.println(result);

    if (node.has("access_token")) {
        result = node.get("access_token").toString();           
    }
    System.out.println(result);
    System.out.println(result.substring(1, result.length()-1));
    return result.substring(1, result.length()-1);

}

I'm able to get the token but it's gets expire, How would I get a refresh token or something that it never gets expired, as my application keeps sending data to the database forever.

Visinghr commented 4 years ago

You are using the client_credential flow, in this flow refresh_token isn't required. whenever your access token expire you can make another call to get the new access token. Refresh Token is given in the user interactive flows of OAuth, where you can use the refresh token for getting the new access token without user interaction once the access token expired.

jianghaolu commented 4 years ago

@ajaiswal595 I've reached out to the msal team to inquire about the specific error you are getting here. But I'm almost certain this is not caused by the server but by the client. If you can write a small reproducible sample and share with us, it will be easier also for us to debug and come up with a fix.

Meanwhile if you want to know the actual on the wire, you can write a small sample and catch the traffic in Fiddler.

ajaiswal595 commented 4 years ago

@jianghaolu thanks for all your support but I have achieved it using custom code even I'm not able to figure out why it was throwing error so I wrote custom code and its working for me.

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.util.ArrayList;
import java.util.List;

public class AzureServicePrincipleTokenManager implements Runnable {

    SQLServerDataSource ds ;
    String secret;
    String clientId;
    String tenetId;
    static final String RESOURCE = "https://database.windows.net";
    static final String ENDPOINT = "https://login.microsoftonline.com/";
    static final String GRANT_TYPE = "client_credentials";
    boolean confirmTokenFlag=false;
    private static Log logger = LogFactory.getLog( "AzureServicePrincipleTokenManager" );

    public AzureServicePrincipleTokenManager(SQLServerDataSource ds, String tenetId, String clientId, String secret) {
        this.ds = ds;
        this.secret = secret;
        this.clientId = clientId;
        this.tenetId = tenetId;
    }

    public boolean getConfirmTokenFlag(){
        return this.confirmTokenFlag;
    }

    private void setAccessToken(String token){
        this.ds.setAccessToken(token);
    }

    @Override
    public void run() {
        logger.info("Fetching Service Principle accessToken");
        String result = "";
        HttpPost post = new HttpPost(ENDPOINT+this.tenetId+"/oauth2/token");
        List<NameValuePair> urlParameters = new ArrayList<>();
        urlParameters.add(new BasicNameValuePair("grant_type", GRANT_TYPE));
        urlParameters.add(new BasicNameValuePair("client_id", this.clientId));
        urlParameters.add(new BasicNameValuePair("client_secret", this.secret));
        urlParameters.add(new BasicNameValuePair("resource", RESOURCE));

        try{

            post.setEntity(new UrlEncodedFormEntity(urlParameters));
            CloseableHttpClient httpClient = HttpClients.createDefault();
            CloseableHttpResponse response = httpClient.execute(post);
            result = EntityUtils.toString(response.getEntity());
            ObjectNode node = new ObjectMapper().readValue(result, ObjectNode.class);

            if (node.has("access_token")) {
                result = node.get("access_token").toString();
            }

        }catch (Exception ex){
            logger.error(ex.getMessage(),ex);
        }

        this.setAccessToken(result.substring(1, result.length()-1));
        confirmTokenFlag=true;
        logger.info("set confirmTokenFlag true");

    }
} 

And the caller will be like

SQLServerDataSource ds = new SQLServerDataSource();

        AzureServicePrincipleTokenManager azureServicePrincipleTokenManager = new AzureServicePrincipleTokenManager(ds,"your tenentID","your clientID","your secret");
        ScheduledExecutorService sches = Executors.newScheduledThreadPool(1);
        sches.scheduleWithFixedDelay(azureServicePrincipleTokenManager, 0, 45, TimeUnit.MINUTES);
        logger.info("----ExecuterService started the Runnable task");

        while (azureServicePrincipleTokenManager.getConfirmTokenFlag()!=true){

            ds.getAccessToken(); //I wonder If i leave while body balnk it never become true. so intentionally i'm calling ds.getAccessToken();
        }
            logger.info("----get the token after settingup  "+ds.getAccessToken());
jianghaolu commented 4 years ago

I'm glad it works out for you in the end and thanks for sharing your code! Sorry I couldn't be more help. I'll forward your code to the msal folks to see if they can figure out why this code works with AAD but not theirs.

jianghaolu commented 4 years ago

Seems like you have resolved the issue thus closing. This seems to be a standalone case at this time.

But if anyone else runs into this same issue and can provide a minimal reproducible sample, we would be happy to find the root cause.