<commit_before>package com.conveyal.datatools.manager.auth;

import com.conveyal.datatools.manager.DataManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import spark.Request;

import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.URL;

import static spark.Spark.halt;

/**
 * Created by demory on 3/22/16.
 */

public class Auth0Connection {

    public static void checkUser(Request req) {
        String token = getToken(req);

        if(token == null) {
            halt(401, "Could not find authorization token");
        }

        try {
            Auth0UserProfile profile = getUserProfile(token);
            req.attribute("user", profile);
        }
        catch(Exception e) {
            e.printStackTrace();
            halt(401, "Could not verify user");
        }
    }

    public static String getToken(Request req) {
        String token = null;

        final String authorizationHeader = req.headers("Authorization");
        if (authorizationHeader == null) return null;

        // check format (Authorization: Bearer [token])
        String[] parts = authorizationHeader.split(" ");
        if (parts.length != 2) return null;

        String scheme = parts[0];
        String credentials = parts[1];

        if (scheme.equals("Bearer")) token = credentials;<commit_msg>do not log every time an unauthenticated call is made<commit_after>package com.conveyal.datatools.manager.auth;

import com.conveyal.datatools.manager.DataManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import spark.Request;

import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.URL;

import static spark.Spark.halt;

/**
 * Created by demory on 3/22/16.
 */

public class Auth0Connection {

    public static void checkUser(Request req) {
        String token = getToken(req);

        if(token == null) {
            halt(401, "Could not find authorization token");
        }

        try {
            Auth0UserProfile profile = getUserProfile(token);
            req.attribute("user", profile);
        }
        catch(Exception e) {
//            e.printStackTrace();
            halt(401, "Could not verify user");
        }
    }

    public static String getToken(Request req) {
        String token = null;

        final String authorizationHeader = req.headers("Authorization");
        if (authorizationHeader == null) return null;

        // check format (Authorization: Bearer [token])
        String[] parts = authorizationHeader.split(" ");
        if (parts.length != 2) return null;

        String scheme = parts[0];
        String credentials = parts[1];

        if (scheme.equals("Bearer")) token = credentials;
{'fraction_non_alphanumeric': 0.10714285714285714, 'fraction_numerical': 0.011204481792717087, 'mean_word_length': 2.7200520833333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3524141', 'n_tokens_mistral': 812, 'n_tokens_neox': 763, 'n_words': 206}