jenkins.model.Jenkins.getCrumbIssuer()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中jenkins.model.Jenkins.getCrumbIssuer()方法的一些代码示例,展示了Jenkins.getCrumbIssuer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getCrumbIssuer()方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getCrumbIssuer

Jenkins.getCrumbIssuer介绍

[英]Gets the CrumbIssuer currently in use.
[中]获取当前正在使用的颁发者。

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Because servlet containers generally don't specify the ordering of the initialization
 * (and different implementations indeed do this differently --- See HUDSON-3878),
 * we cannot use Hudson to the CrumbIssuer into CrumbFilter eagerly.
 */
public CrumbIssuer getCrumbIssuer() {
  Jenkins h = Jenkins.getInstanceOrNull();
  if(h==null)     return null;    // before Jenkins is initialized?
  return h.getCrumbIssuer();
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean isActivated() {
    return Jenkins.get().getCrumbIssuer() == null;
  }
}

代码示例来源:origin: jenkinsci/jenkins

public static String getCrumb(StaplerRequest req) {
  Jenkins h = Jenkins.getInstanceOrNull();
  CrumbIssuer issuer = h != null ? h.getCrumbIssuer() : null;
  return issuer != null ? issuer.getCrumb(req) : "";
}

代码示例来源:origin: jenkinsci/jenkins

public static String getCrumbRequestField() {
  Jenkins h = Jenkins.getInstanceOrNull();
  CrumbIssuer issuer = h != null ? h.getCrumbIssuer() : null;
  return issuer != null ? issuer.getDescriptor().getCrumbRequestField() : "";
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public String issueCrumb(StaplerRequest request) {
  CrumbIssuer ci = Jenkins.getInstance().getCrumbIssuer();
  return ci!=null ? ci.getCrumb(request) : DEFAULT.issueCrumb(request);
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  public void validateCrumb(StaplerRequest request, String submittedCrumb) {
    CrumbIssuer ci = Jenkins.getInstance().getCrumbIssuer();
    if (ci==null) {
      DEFAULT.validateCrumb(request,submittedCrumb);
    } else {
      if (!ci.validateCrumb(request, ci.getDescriptor().getCrumbSalt(), submittedCrumb))
        throw new SecurityException("Crumb didn't match");
    }
  }
});

代码示例来源:origin: jenkinsci/jenkins

@RequirePOST
@Restricted(NoExternalUse.class)
public HttpResponse doConfigureInstance(StaplerRequest req, @QueryParameter String rootUrl) {
  Jenkins.get().checkPermission(Jenkins.ADMINISTER);
  
  Map<String, String> errors = new HashMap<>();
  // pre-check data
  checkRootUrl(errors, rootUrl);
  
  if(!errors.isEmpty()){
    return HttpResponses.errorJSON(Messages.SetupWizard_ConfigureInstance_ValidationErrors(), errors);
  }
  
  // use the parameters to configure the instance
  useRootUrl(errors, rootUrl);
  
  if(!errors.isEmpty()){
    return HttpResponses.errorJSON(Messages.SetupWizard_ConfigureInstance_ValidationErrors(), errors);
  }
  
  InstallUtil.proceedToNextStateFrom(InstallState.CONFIGURE_INSTANCE);
  CrumbIssuer crumbIssuer = Jenkins.get().getCrumbIssuer();
  JSONObject data = new JSONObject();
  if (crumbIssuer != null) {
    data.accumulate("crumbRequestField", crumbIssuer.getCrumbRequestField()).accumulate("crumb", crumbIssuer.getCrumb(req));
  }
  return HttpResponses.okJSON(data);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Do a finger-print check.
 */
@RequirePOST
public void doDoFingerprintCheck( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  // Parse the request
  try (MultipartFormDataParser p = new MultipartFormDataParser(req)) {
    if (isUseCrumbs() && !getCrumbIssuer().validateCrumb(req, p)) {
      // TODO investigate whether this check can be removed
      rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "No crumb found");
    }
    rsp.sendRedirect2(req.getContextPath()+"/fingerprint/"+
      Util.getDigestOf(p.getFileItem("name").getInputStream())+'/');
  }
}

代码示例来源:origin: jenkinsci/jenkins

CrumbIssuer crumbIssuer = Jenkins.getInstance().getCrumbIssuer();
JSONObject data = new JSONObject();
if (crumbIssuer != null) {

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
  public boolean isActivated() {
    return Jenkins.getInstance().getCrumbIssuer() == null;
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Because servlet containers generally don't specify the ordering of the initialization
 * (and different implementations indeed do this differently --- See HUDSON-3878),
 * we cannot use Hudson to the CrumbIssuer into CrumbFilter eagerly.
 */
public CrumbIssuer getCrumbIssuer() {
  Jenkins h = Jenkins.getInstanceOrNull();
  if(h==null)     return null;    // before Jenkins is initialized?
  return h.getCrumbIssuer();
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public static String getCrumb(StaplerRequest req) {
  Jenkins h = Jenkins.getInstanceOrNull();
  CrumbIssuer issuer = h != null ? h.getCrumbIssuer() : null;
  return issuer != null ? issuer.getCrumb(req) : "";
}

代码示例来源:origin: jenkinsci/jenkins-test-harness

private NameValuePair getCrumbHeaderNVP() {
    return new NameValuePair(jenkins.getCrumbIssuer().getDescriptor().getCrumbRequestField(),
            jenkins.getCrumbIssuer().getCrumb( null ));
  }
}

代码示例来源:origin: jenkinsci/jenkins-test-harness

/**
 * Adds a security crumb to the quest
 */
public WebRequest addCrumb(WebRequest req) {
  com.gargoylesoftware.htmlunit.util.NameValuePair crumb = new com.gargoylesoftware.htmlunit.util.NameValuePair(
      jenkins.getCrumbIssuer().getDescriptor().getCrumbRequestField(),
      jenkins.getCrumbIssuer().getCrumb( null ));
  req.setRequestParameters(Arrays.asList( crumb ));
  return req;
}

代码示例来源:origin: jenkinsci/jenkins-test-harness

/**
 * Creates a URL with crumb parameters relative to {{@link #getContextPath()}
 */
public URL createCrumbedUrl(String relativePath) throws IOException {
  CrumbIssuer issuer = jenkins.getCrumbIssuer();
  String crumbName = issuer.getDescriptor().getCrumbRequestField();
  String crumb = issuer.getCrumb(null);
  if (relativePath.indexOf('?') == -1) {
    return new URL(getContextPath()+relativePath+"?"+crumbName+"="+crumb);
  }
  return new URL(getContextPath()+relativePath+"&"+crumbName+"="+crumb);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public static String getCrumbRequestField() {
  Jenkins h = Jenkins.getInstanceOrNull();
  CrumbIssuer issuer = h != null ? h.getCrumbIssuer() : null;
  return issuer != null ? issuer.getDescriptor().getCrumbRequestField() : "";
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
public String issueCrumb(StaplerRequest request) {
  CrumbIssuer ci = Jenkins.getInstance().getCrumbIssuer();
  return ci!=null ? ci.getCrumb(request) : DEFAULT.issueCrumb(request);
}

代码示例来源:origin: jenkinsci/jenkins-test-harness

/**
 * Creates a URL with crumb parameters relative to {{@link #getContextPath()}
 */
public URL createCrumbedUrl(String relativePath) throws IOException {
  CrumbIssuer issuer = jenkins.getCrumbIssuer();
  String crumbName = issuer.getDescriptor().getCrumbRequestField();
  String crumb = issuer.getCrumb(null);
  
  return new URL(getContextPath()+relativePath+"?"+crumbName+"="+crumb);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
  public void validateCrumb(StaplerRequest request, String submittedCrumb) {
    CrumbIssuer ci = Jenkins.getInstance().getCrumbIssuer();
    if (ci==null) {
      DEFAULT.validateCrumb(request,submittedCrumb);
    } else {
      if (!ci.validateCrumb(request, ci.getDescriptor().getCrumbSalt(), submittedCrumb))
        throw new SecurityException("Crumb didn't match");
    }
  }
});

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Do a finger-print check.
 */
@RequirePOST
public void doDoFingerprintCheck( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  // Parse the request
  try (MultipartFormDataParser p = new MultipartFormDataParser(req)) {
    if (isUseCrumbs() && !getCrumbIssuer().validateCrumb(req, p)) {
      // TODO investigate whether this check can be removed
      rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "No crumb found");
    }
    rsp.sendRedirect2(req.getContextPath()+"/fingerprint/"+
      Util.getDigestOf(p.getFileItem("name").getInputStream())+'/');
  }
}

相关文章

Jenkins类方法