<commit_before>package org.ihtsdo.buildcloud.security;

import org.ihtsdo.buildcloud.entity.User;
import org.ihtsdo.buildcloud.service.AuthenticationService;
import org.ihtsdo.buildcloud.service.security.SecurityHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.DatatypeConverter;

public class SecurityHandlerInterceptor implements HandlerInterceptor {

	@Autowired
	private AuthenticationService authenticationService;

	private static final String AUTH_TOKEN_NAME = "auth_token";

	private static final Logger LOGGER = LoggerFactory.getLogger(SecurityHandlerInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		SecurityHelper.clearUser();
		final String authHeader = request.getHeader("Authorization");
		//For a file upload we're sending the auth token in a hidden input element
		final String authParameter = request.getParameter(AUTH_TOKEN_NAME);
		
		String pathInfo = request.getPathInfo();
		String requestMethod = request.getMethod();
		LOGGER.debug("pathInfo: '{}' from {}", pathInfo, request.getRemoteAddr());
		User validUser = null;

		if (pathInfo != null && pathInfo.startsWith("/login")) {
			// Trying to log in
			validUser = authenticationService.getAnonymousSubject();
		} else if (authHeader == null && (requestMethod.equals("GET") || requestMethod.equals("HEAD"))) {<commit_msg>SRS-640 Corrected authentication token name<commit_after>package org.ihtsdo.buildcloud.security;

import org.ihtsdo.buildcloud.entity.User;
import org.ihtsdo.buildcloud.service.AuthenticationService;
import org.ihtsdo.buildcloud.service.security.SecurityHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.DatatypeConverter;

public class SecurityHandlerInterceptor implements HandlerInterceptor {

	@Autowired
	private AuthenticationService authenticationService;

	private static final String AUTH_TOKEN_NAME = "X-AUTH-token";

	private static final Logger LOGGER = LoggerFactory.getLogger(SecurityHandlerInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		SecurityHelper.clearUser();
		final String authHeader = request.getHeader("Authorization");
		//For a file upload we're sending the auth token in a hidden input element
		final String authParameter = request.getParameter(AUTH_TOKEN_NAME);
		
		String pathInfo = request.getPathInfo();
		String requestMethod = request.getMethod();
		LOGGER.debug("pathInfo: '{}' from {}", pathInfo, request.getRemoteAddr());
		User validUser = null;

		if (pathInfo != null && pathInfo.startsWith("/login")) {
			// Trying to log in
			validUser = authenticationService.getAnonymousSubject();
		} else if (authHeader == null && (requestMethod.equals("GET") || requestMethod.equals("HEAD"))) {
{'fraction_non_alphanumeric': 0.09779454439930355, 'fraction_numerical': 0.0020313406848520023, 'mean_word_length': 6.334042553191489, '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': '6990677', 'n_tokens_mistral': 954, 'n_tokens_neox': 926, 'n_words': 220}