Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

aadauthenticationfilter - failed to initialize userprincipal. com.nimbusds.jose.remotekeysourceexception: couldn't retrieve remote jwk set: read timed out #417

Closed
vipinsaini434 opened this issue Sep 14, 2018 · 15 comments

Comments

@vipinsaini434
Copy link

vipinsaini434 commented Sep 14, 2018

Environment

  • Spring boot starter:

    -azure-active-directory-spring-boot-sample

  • OS Type: Windows

  • Java version:

    • 1.8

Summary

ERROR c.m.a.s.a.a.AADAuthenticationFilter - Failed to initialize UserPrincipal.
com.nimbusds.jose.RemoteKeySourceException: Couldn't retrieve remote JWK set: Read timed out

Getting exception of timeout. This exception is coming in AADAuthenticationFilter

This issue was raised previously as well #247
but it is closed now.
Is there any fix. I am using latest version 2.0.5 but still getting the same issue.

Reproduce steps

  • Download the example
  • azure-active-directory-spring-boot-sample
    and run it after changing configuration files.
    It is a intermittent issue. May be it is related to server and by default timeout configuraion is 250ms but could you please suggest is there any way to increase it.

Expected Results

Should use the default timeout and timeout should increased if it is taking longer time.
Or should be someway to configure it.

Actual Results

Throwing exception and failing API call.

@vipinsaini434
Copy link
Author

Any update on this. Please suggest how to increase timeout.

@sophiaso
Copy link
Member

@vipinsaini434 Could you share the detailed stack trace? The stack trace of the old issue you linked is out-of-date, as code has been updated since then. Meanwhile, could you check the WIP pull request #418 and build a local package, use local built package and check whether longer timeout fixes your issue?

@vipinsaini434
Copy link
Author

@vipinsaini434 Could you share the detailed stack trace? The stack trace of the old issue you linked is out-of-date, as code has been updated since then. Meanwhile, could you check the WIP pull request #418 and build a local package, use local built package and check whether longer timeout fixes your issue?

Thanks for your reply @sophiaso. Yeah i made the local build and it is working fine after increasing the timeout in 'nimbus-jose-jwt' code base.I saw the pull request as mentioned. This is a good idea to make it configurable.

@sophiaso
Copy link
Member

Version 2.0.7 has been released.

@juanegt7
Copy link

Hi, thanks for your help. How can I increasing the timeout? I have a autowired AADAuthenticationFilter, but I can't set the new timeout.

@sophiaso
Copy link
Member

@juanegt7 The timeout is configurable through:

azure.activedirectory.jwt-connect-timeout
azure.activedirectory.jwt-read-timeout
azure.activedirectory.jwt-size-limit

In milliseconds.

@juanegt7
Copy link

Hello, I changed the values but I have the same problem yet, I'm working with a internet network with proxy. Any ideas?

@sophiaso
Copy link
Member

@juanegt7 Thanks for your comments, it might be caused by a bug, could you clone this repo, build a local version for branch #470 and try whether it fixes your issue? (branch https://github.com/Microsoft/azure-spring-boot/tree/timeout-bugfix)

@juanegt7
Copy link

Yes! The issue is fixed. Thanks for your help! Do we have a new version with this?

@sophiaso
Copy link
Member

@juanegt7 It's not released yet, but will try to release a new version recently. Will update here once released.

@jcainelli
Copy link

Good night,

I had the same problem and resolved with the @sophiaso branch. Prevision for release of fix in maven repository ?

Thanks.

@leizhang
Copy link

@sophiaso any plan to merge this patch with master?

@sidyes
Copy link

sidyes commented Jan 24, 2020

Any updates?

@jialindai
Copy link
Contributor

@sidyes, you can use latest release on 2.1.x or 2.2.x which include this fix.

  • 2.1.x latest release: 2.1.8
  • 2.2.x latest release: 2.2.2

@sidyes
Copy link

sidyes commented Mar 24, 2020

For me the problem were outgoing requests specifially with this lib as we also have a proxy.
Adding the **marked line** to the websecurity config solved the issue for me:

protected void configure(HttpSecurity http) throws Exception {
    **System.setProperty("java.net.useSystemProxies", "true");**

    // stateless configuration
    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);

    // Allow preflight requests
    http.cors();

    // require OAuth JWT token from AzureAD app
    http.authorizeRequests()
        .anyRequest().authenticated();

    // adding userid Password authentication filter to the filter chain
    http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class);
  }

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

7 participants