public class InsecureBasicAuth {
  /**
   * Test basic authentication with Apache HTTP request.
   */	
  public void testApacheHttpRequest(String username, String password) {
  {
    // BAD: basic authentication over HTTP
    String url = "http://www.example.com/rest/getuser.do?uid=abcdx";
  }

  {
    // GOOD: basic authentication over HTTPS
    String url = "https://www.example.com/rest/getuser.do?uid=abcdx";
  }

    HttpPost post = new HttpPost(url);
    post.setHeader("Accept", "application/json");
    post.setHeader("Content-type", "application/json");
		
    String authString = username + ":" + password;
    byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes());
    String authStringEnc = new String(authEncBytes);

    post.addHeader("Authorization", "Basic " + authStringEnc);
  }

  /**
   * Test basic authentication with Java HTTP URL connection.
   */
  public void testHttpUrlConnection(String username, String password) {
  {
    // BAD: basic authentication over HTTP
    String urlStr = "http://www.example.com/rest/getuser.do?uid=abcdx";
  }

  {
    // GOOD: basic authentication over HTTPS
    String urlStr = "https://www.example.com/rest/getuser.do?uid=abcdx";
  }

    String authString = username + ":" + password;
    String encoding = Base64.getEncoder().encodeToString(authString.getBytes("UTF-8"));
    URL url = new URL(urlStr);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    conn.setRequestProperty("Authorization", "Basic " + encoding);
  }
}

@@ -94,17 +94,16 @@
 t.%0A   */
-%09
 %0A  publi
@@ -159,35 +159,32 @@
 ing password) %7B%0A
-  %7B
 %0A    // BAD: bas
@@ -276,32 +276,24 @@
 uid=abcdx%22;%0A
-  %7D%0A%0A  %7B
 %0A    // GOOD
@@ -326,31 +326,24 @@
 r HTTPS%0A    
-String 
 url = %22https
@@ -384,28 +384,24 @@
 ?uid=abcdx%22;
-%0A  %7D
 %0A%0A    HttpPo
@@ -539,10 +539,8 @@
 %22);%0A
-%09%09
 %0A   
@@ -932,19 +932,16 @@
 word) %7B%0A
-  %7B
 %0A    // 
@@ -1052,16 +1052,8 @@
 x%22;%0A
-  %7D%0A%0A  %7B
 %0A   
@@ -1094,31 +1094,24 @@
 r HTTPS%0A    
-String 
 urlStr = %22ht
@@ -1159,20 +1159,16 @@
 =abcdx%22;
-%0A  %7D
 %0A%0A    St

Fix scope issues in the Java example