<commit_before>package org.fedorahosted.flies.rest.service;

import java.util.List;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.fedorahosted.flies.core.dao.AccountDAO;
import org.fedorahosted.flies.core.model.HAccount;
import org.hibernate.Session;
import org.jboss.resteasy.annotations.interception.SecurityPrecedence;
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.ResourceMethod;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.Failure;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.UnauthorizedException;
import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;
import org.jboss.seam.resteasy.SeamResteasyProviderFactory;

@SecurityPrecedence
@ServerInterceptor
public class FliesRestSecurityInterceptor implements PreProcessInterceptor{

	public static final String X_AUTH_TOKEN_HEADER = "X-Auth-Token";
	
	@In
	AccountDAO accountDAO;
	
	@Override
	public ServerResponse preProcess(HttpRequest request, ResourceMethod method)
			throws Failure, WebApplicationException {
		
		AccountDAO accountDAO = (AccountDAO) Component.getInstance(AccountDAO.class,true);
		Log log =  Logging.getLog(FliesRestSecurityInterceptor.class);
		log.info("Authenticating a REST request...");
		List<String> tokenHeaders = request.getHttpHeaders().getRequestHeader(X_AUTH_TOKEN_HEADER);
		if(tokenHeaders != null && tokenHeaders.isEmpty()){
			String apiKey = tokenHeaders.get(0);
			HAccount account = accountDAO.getByApiKey(apiKey);
			if(account != null) {
				// TODO set up seam identity framework here
				return null;
			}
		}
		
		throw new UnauthorizedException();
	}	
}<commit_msg>a not can make a lot of difference when authenticating :)<commit_after>package org.fedorahosted.flies.rest.service;

import java.util.List;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.fedorahosted.flies.core.dao.AccountDAO;
import org.fedorahosted.flies.core.model.HAccount;
import org.hibernate.Session;
import org.jboss.resteasy.annotations.interception.SecurityPrecedence;
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.ResourceMethod;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.Failure;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.UnauthorizedException;
import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;
import org.jboss.seam.resteasy.SeamResteasyProviderFactory;

@SecurityPrecedence
@ServerInterceptor
public class FliesRestSecurityInterceptor implements PreProcessInterceptor{

	public static final String X_AUTH_TOKEN_HEADER = "X-Auth-Token";
	
	@In
	AccountDAO accountDAO;
	
	@Override
	public ServerResponse preProcess(HttpRequest request, ResourceMethod method)
			throws Failure, WebApplicationException {
		
		AccountDAO accountDAO = (AccountDAO) Component.getInstance(AccountDAO.class,true);
		Log log =  Logging.getLog(FliesRestSecurityInterceptor.class);
		log.info("Authenticating a REST request...");
		List<String> tokenHeaders = request.getHttpHeaders().getRequestHeader(X_AUTH_TOKEN_HEADER);
		if(tokenHeaders != null && !tokenHeaders.isEmpty()){
			String apiKey = tokenHeaders.get(0);
			HAccount account = accountDAO.getByApiKey(apiKey);
			if(account != null) {
				// TODO set up seam identity framework here
				return null;
			}
		}
		
		throw new UnauthorizedException();
	}	
}
{'fraction_non_alphanumeric': 0.10206995003568879, 'fraction_numerical': 0.0004758505829169641, 'mean_word_length': 5.791599353796446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '381453', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1327, 'n_words': 236}