hudson.Util.getDigestOf()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(181)

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

Util.getDigestOf介绍

[英]Computes the MD5 digest of a file.
[中]计算文件的MD5摘要。

代码示例

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

@Override
  public String invoke(File f, VirtualChannel channel) throws IOException {
    return Util.getDigestOf(reading(f));
  }
}

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

@Nonnull
public static String getDigestOf(@Nonnull String text) {
  try {
    return getDigestOf(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)));
  } catch (IOException e) {
    throw new Error(e);
  }
}

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

/**
 * Computes the MD5 digest of a file.
 * @param file a file
 * @return a 32-character string
 * @throws IOException in case reading fails
 * @since 1.525
 */
@Nonnull
public static String getDigestOf(@Nonnull File file) throws IOException {
  // Note: getDigestOf() closes the input stream.
  return getDigestOf(Files.newInputStream(fileToPath(file)));
}

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

/**
 * Returns the unique identifier of this Jenkins that has been historically used to identify
 * this Jenkins to the outside world.
 *
 * <p>
 * This form of identifier is weak in that it can be impersonated by others. See
 * https://wiki.jenkins-ci.org/display/JENKINS/Instance+Identity for more modern form of instance ID
 * that can be challenged and verified.
 *
 * @since 1.498
 */
@SuppressWarnings("deprecation")
public String getLegacyInstanceId() {
  return Util.getDigestOf(getSecretKey());
}

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

context.setAttribute("version",ver);
VERSION_HASH = Util.getDigestOf(ver).substring(0, 8);
SESSION_HASH = Util.getDigestOf(ver+System.currentTimeMillis()).substring(0, 8);

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

/**
 * If {@code jenkins.exe} is old compared to our copy,
 * schedule an overwrite (except that since it's currently running,
 * we can only do it when Jenkins restarts next time.)
 */
private void updateJenkinsExeIfNeeded() {
  try {
    File baseDir = getBaseDir();
    URL exe = getClass().getResource("/windows-service/jenkins.exe");
    String ourCopy = Util.getDigestOf(exe.openStream());
    for (String name : new String[]{"hudson.exe","jenkins.exe"}) {
      try {
        File currentCopy = new File(baseDir,name);
        if(!currentCopy.exists())   continue;
        String curCopy = new FilePath(currentCopy).digest();
        if(ourCopy.equals(curCopy))     continue; // identical
        File stage = new File(baseDir,name+".new");
        FileUtils.copyURLToFile(exe,stage);
        Kernel32.INSTANCE.MoveFileExA(stage.getAbsolutePath(),currentCopy.getAbsolutePath(),MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING);
        LOGGER.info("Scheduled a replacement of "+name);
      } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Failed to replace "+name,e);
      } catch (InterruptedException e) {
      }
    }
  } catch (IOException e) {
    LOGGER.log(Level.SEVERE, "Failed to replace jenkins.exe",e);
  }
}

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

private void addLegacyToken(@Nonnull Secret legacyToken, boolean migrationFromExistingLegacy) {
  String tokenUserUseNormally = Util.getDigestOf(legacyToken.getPlainText());
  
  String secretValueHashed = this.plainSecretToHashInHex(tokenUserUseNormally);
  
  HashValue hashValue = new HashValue(LEGACY_VERSION, secretValueHashed);
  HashedToken token = HashedToken.buildNewFromLegacy(hashValue, migrationFromExistingLegacy);
  
  this.addToken(token);
}

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

@Nonnull
@Restricted(NoExternalUse.class)
/*package*/ String getApiTokenInsecure() {
  if(apiToken == null){
    return Messages.ApiTokenProperty_NoLegacyToken();
  }
  String p = apiToken.getPlainText();
  if (p.equals(Util.getDigestOf(Jenkins.getInstance().getSecretKey()+":"+user.getId()))) {
    // if the current token is the initial value created by pre SECURITY-49 Jenkins, we can't use that.
    // force using the newer value
    apiToken = Secret.fromString(p=API_KEY_SEED.mac(user.getId()));
  }
  return Util.getDigestOf(p);
}

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

public static @CheckForNull User isConnectingUsingApiToken(String username, String tokenValue){
    User user = User.getById(username, false);
    if(user == null){
      ApiTokenPropertyConfiguration apiTokenConfiguration = GlobalConfiguration.all().getInstance(ApiTokenPropertyConfiguration.class);
      if(apiTokenConfiguration.isTokenGenerationOnCreationEnabled()){
        String generatedTokenOnCreation = Util.getDigestOf(ApiTokenProperty.API_KEY_SEED.mac(username));
        boolean areTokenEqual = MessageDigest.isEqual(
            generatedTokenOnCreation.getBytes(StandardCharsets.US_ASCII),
            tokenValue.getBytes(StandardCharsets.US_ASCII)
        );
        if(areTokenEqual){
          // directly return the user freshly created
          // and no need to check its token as the generated token 
          // will be the same as the one we checked just above
          return User.getById(username, true);
        }
      }
    }else{
      ApiTokenProperty t = user.getProperty(ApiTokenProperty.class);
      if (t!=null && t.matchesPassword(tokenValue)) {
        return user;
      }
    }
    
    return null;
  }
}

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

InputStream fingerprintInput = baseFile.open();
try {
  rsp.forward(Jenkins.getInstance().getFingerprint(Util.getDigestOf(fingerprintInput)), "/", req);
} finally {
  fingerprintInput.close();

代码示例来源: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: hudson/hudson-2.x

public static String getDigestOf(String text) {
  try {
    return getDigestOf(new ByteArrayInputStream(text.getBytes("UTF-8")));
  } catch (IOException e) {
    throw new Error(e);
  }
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

public static String getDigestOf(String text) {
  try {
    return getDigestOf(new ByteArrayInputStream(text.getBytes("UTF-8")));
  } catch (IOException e) {
    throw new Error(e);
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Gets the 8 character-wide hash code for this combination
 */
public String digest() {
  return Util.getDigestOf(toString());
}

代码示例来源:origin: org.jenkins-ci.plugins/matrix-project

/**
 * Gets the 8 character-wide hash code for this combination
 */
public String digest() {
  return Util.getDigestOf(toString());
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Gets the 8 character-wide hash code for this combination
 */
public String digest() {
  return Util.getDigestOf(toString());
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-test-harness

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  String path = req.getServletPath();
  String d = Util.getDigestOf(path);
  File cache = new File(cacheFolder, d);
  if(!cache.exists()) {
    URL url = new URL("http://hudson-ci.org/" + path);
    FileUtils.copyURLToFile(url,cache);
  }
  resp.setContentType(getMimeType(path));
  IOUtils.copy(cache,resp.getOutputStream());
}

代码示例来源:origin: jenkinsci/docker-plugin

public static String getInstanceId() {
  try {
    if( _id == null ) {
      _id = Util.getDigestOf(
          new ByteArrayInputStream(InstanceIdentity.get().getPublic().getEncoded()));
    }
  } catch (IOException e) {
    LOG.error("Could not get Jenkins instance ID.");
    _id = "";
  }
  return _id;
}

代码示例来源:origin: org.jenkins-ci.modules/systemd-slave-installer

@Override
public SlaveInstaller createIfApplicable(Channel c) throws IOException, InterruptedException {
  if (c.call(new HasSystemd())) {
    RSAPublicKey key = id.getPublic();
    String instanceId = Util.getDigestOf(new String(Base64.encodeBase64(key.getEncoded()))).substring(0,8);
    return new SystemdSlaveInstaller(instanceId);
  }
  return null;
}

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

@Nonnull
@Restricted(NoExternalUse.class)
/*package*/ String getApiTokenInsecure() {
  String p = apiToken.getPlainText();
  if (p.equals(Util.getDigestOf(Jenkins.getInstance().getSecretKey()+":"+user.getId()))) {
    // if the current token is the initial value created by pre SECURITY-49 Jenkins, we can't use that.
    // force using the newer value
    apiToken = Secret.fromString(p=API_KEY_SEED.mac(user.getId()));
  }
  return Util.getDigestOf(p);
}

相关文章

微信公众号

最新文章

更多