title: How to disable JWT Authorization on specific API endpoints (Java)?
body: <p>I have API endpoints configured for JWT Authorization:</p>
  <pre><code> @Bean
    public FilterRegistrationBean&lt;EsgJwtAuth&gt; esgJwtAuthBean() {
      EsgJwtAuth esgJwtAuth;
      try {
        HashMap&lt;String, String&gt; myConf = new HashMap&lt;&gt;();
        myConf.put(&quot;header&quot;, &quot;Authorization&quot;);
        myConf.put(&quot;jwksUrl&quot;, jwksUrl);
        myConf.put(&quot;jwksCacheSize&quot;, jwksCacheSize);
        myConf.put(&quot;jwksExpiresIn&quot;, jwksExpiresIn);
        myConf.put(&quot;jwksRateLimitSize&quot;, jwksRateLimitSize);
        myConf.put(&quot;jwksRateLimitRefillRate&quot;, jwksRateLimitRefillRate);
        esgJwtAuth = new EsgJwtAuth(myConf);
      } catch (Exception e) {
        esgJwtAuth = new EsgJwtAuth();
      }
  
      FilterRegistrationBean&lt;EsgJwtAuth&gt; registrationBean = new FilterRegistrationBean&lt;&gt;();
      registrationBean.setFilter(esgJwtAuth);
      registrationBean.addUrlPatterns(&quot;/a/*&quot;);
      registrationBean.addUrlPatterns(&quot;/b/*&quot;);
      registrationBean.addUrlPatterns(&quot;/c/*&quot;);
      return registrationBean;
    }
  </code></pre>
  <p>Now, i wanted to make <code>/a/noauth</code> to not require a JWT authorization. But for other endpoints such as <code>/a/withauth/</code>, <code>/a/*</code> i want it to require JWT authorization (as registered on the FilterRegistrationBean)</p>
  <p>So far, i tried extending my class with <code>OncePerRequestFilter</code> and implemented the ff codes:</p>
  <pre><code> @Override
    protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
      List&lt;String&gt; excludeUrlPatterns = new ArrayList&lt;String&gt;();
      excludeUrlPatterns.add(&quot;/a/noauth/&quot;);
      excludeUrlPatterns.add(&quot;/b/noauth/&quot;);
  
      return excludeUrlPatterns.stream()
          .anyMatch(exclude -&gt; request.getRequestURI().contains(exclude));
    }
  
    @Override
    protected void doFilterInternal(HttpServletRequest request,
                                    HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException {
      chain.doFilter(request, response);
    }
  </code></pre>
  <p>But when i run a request for <code>/a/noauth</code> <strong>without</strong> the <code>Header: &lt;JWT token&gt;</code>, it is <em><strong>Unauthorized</strong></em>. How to allow it? Thank you.</p>