List of usage examples for org.apache.commons.codec.digest DigestUtils md5Hex
public static String md5Hex(String data)
From source file:cn.wanghaomiao.seimi.def.DefaultLocalQueue.java
@Override public boolean isProcessed(Request req) { ConcurrentSkipListSet<String> set = getProcessedSet(req.getCrawlerName()); String sign = DigestUtils.md5Hex(req.getUrl()); return set.contains(sign); }
From source file:com.jaeksoft.searchlib.util.FileUtils.java
public final static String computeMd5(File file) { FileInputStream fis = null;//from w ww. j a va 2 s .c om try { fis = new FileInputStream(file); return DigestUtils.md5Hex(fis); } catch (IOException e) { Logging.warn(e); return null; } finally { if (fis != null) IOUtils.closeQuietly(fis); } }
From source file:com.epam.ta.reportportal.auth.DatabaseUserDetailsProviderTest.java
@Test public void testDetailLoading() { UserDetails details = userDetailsService.loadUserByUsername(AuthConstants.TEST_USER); Assert.assertEquals("Incorrect userName", AuthConstants.TEST_USER, details.getUsername()); Assert.assertEquals("Incorrect password", DigestUtils.md5Hex(AuthConstants.USER_PASSWORD), details.getPassword());//from ww w . j a v a 2s. c o m Assert.assertEquals("Incorrect Granted Authorities size", 1, details.getAuthorities().size()); GrantedAuthority authority = details.getAuthorities().iterator().next(); Assert.assertEquals("Incorrect Granted Authorities", AuthConstants.ROLE.name(), authority.getAuthority()); }
From source file:com.yevster.spdxtra.TestFileOperations.java
@Test public void testAddFileToPackage() { assertEquals("Newly-created package should have no files", 0, pkg.getFiles().count()); final String fileName = "./foo/bar/whatevs.txt"; final String expectedFileUrl = baseUrl + "#SPDXRef-myFile"; final String mockSha1 = "abc135875aeffffff"; final String mockMd5 = DigestUtils.md5Hex("My sum"); final String mockSha256 = DigestUtils.sha256Hex("My sum"); final String extractedLicense = "This is the extracting license. Once this was in a file. Now it is here."; final String copyrightText = "Copyright (C) 2016 Aweomsness Awesome, Inc."; final String comment = "No comment. Carry on. Wait, this is a comment. Curses!"; final String artifactOfHomepage = "http://example.org/epic/fail"; final String artifactOfName = "Epic Failure 1,9"; final String licenseName = "El nombre"; Write.applyUpdatesInOneTransaction(dataset, Write.Package.addFile(baseUrl, packageSpdxId, "SPDXRef-myFile", fileName), Write.File.fileTypes(expectedFileUrl, FileType.OTHER, FileType.APPLICATION), Write.File.concludedLicense(expectedFileUrl, License.NONE), Write.File.checksums(expectedFileUrl, mockSha1, Checksum.md5(mockMd5)), Write.File.addLicenseInfoInFile(expectedFileUrl, License.extracted(extractedLicense, licenseName, baseUrl, "LicenseRef-el")), Write.File.artifactOf(expectedFileUrl, artifactOfName, null)); reloadPackage();/*from w w w.j a v a 2s . c om*/ List<SpdxFile> allFilesInPackage = pkg.getFiles().collect(Collectors.toList()); assertEquals("Expected to one file in package after adding one file.", 1, allFilesInPackage.size()); SpdxFile file = allFilesInPackage.get(0); assertEquals(expectedFileUrl, file.getUri()); assertEquals(fileName, file.getFileName()); assertEquals(Sets.newHashSet(FileType.OTHER, FileType.APPLICATION), file.getFileTypes()); assertEquals(AbsentValue.NONE.getUri(), file.getPropertyAsResource(SpdxProperties.LICENSE_CONCLUDED).get().getURI()); assertEquals(Sets.newHashSet(Checksum.md5(mockMd5), Checksum.sha1(mockSha1)), file.getChecksums()); // Test default copyright - NOASSERTION assertEquals(SpdxUris.NO_ASSERTION, file.getCopyrightText().getLiteralOrUriValue()); assertEquals("Empty optional not returned for uninitialized comment", Optional.empty(), file.getComment()); assertEquals(Optional.empty(), file.getOptionalPropertyAsString(SpdxProperties.LICENSE_COMMENTS)); assertEquals(Optional.empty(), file.getNoticeText()); assertEquals(new HashSet<String>(), file.getContributors()); Resource doapProject = file.rdfResource.getProperty(SpdxProperties.ARTIFACT_OF).getObject().asResource(); // The spec supports a value of UNKNOWN, but as other tools validate // this field as a URL and it is optional // SpdXtra should omit it entirely if blank. Assert.assertEquals("When DOAP homepage not specified, should omit.", false, doapProject.listProperties(SpdxProperties.DOAP_HOMEPAGE).hasNext()); Assert.assertEquals(artifactOfName, doapProject.getProperty(SpdxProperties.DOAP_NAME).getString()); // Test overwrites Write.applyUpdatesInOneTransaction(dataset, Write.File.checksums(file.getUri(), mockSha1, Checksum.sha256(mockSha256)), Write.File.copyrightText(expectedFileUrl, NoneNoAssertionOrValue.of(copyrightText)), Write.File.comment(file.getUri(), comment), Write.File.artifactOf(expectedFileUrl, artifactOfName, artifactOfHomepage), Write.File.licenseComments(expectedFileUrl, "Nice file license!"), Write.File.noticeText(file.getUri(), "NOTICE THIS!"), Write.File.contributors(file.getUri(), "Larry", "Curly", "Moe")); // Reload Resource fileResource = Read.lookupResourceByUri(dataset, expectedFileUrl).get(); file = new SpdxFile(fileResource); assertEquals(Sets.newHashSet(Checksum.sha256(mockSha256), Checksum.sha1(mockSha1)), file.getChecksums()); assertEquals(baseUrl + "#LicenseRef-el", file.rdfResource.getPropertyResourceValue(SpdxProperties.LICENSE_INFO_IN_FILE).getURI()); assertEquals(copyrightText, file.getCopyrightText().getValue().get()); assertEquals(comment, file.getComment().get()); assertEquals(Optional.of("Nice file license!"), file.getOptionalPropertyAsString(SpdxProperties.LICENSE_COMMENTS)); assertEquals(Optional.of("NOTICE THIS!"), file.getNoticeText()); assertEquals(Sets.newHashSet("Larry", "Curly", "Moe"), file.getContributors()); List<Resource> doapProjects = MiscUtils .toLinearStream(fileResource.listProperties(SpdxProperties.ARTIFACT_OF)).map(Statement::getObject) .map(RDFNode::asResource).collect(Collectors.toList()); Assert.assertEquals("Applying artifactOf update twice should produce two properties.", 2, doapProjects.size()); Set<String> expectedHomepages = Sets.newHashSet(null, artifactOfHomepage); for (Resource dp : doapProjects) { Assert.assertNotNull(dp); Assert.assertEquals(artifactOfName, dp.getProperty(SpdxProperties.DOAP_NAME).getString()); // Use a null value to represent the project with no homepage (which // in truth just won't have that property). String actualHomepage = dp.getProperty(SpdxProperties.DOAP_HOMEPAGE) != null ? dp.getProperty(SpdxProperties.DOAP_HOMEPAGE).getString() : null; Assert.assertTrue("Homepage has an unexpected value: " + actualHomepage, expectedHomepages.remove(actualHomepage)); Assert.assertEquals("Unexpected type for DOAP Project resource", "http://usefulinc.com/ns/doap#Project", dp.getProperty(SpdxProperties.RDF_TYPE).getObject().asResource().getURI()); } }
From source file:com.lazerycode.selenium.filedownloader.CheckFileHash.java
/** * Performs a expectedFileHash check on a File. * * @return/*w w w . j ava 2s.co m*/ * @throws IOException */ public boolean hasAValidHash() throws IOException { if (this.fileToCheck == null) throw new FileNotFoundException("File to check has not been set!"); if (this.expectedFileHash == null || this.typeOfOfHash == null) throw new NullPointerException("Hash details have not been set!"); String actualFileHash = ""; boolean isHashValid = false; switch (this.typeOfOfHash) { case MD5: actualFileHash = DigestUtils.md5Hex(new FileInputStream(this.fileToCheck)); if (this.expectedFileHash.equals(actualFileHash)) isHashValid = true; break; case SHA1: actualFileHash = DigestUtils.shaHex(new FileInputStream(this.fileToCheck)); if (this.expectedFileHash.equals(actualFileHash)) isHashValid = true; break; } // LOG.info("Filename = '" + this.fileToCheck.getName() + "'"); // LOG.info("Expected Hash = '" + this.expectedFileHash + "'"); //LOG.info("Actual Hash = '" + actualFileHash + "'"); return isHashValid; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.message.MessageIdGeneratorImpl.java
@Override public String generate(String clientId, String appId, String deviceId) { StringBuilder builder = new StringBuilder(); builder.append(Long.toString(getCurrentTimeMillis())); builder.append(clientId);/*from w ww . j av a 2s. c o m*/ builder.append(appId); builder.append(randomGenerator.nextLong()); if (deviceId != null) { builder.append(deviceId); } String generated; try { byte[] bytes = builder.toString().getBytes(MMXServerConstants.UTF8_ENCODING); generated = DigestUtils.md5Hex(bytes); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } return generated; }
From source file:com.google.sampling.experiential.server.migration.MigrationBackendServlet.java
@Override protected void doGet(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { log.info("MIGRATE BACKEND"); final String requestorEmail = getRequestorEmail(req); final String migrationJobName = HttpUtil.getParam(req, "migrationName"); final String useTaskQueue = HttpUtil.getParam(req, "queue"); final String cursor = HttpUtil.getParam(req, "cursor"); final String sTime = HttpUtil.getParam(req, "startTime"); final String eTime = HttpUtil.getParam(req, "endTime"); final String jobId = migrationJobName + "_" + DigestUtils.md5Hex(requestorEmail + Long.toString(System.currentTimeMillis())); log.info("In migrate backend for job: " + jobId); final ReportJobStatusManager statusMgr = new ReportJobStatusManager(); statusMgr.startReport(requestorEmail, jobId); final ClassLoader cl = getClass().getClassLoader(); final Thread thread2 = ThreadManager.createBackgroundThread(new Runnable() { @Override//ww w. j a v a2 s . c o m public void run() { log.info("MigrationBackend running"); Thread.currentThread().setContextClassLoader(cl); try { DateTime startTime = null; DateTime endTime = null; if (sTime != null && eTime != null) { startTime = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.sssZ").parseDateTime(sTime); endTime = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.sssZ").parseDateTime(eTime); } if (doMigration(migrationJobName, cursor, startTime, endTime)) { statusMgr.completeReport(requestorEmail, jobId, Constants.LOCATION_NA); } else { statusMgr.failReport(requestorEmail, jobId, "Check server logs for stacktrace"); } } catch (Throwable e) { final String fullStack = getStackTraceAsString(e); final String string = fullStack.length() > 700 ? fullStack.substring(0, 700) : fullStack; statusMgr.failReport(requestorEmail, jobId, e.getClass() + "." + e.getMessage() + "\n" + string); log.severe("Could not run migration job: " + e.getMessage()); log.severe("stacktrace: " + fullStack); } } }); thread2.start(); log.info("Leaving migration backend"); resp.setContentType("text/plain;charset=UTF-8"); resp.getWriter().println(jobId); }
From source file:com.dp2345.controller.admin.ProfileController.java
/** * //from w w w . j av a 2s . c om */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(String currentPassword, String password, String email, RedirectAttributes redirectAttributes) { if (!isValid(Admin.class, "email", email)) { return ERROR_VIEW; } Admin pAdmin = adminService.getCurrent(); if (StringUtils.isNotEmpty(currentPassword) && StringUtils.isNotEmpty(password)) { if (!isValid(Admin.class, "password", password)) { return ERROR_VIEW; } if (!StringUtils.equals(DigestUtils.md5Hex(currentPassword), pAdmin.getPassword())) { return ERROR_VIEW; } pAdmin.setPassword(DigestUtils.md5Hex(password)); } pAdmin.setEmail(email); adminService.update(pAdmin); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:edit.jhtml"; }
From source file:com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketBuildStatus.java
public BitbucketBuildStatus(String hash, String description, String state, String url, String key, String name) {/*from w w w .ja v a 2 s . com*/ this.hash = hash; this.description = description; this.state = state; this.url = url; this.key = DigestUtils.md5Hex(key); this.name = name; }
From source file:com.payu.sdk.utils.SignUtil.java
/** * Generates the signature based on information received. * * @param algorithm The algorithm used to generate the sign. * @param key The message key.//from www .j a v a 2s.c om * @param message The message to create the signature. * @return the signature created. */ public static String createSignature(final String algorithm, final String key, final String message) { final String str = key + SIGNATURE_SEPARATOR + message; String signature = null; final String localAlgorithm = StringUtils.isBlank(algorithm) ? DEFAULT_ALGORITHM : algorithm; if (Constants.ALGORITHM_MD5.equalsIgnoreCase(localAlgorithm)) { signature = DigestUtils.md5Hex(str); } else if (Constants.ALGORITHM_SHA.equalsIgnoreCase(localAlgorithm)) { signature = DigestUtils.shaHex(str); } else if (Constants.ALGORITHM_SHA_256.equalsIgnoreCase(localAlgorithm)) { signature = DigestUtils.sha256Hex(str); } else { throw new IllegalArgumentException("Could not create signature. Invalid algorithm " + localAlgorithm); } return signature; }