# Auth0 Spring Security API ProviderNotFoundException when using @PreAuthorize

**URL:** <https://community.auth0.com/t/auth0-spring-security-api-providernotfoundexception-when-using-preauthorize/7553>\
**Category:** Get Help\
**Tags:** quickstart, spring, java, spring-security\
**Created:** [July 18, 2017, 1:49am UTC](https://community.auth0.com/t/auth0-spring-security-api-providernotfoundexception-when-using-preauthorize/7553 "2017-07-18T01:49:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![auth06](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@auth06](https://community.auth0.com/u/auth06)\
**Post date:** [July 18, 2017, 1:49am UTC](https://community.auth0.com/t/auth0-spring-security-api-providernotfoundexception-when-using-preauthorize/7553/1 "2017-07-18T01:49:17Z")

</div>

I am having problem using the `@PreAuthorize` annotation for my endpoints after following the Auth0 Spring Security for API quickstart guide. The response i get is:

```
 "status": 401,
 "error": "Unauthorized",
 "exception":"org.springframework.security.authentication.ProviderNotFoundException"

```

I have tried to manually set the authentication provider using the following code for my WebSecurityConfig:

```
@Override
    protected void configure(HttpSecurity http) throws Exception {
        logger.info("Configuring for Jwt token with iss {} & aud {}", issuer, audience);
        JwtWebSecurityConfigurer.forRS256(audience, issuer)
                .configure(http)
                .authorizeRequests()
                .antMatchers(HttpMethod.GET, "/secure/**").hasAuthority("read:secure");
    }
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        JwkProvider jwkProvider = new JwkProviderBuilder(issuer).build();
        JwtAuthenticationProvider authenticationProvider =new JwtAuthenticationProvider(jwkProvider, issuer, audience);
        auth.authenticationProvider(authenticationProvider);
    }

```

And the endpoint looks like this:

```
    @PreAuthorize("permitAll()")
    @RequestMapping(value = "/test2")
    @ResponseBody
    public String test2(){
        return"secure";
    }

```

Any advice?

---

<div class="post-metadata">

**Author:** ![brianra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brianra/32/11261_2.png) [@brianra](https://community.auth0.com/u/brianra)\
**Post date:** [December 28, 2017, 1:51am UTC](https://community.auth0.com/t/auth0-spring-security-api-providernotfoundexception-when-using-preauthorize/7553/2 "2017-12-28T01:51:07Z")

</div>

We are seeing similar responses, seemingly out of the blue. This is happening for us only on Native client requests. SPA client requests seem fine. This is happening on a Prod app that has been in prod for months without this issue.

@auth06 - did you ever find an answer to this?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:55am UTC](https://community.auth0.com/t/auth0-spring-security-api-providernotfoundexception-when-using-preauthorize/7553/3 "2018-03-02T05:55:26Z")

</div>


