<commit_before>package br.com.caelum.brutal.auth;

import static br.com.caelum.vraptor.view.Results.http;
import br.com.caelum.brutal.auth.rules.ComposedRule;
import br.com.caelum.brutal.auth.rules.MinimumKarmaRule;
import br.com.caelum.brutal.auth.rules.ModeratorRule;
import br.com.caelum.brutal.auth.rules.PermissionRule;
import br.com.caelum.brutal.model.User;
import br.com.caelum.vraptor.InterceptionException;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.interceptor.Interceptor;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.resource.ResourceMethod;

@Intercepts
@Component
public class ModeratorOrEnoughKarmaInterceptor implements Interceptor {
    
    private final User currentUser;
    private final Result result;
    
    public ModeratorOrEnoughKarmaInterceptor(User currentUser, Result result) {
        this.currentUser = currentUser;
        this.result = result;
    }

    @Override
    public boolean accepts(ResourceMethod method) {
        return method.containsAnnotation(ModeratorOrKarmaAccess.class);
    }

    @Override
    public void intercept(InterceptorStack stack, ResourceMethod method, Object obj)
            throws InterceptionException {
    	long karma = method.getMethod().getAnnotation(ModeratorOrKarmaAccess.class).value();
    	
    	MinimumKarmaRule<Void> minimumKarmaRule = new MinimumKarmaRule<>(karma);
    	ModeratorRule moderatorRule = new ModeratorRule();
    	ComposedRule<Void> compose = new ComposedRule<>();
    	
    	PermissionRule<Void> rule = compose.thiz(moderatorRule).or(minimumKarmaRule);
    	
        if (currentUser == null || rule.isAllowed(currentUser, null)){
            result.use(http()).sendError(403);
            return;
        }
        stack.next(method, obj);
    }
<commit_msg>faltou uma negacao marota :)<commit_after>package br.com.caelum.brutal.auth;

import static br.com.caelum.vraptor.view.Results.http;
import br.com.caelum.brutal.auth.rules.ComposedRule;
import br.com.caelum.brutal.auth.rules.MinimumKarmaRule;
import br.com.caelum.brutal.auth.rules.ModeratorRule;
import br.com.caelum.brutal.auth.rules.PermissionRule;
import br.com.caelum.brutal.model.User;
import br.com.caelum.vraptor.InterceptionException;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.interceptor.Interceptor;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.resource.ResourceMethod;

@Intercepts
@Component
public class ModeratorOrEnoughKarmaInterceptor implements Interceptor {
    
    private final User currentUser;
    private final Result result;
    
    public ModeratorOrEnoughKarmaInterceptor(User currentUser, Result result) {
        this.currentUser = currentUser;
        this.result = result;
    }

    @Override
    public boolean accepts(ResourceMethod method) {
        return method.containsAnnotation(ModeratorOrKarmaAccess.class);
    }

    @Override
    public void intercept(InterceptorStack stack, ResourceMethod method, Object obj)
            throws InterceptionException {
    	long karma = method.getMethod().getAnnotation(ModeratorOrKarmaAccess.class).value();
    	
    	MinimumKarmaRule<Void> minimumKarmaRule = new MinimumKarmaRule<>(karma);
    	ModeratorRule moderatorRule = new ModeratorRule();
    	ComposedRule<Void> compose = new ComposedRule<>();
    	
    	PermissionRule<Void> rule = compose.thiz(moderatorRule).or(minimumKarmaRule);
    	
        if (currentUser == null || !rule.isAllowed(currentUser, null)){
            result.use(http()).sendError(403);
            return;
        }
        stack.next(method, obj);
    }

{'fraction_non_alphanumeric': 0.10047219307450157, 'fraction_numerical': 0.0015739769150052466, 'mean_word_length': 3.971316818774446, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5714125', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1250, 'n_words': 200}