title: Entering Infinite Loop in Authentication Filter in Java
body: <p>I am trying to make a GET request within a custom authentication filter I've made in Spring, but seem to be entering an infinite loop.  Basically, I want to make a GET request with a username and check whether this username is authenticated on a separate server with implementation in Python.</p>
  
  <p>After removing the GET request, it seems to work.  Is it applying the filter to the URL I create in the code?  How can I get around this, if so?</p>
  
  <pre><code>            String authURL = request.getScheme() + "://" + "test-app";
              authURL += "/test/authenticate_user?ui_user=" + http_request.getParameter("ui_user");
  
              System.out.println("\nSending 'GET' request to URL : " + authURL);
  
              try {
                  sslContext = SSLContext.getInstance("SSL");
                  sslContext.init(null,
                          trustAllCerts,
                          new SecureRandom());
                  HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
                  URL auth_obj = new URL(null, authURL, new Handler());
                  System.out.println(authURL);
                  auth_con = (HttpsURLConnection) auth_obj.openConnection();
                  auth_con.setRequestMethod("GET");
                  auth_con.setRequestProperty("Content-type", "application/json");
              } catch (Exception e) {
                  System.out.println(e.getMessage());
              }
              StringBuffer result = new StringBuffer();
              if (true) {
                  BufferedReader in = new BufferedReader(
                          new InputStreamReader(auth_con.getInputStream()));
                  String inputLine;
  
                  while ((inputLine = in.readLine()) != null) {
                      result.append(inputLine);
                  }
                  in.close();
                  Authentication authentication = new UsernamePasswordAuthenticationToken("", null,
                          AuthorityUtils.createAuthorityList("USER"));
                  SecurityContextHolder.getContext().setAuthentication(authentication);
                  chain.doFilter(http_request, http_response);
              }
  </code></pre>