<commit_before>package hudson.model;

import com.thoughtworks.xstream.converters.basic.AbstractBasicConverter;
import hudson.Util;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import java.io.IOException;

/**
 * Authorization token to allow projects to trigger themselves under the secured environment.
 *
 * @author <NAME>
 * @see BuildableItem
 */
public final class BuildAuthorizationToken {
    private final String token;

    public BuildAuthorizationToken(String token) {
        this.token = token;
    }

    public static BuildAuthorizationToken create(StaplerRequest req) {
        if (req.getParameter("pseudoRemoteTrigger") != null)
            return new BuildAuthorizationToken(Util.fixEmpty(req.getParameter("authToken")));
        else
            return null;
    }

    public static void checkPermission(AbstractProject project, BuildAuthorizationToken token, StaplerRequest req, StaplerResponse rsp) throws IOException {
        if (!Hudson.getInstance().isUseSecurity())
            return;    // everyone is authorized

        if(token!=null) {
            if(token.token != null) {
                //check the provided token
                String providedToken = req.getParameter("token");
                if (providedToken != null && providedToken.equals(token.token))
                    return;
            }
        }

        project.checkPermission(AbstractProject.BUILD);<commit_msg>[FIXED HUDSON-2089] I believe I fixed this NPE now in 1.236.<commit_after>package hudson.model;

import com.thoughtworks.xstream.converters.basic.AbstractBasicConverter;
import hudson.Util;
import hudson.security.ACL;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import java.io.IOException;

/**
 * Authorization token to allow projects to trigger themselves under the secured environment.
 *
 * @author <NAME>
 * @see BuildableItem
 * @deprecated
 *      Use {@link ACL} and {@link AbstractProject#BUILD}. This code is only here
 *      for the backward compatibility.
 */
public final class BuildAuthorizationToken {
    private final String token;

    public BuildAuthorizationToken(String token) {
        this.token = token;
    }

    public static BuildAuthorizationToken create(StaplerRequest req) {
        if (req.getParameter("pseudoRemoteTrigger") != null) {
            String token = Util.fixEmpty(req.getParameter("authToken"));
            if(token!=null)
                return new BuildAuthorizationToken(token);
        }
        
        return null;
    }

    public static void checkPermission(AbstractProject project, BuildAuthorizationToken token, StaplerRequest req, StaplerResponse rsp) throws IOException {
        if (!Hudson.getInstance().isUseSecurity())
            return;    // everyone is authorized

        if(token!=null) {
            if(token.token != null) {
                //check the provided token
                String providedToken = req.getParameter("token");
                if (providedToken != null && providedToken.equals(token.token))
                    return;
            }
        }

        project.checkPermission(AbstractProject.BUILD);
{'fraction_non_alphanumeric': 0.0890625, 'fraction_numerical': 0.0025, 'mean_word_length': 2.851985559566787, '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': '6741846', 'n_tokens_mistral': 841, 'n_tokens_neox': 801, 'n_words': 210}