Compare commits
	
		
			4 Commits
		
	
	
		
			http_const
			...
			5bdebcee04
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 5bdebcee04 | |||
| a1e1caff5d | |||
| e22dec88a5 | |||
| a757b08722 | 
@@ -24,14 +24,12 @@ public class Main {
 | 
			
		||||
    public static String password = "AdminSecret1C";
 | 
			
		||||
    public static String port = "443";
 | 
			
		||||
    public static int rotation = 4;
 | 
			
		||||
    public static boolean insecure = false;
 | 
			
		||||
    public static boolean asynchronous = true;
 | 
			
		||||
    public static Request requestClient;
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) throws IOException, InterruptedException, NoSuchAlgorithmException, KeyManagementException {
 | 
			
		||||
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
 | 
			
		||||
 | 
			
		||||
        requestClient = new Request(false);
 | 
			
		||||
 | 
			
		||||
        if (Arrays.asList(args).contains("--synchronous") || Arrays.asList(args).contains("-s")) {
 | 
			
		||||
            asynchronous = false;
 | 
			
		||||
        }
 | 
			
		||||
@@ -71,7 +69,7 @@ public class Main {
 | 
			
		||||
        boolean tokenFound = false;
 | 
			
		||||
        while (!tokenFound) {
 | 
			
		||||
            try {
 | 
			
		||||
                response = requestClient.get(link, port, "/login", requestJSON, null);
 | 
			
		||||
                response = Request.get(link, port, "/login", requestJSON, null, insecure);
 | 
			
		||||
                if (response.statusCode() == 308) {
 | 
			
		||||
                    System.err.println("The server is trying to force HTTPS use. Would you like to retry with HTTPS ? [Y/n]");
 | 
			
		||||
                    if (reader.readLine().equalsIgnoreCase("n")) {
 | 
			
		||||
@@ -90,7 +88,7 @@ public class Main {
 | 
			
		||||
                    System.err.println("Operation aborted ! Security failure.");
 | 
			
		||||
                    System.exit(1);
 | 
			
		||||
                } else {
 | 
			
		||||
                    requestClient = new Request(true);
 | 
			
		||||
                    insecure = true;
 | 
			
		||||
                }
 | 
			
		||||
            } catch (SSLException e) {
 | 
			
		||||
                if (e.getMessage().contains("plaintext connection?")) {
 | 
			
		||||
@@ -110,6 +108,8 @@ public class Main {
 | 
			
		||||
            System.exit(1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        System.out.println(response.statusCode());
 | 
			
		||||
 | 
			
		||||
        JSONObject responseObject = new JSONObject(response.body());
 | 
			
		||||
        String token = responseObject.optString("token");
 | 
			
		||||
 | 
			
		||||
@@ -124,7 +124,7 @@ public class Main {
 | 
			
		||||
        Map<String, String> headers = new HashMap<>();
 | 
			
		||||
        headers.put("Authorization", "Bearer " + token);
 | 
			
		||||
 | 
			
		||||
        response = requestClient.get(link, port, "/references", requestJSON, headers);
 | 
			
		||||
        response = Request.get(link, port, "/references", requestJSON, headers, insecure);
 | 
			
		||||
        JSONArray usersArray = new JSONArray(response.body());
 | 
			
		||||
 | 
			
		||||
        System.out.println(usersArray.length() + " users found !");
 | 
			
		||||
 
 | 
			
		||||
@@ -16,19 +16,16 @@ import java.util.Map;
 | 
			
		||||
 | 
			
		||||
public class Request {
 | 
			
		||||
 | 
			
		||||
    private final HttpClient client;
 | 
			
		||||
    public static HttpResponse<String> get(String link, String port, String endpoint,JSONObject params, Map<String, String> headers, boolean insecure) throws NoSuchAlgorithmException, KeyManagementException, IOException, InterruptedException {
 | 
			
		||||
        HttpClient client = HttpClient.newHttpClient();
 | 
			
		||||
 | 
			
		||||
    public Request(boolean insecure) throws NoSuchAlgorithmException, KeyManagementException {
 | 
			
		||||
        HttpClient.Builder builder = HttpClient.newBuilder();
 | 
			
		||||
        if (insecure) {
 | 
			
		||||
            SSLContext customContext = SSLContext.getInstance("TLS");
 | 
			
		||||
            customContext.init(null, new TrustManager[]{new SSLBypass()}, new SecureRandom());
 | 
			
		||||
            builder.sslContext(customContext);
 | 
			
		||||
        }
 | 
			
		||||
        this.client = builder.build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public HttpResponse<String> get(String link, String port, String endpoint,JSONObject params, Map<String, String> headers) throws IOException, InterruptedException {
 | 
			
		||||
            client = HttpClient.newBuilder().sslContext(customContext).build();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(link + ":" + port + endpoint));
 | 
			
		||||
        if (headers != null) {
 | 
			
		||||
            for (Map.Entry<String, String> header : headers.entrySet()) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user