List of usage examples for org.apache.commons.codec.digest DigestUtils md5Hex
public static String md5Hex(String data)
From source file:com.chiorichan.util.StringUtil.java
public static String md5(String str) { return DigestUtils.md5Hex(str); }
From source file:com.googlecode.fascinator.storage.filesystem.FileSystemStorage.java
private void setVariable(JsonSimpleConfig config) { email = config.getString(DEFAULT_EMAIL, "email"); String home = config.getString(DEFAULT_HOME_DIR, "storage", "file-system", "home"); homeDir = new File(home, DigestUtils.md5Hex(email)); if (!homeDir.exists()) { homeDir.mkdirs();/* w ww . ja v a 2s . com*/ } }
From source file:com.google.sampling.experiential.server.reports.ReportsBackendServlet.java
public String getJobId(ReportRequest repRequest) { final String jobId = repRequest.getReportId() + "_" + DigestUtils.md5Hex(repRequest.getWho() + Long.toString(System.currentTimeMillis())); log.info("In report backend for job: " + jobId); return jobId; }
From source file:net.siegmar.japtproxy.JaptProxyServlet.java
/** * Check the requested data and forward the request to internal sender. * * @param req the HttpServletRequest object * @param res the HttpServletResponse object * @throws ServletException {@inheritDoc} * @throws IOException {@inheritDoc} */// w w w. ja v a 2 s. c o m @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { res.setBufferSize(Util.DEFAULT_BUFFER_SIZE); MDC.put("REQUEST_ID", DigestUtils.md5Hex(Long.toString(System.currentTimeMillis()))); LOG.debug("Incoming request from IP '{}', " + "User-Agent '{}'", req.getRemoteAddr(), req.getHeader(HttpHeaderConstants.USER_AGENT)); if (LOG.isDebugEnabled()) { logHeader(req); } try { japtProxy.handleRequest(req, res); } catch (final InvalidRequestException e) { LOG.warn(e.getMessage()); res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request"); return; } catch (final UnknownBackendException e) { LOG.info(e.getMessage()); res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown backend"); return; } catch (final ResourceUnavailableException e) { LOG.debug(e.getMessage(), e); res.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (final HandlingException e) { LOG.error("HandlingException", e); res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } finally { MDC.clear(); } res.flushBuffer(); }
From source file:cascading.util.Util.java
/** * This method creates a globally unique HEX value seeded by the given string. * * @param seed/* www . j a v a 2s . c o m*/ * @return a String */ public static String createUniqueID(String seed) { String base = String.format("%s%d%.10f", seed, System.currentTimeMillis(), Math.random()); return DigestUtils.md5Hex(base); }
From source file:com.eriwen.gradle.Digest.java
private String digest(final File file, final DigestAlgorithm algorithm) throws IOException { final byte[] contentBytes = Files.readAllBytes(file.toPath()); final String checksum; switch (algorithm) { case MD5://from w w w.j ava 2 s. c o m checksum = DigestUtils.md5Hex(contentBytes); break; case SHA1: checksum = DigestUtils.sha1Hex(contentBytes); break; case SHA256: checksum = DigestUtils.sha256Hex(contentBytes); break; case SHA512: checksum = DigestUtils.sha512Hex(contentBytes); break; default: throw new IllegalArgumentException("Cannot use unknown digest algorithm " + algorithm.toString()); } return checksum; }
From source file:com.hyeb.back.authenticate.AuthenticationRealm.java
/** * ???/*from w w w .j ava 2 s .c o m*/ * * @param token * * @return ?? */ @Override protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) { SysUserService sysUserService = (SysUserService) SpringUtils.getBean("sysUserServiceImpl"); AuthenticationToken authenticationToken = (AuthenticationToken) token; String username = authenticationToken.getUsername(); String password = new String(authenticationToken.getPassword()); String captchaId = authenticationToken.getCaptchaId(); String captcha = authenticationToken.getCaptcha(); String ip = authenticationToken.getHost(); if (!captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) { throw new UnsupportedTokenException(); } if (username != null && password != null) { SysUser sysUser = sysUserService.findByUsername(username); if (sysUser == null) { throw new UnknownAccountException(); } if (!sysUser.getIsEnabled()) { throw new DisabledAccountException(); } Setting setting = SettingUtils.get(); if (sysUser.getIsLocked()) { if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) { int loginFailureLockTime = setting.getAccountLockTime(); if (loginFailureLockTime == 0) { throw new LockedAccountException(); } Date lockedDate = sysUser.getLockedDate(); Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime); if (new Date().after(unlockDate)) { sysUser.setLoginFailureCount(0); sysUser.setIsLocked(false); sysUser.setLockedDate(null); sysUserService.update(sysUser); } else { throw new LockedAccountException(); } } else { sysUser.setLoginFailureCount(0); sysUser.setIsLocked(false); sysUser.setLockedDate(null); sysUserService.update(sysUser); } } if (!DigestUtils.md5Hex(password).equals(sysUser.getPassword())) { int loginFailureCount = sysUser.getLoginFailureCount() + 1; if (loginFailureCount >= setting.getAccountLockCount()) { sysUser.setIsLocked(true); sysUser.setLockedDate(new Date()); } sysUser.setLoginFailureCount(loginFailureCount); sysUserService.update(sysUser); throw new IncorrectCredentialsException(); } sysUser.setLoginIp(ip); sysUser.setLoginDate(new Date()); sysUser.setLoginFailureCount(0); sysUserService.update(sysUser); SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo( new Principal(sysUser.getId(), username), password, getName()); return simpleAuthenticationInfo; } throw new UnknownAccountException(); }
From source file:com.seajas.search.utilities.spring.security.CrowdSSOAuthenticationProvider.java
/** * Retrieve a User from the given Crowd UserDetails. * //from w w w. j a v a 2 s .c o m * @param details * @return User */ private User getUserFromDetails(final CrowdUserDetails details) { User user; // Generate a random password since we can't retrieve the one from Crowd String randomPassword = DigestUtils.md5Hex(UUID.randomUUID().toString()); if (details.getUsername().equals(USERNAME_ADMIN)) user = new User(-1, details.getUsername(), randomPassword, details.getFullName(), true); else user = userDAO.findUserByUsername(details.getUsername()); if (user == null) { logger.info("Unknown Crowd user '" + details.getUsername() + "' successfully authenticated. Adding to internal database."); if (userDAO.addUser(details.getUsername(), randomPassword, details.getFullName())) user = userDAO.findUserByUsername(details.getUsername()); } return user; }
From source file:com.endgame.binarypig.util.BuildSequenceFileFromArchive.java
public void load(FileSystem fs, Configuration conf, File archive, Path outputDir) throws Exception { Text key = new Text(); BytesWritable val = new BytesWritable(); SequenceFile.Writer writer = null; ArchiveInputStream archiveInputStream = null; try {/* w w w . ja va 2 s.c om*/ Path sequenceName = new Path(outputDir, archive.getName() + ".seq"); System.out.println("Writing to " + sequenceName); writer = SequenceFile.createWriter(fs, conf, sequenceName, Text.class, BytesWritable.class, CompressionType.RECORD); String lowerName = archive.toString().toLowerCase(); if (lowerName.endsWith(".tar.gz") || lowerName.endsWith(".tgz")) { archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream("tar", new GZIPInputStream(new FileInputStream(archive))); } else if (lowerName.endsWith(".tar.bz") || lowerName.endsWith(".tar.bz2") || lowerName.endsWith(".tbz")) { FileInputStream is = new FileInputStream(archive); is.read(); // read 'B' is.read(); // read 'Z' archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream("tar", new CBZip2InputStream(is)); } else if (lowerName.endsWith(".tar")) { archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream("tar", new FileInputStream(archive)); } else if (lowerName.endsWith(".zip")) { archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream("zip", new FileInputStream(archive)); } else { throw new RuntimeException("Can't handle archive format for: " + archive); } ArchiveEntry entry = null; while ((entry = archiveInputStream.getNextEntry()) != null) { if (!entry.isDirectory()) { try { byte[] outputFile = IOUtils.toByteArray(archiveInputStream); val.set(outputFile, 0, outputFile.length); key.set(DigestUtils.md5Hex(outputFile)); writer.append(key, val); } catch (IOException e) { System.err.println("Warning: archive may be truncated: " + archive); // Truncated Archive break; } } } } finally { archiveInputStream.close(); writer.close(); } }
From source file:com.siberhus.ngai.QTO.java
public String getHashString() { String s = queryBuffer.toString() + "|" + StringUtils.join(getParameterList(), ','); return DigestUtils.md5Hex(s); }