List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * Create Folder Form Workflow./* ww w .jav a 2 s.c o m*/ * @param user {@link User} * @param folder {@link UUID} * @param parentUUID {@link UUID} * @param uuid {@link UUID} * @return {@link FolderForm} */ private FolderForm createClientWorkflow(final User user, final UUID folder, final UUID parentUUID, final UUID uuid) { String sha256hash = DigestUtils.sha256Hex(folder + " " + uuid); FolderForm w = new FolderForm(); w.setType(ClientFormType.WORKFLOW); w.setFolderid(folder); w.setData(JSON); w.setSha1hash("CCC"); w.setUUID(uuid); w.setParentUUID(parentUUID); w.setAssetid(UUID.randomUUID()); w.setStatus(FolderFormStatus.ACTIVE); w.setInsertedDate(new Date()); w.setUpdatedDate(new Date()); this.folderDao.saveForm(user, w, sha256hash); return w; }
From source file:it.greenvulcano.gvesb.gviamx.service.internal.EmailChangeManager.java
public EmailChangeRequest retrieveEmailChangeRequest(String email, String token) { EmailChangeRequest request = repository.get(email.toLowerCase(), EmailChangeRequest.class) .orElseThrow(() -> new IllegalArgumentException("No password reset request found for this email")); if (DigestUtils.sha256Hex(token).equals(request.getToken())) { if (System.currentTimeMillis() > request.getIssueTime().getTime() + request.getExpireTime()) { repository.remove(request);/*from www . jav a 2s . c om*/ throw new SecurityException("No password reset request found for this email"); } return request; } else { throw new SecurityException("Token missmatch"); } }
From source file:com.zimbra.cs.account.oauth.utils.OAuthServiceProvider.java
/** * Generate request token and secret for a consumer. * * @throws OAuthException/*from w ww. jav a2 s . c o m*/ */ public static synchronized void generateRequestToken(OAuthAccessor accessor) throws OAuthException, ServiceException { String consumer_key = (String) accessor.consumer.getProperty("key"); String token_data = consumer_key + System.nanoTime(); String token = DigestUtils.sha256Hex(token_data); String secret_data = consumer_key + System.nanoTime() + token; String secret = DigestUtils.sha256Hex(secret_data); accessor.requestToken = token; accessor.tokenSecret = secret; accessor.accessToken = null; // add to Memcache OAuthTokenCache.put(accessor, OAuthTokenCache.REQUEST_TOKEN_TYPE); }
From source file:io.hawkcd.services.UserService.java
@Override @Authorization(scope = PermissionScope.SERVER, type = PermissionType.ADMIN) public ServiceResult changeUserPassword(UserDto user, String newPassword, String oldPassword) { String hashedPassword = DigestUtils.sha256Hex(oldPassword); ServiceResult result = this.getByEmailAndPassword(user.getUsername(), hashedPassword); if (result.getNotificationType() == NotificationType.ERROR) { return result; }// w ww .j a v a2s. c om User userToUpdate = (User) result.getEntity(); String hashedPasswordToUpdateUser = DigestUtils.sha256Hex(newPassword); userToUpdate.setPassword(hashedPasswordToUpdateUser); return this.update(userToUpdate); }
From source file:io.zipi.common.auth.AuthTokenUtil.java
/** * Generates a signature for the given token. * @param token/*from w w w. j a va2s . c o m*/ */ private static String generateSignature(AuthToken token) { StringBuilder builder = new StringBuilder(); builder.append(token.getPrincipal()); builder.append("||"); //$NON-NLS-1$ builder.append(token.getExpiresOn().getTime()); builder.append("||"); //$NON-NLS-1$ builder.append(token.getIssuedOn().getTime()); builder.append("||"); //$NON-NLS-1$ TreeSet<String> roles = new TreeSet<>(token.getRoles()); boolean first = true; for (String role : roles) { if (first) { first = false; } else { builder.append(","); //$NON-NLS-1$ } builder.append(role); } builder.append("||"); //$NON-NLS-1$ builder.append(sharedSecretSource.getSharedSecret()); return DigestUtils.sha256Hex(builder.toString()); }
From source file:com.squid.kraken.v4.core.analysis.engine.processor.AnalysisSmartCacheSignature.java
/** * @param analysis /*w w w .jav a 2 s . c om*/ * @return */ protected String computeAxesSignature(Universe universe) { // // add the customer ID / project ID StringBuilder signature = new StringBuilder(); signature.append(universe.getProject().getId().toUUID()); // // add the measure group domain Domain root = measures.getRoot(); signature.append("##").append(root.getOid()); // // add the axes signature.append("#"); ArrayList<GroupByAxis> ordered = new ArrayList<>(analysis.getGrouping()); // generalize if (generalize != null) { ordered.add(new GroupByAxis(generalize)); } Collections.sort(ordered, new Comparator<GroupByAxis>() { @Override public int compare(GroupByAxis o1, GroupByAxis o2) { return o1.getAxis().getId().compareTo(o2.getAxis().getId()); } }); axes = new HashSet<>(); for (GroupByAxis axis : ordered) { String hash = DigestUtils.sha256Hex(axis.getAxis().getId()); signature.append("#").append(hash); axes.add(axis.getAxis()); } // // add the conditions ArrayList<DomainSelection> domains = new ArrayList<>(analysis.getSelection().get()); Collections.sort(domains, new Comparator<DomainSelection>() { @Override public int compare(DomainSelection o1, DomainSelection o2) { return o1.getDomain().getOid().compareTo(o2.getDomain().getOid()); } }); for (DomainSelection ds : domains) { // add domain signature.append("#"); String domainId = ds.getDomain().getOid(); ArrayList<ExpressionInput> inputs = new ArrayList<>(ds.getConditions()); Collections.sort(inputs, new Comparator<ExpressionInput>() { @Override public int compare(ExpressionInput o1, ExpressionInput o2) { return o1.getInput().compareTo(o2.getInput()); } }); for (ExpressionInput input : inputs) { // hash the expression input String normalized = input.getExpression().prettyPrint(); String hash = DigestUtils.sha256Hex(domainId + "!" + normalized); signature.append("#").append(hash); } } return signature.toString(); }
From source file:it.greenvulcano.gvesb.gviamx.service.internal.SignUpManager.java
public void createSignUpRequest(String email, byte[] request) throws UserExistException { if (email == null || !email.matches(UserActionRequest.EMAIL_PATTERN)) { throw new IllegalArgumentException("Invalid email: " + email); }//w w w .j av a 2 s. c om try { usersManager.getUser(email.toLowerCase()); throw new UserExistException(email); } catch (UserNotFoundException e) { if (usersManager.searchUsers(SearchCriteria.builder().byEmail(email.toLowerCase()).limitedTo(1).build()) .getTotalCount() > 0) { throw new UserExistException(email); } } SignUpRequest signUpRequest = signupRepository.get(email.toLowerCase(), SignUpRequest.class) .orElseGet(SignUpRequest::new); signUpRequest.setEmail(email.toLowerCase()); signUpRequest.setIssueTime(new Date()); signUpRequest.setExpireTime(expireTime); signUpRequest.setRequest(request); signUpRequest.setNotificationStatus(NotificationStatus.PENDING); byte[] token = new byte[4]; secureRandom.nextBytes(token); String clearTextToken = String.format(Locale.US, "%02x%02x%02x%02x", IntStream.range(0, token.length).mapToObj(i -> Byte.valueOf(token[i])).toArray()); signUpRequest.setToken(DigestUtils.sha256Hex(clearTextToken)); signupRepository.add(signUpRequest); signUpRequest.setClearToken(clearTextToken); notificationServices.stream() .map(n -> new NotificationManager.NotificationTask(n, signUpRequest, signupRepository, "signup")) .forEach(executor::submit); }
From source file:net.solarnetwork.central.dras.dao.ibatis.test.IbatisUserDaoTest.java
@Test public void insertUserWithSingleContactInfo() { UserContact ct1 = new UserContact(UserContact.ContactKind.VOICE, "555-555-5555", 1); List<UserContact> contacts = new ArrayList<UserContact>(1); contacts.add(ct1);//from ww w .j a v a 2s . co m User user = new User(); user.setAddress(new String[] { "One", "Two" }); user.setContactInfo(contacts); user.setDisplayName("Test Uesr"); user.setEnabled(Boolean.TRUE); user.setPassword(DigestUtils.sha256Hex("password")); user.setUsername("foouser"); user.setVendor("vendor"); logger.debug("Inserting new User: " + user); Long id = userDao.store(user); assertNotNull(id); User entity = userDao.get(id); validateUser(user, entity); lastUserId = id; }
From source file:net.lyonlancer5.mcmp.karasu.util.ModFileUtils.java
public void doHashCheck(File jarFile) { if (!hasInitialized) initialize();// w ww.j av a 2s. com if (doHashCheck) { LOGGER.info("Mod source file located at " + jarFile.getPath()); if (jarFile.isFile() && !jarFile.getName().endsWith("bin")) { try { List<String> lines = IOUtils.readLines(new FileInputStream(remoteHashes)); for (String s : lines) { //version:jarName:md5:sha1:sha256:sha512 String[] params = s.split(":"); if (params[0].equals(Constants.VERSION)) { if (!params[1].equals(jarFile.getName())) LOGGER.warn("JAR filename has been changed!"); FileInputStream fis = new FileInputStream(jarFile); String var0 = DigestUtils.md5Hex(fis); String var1 = DigestUtils.sha1Hex(fis); String var2 = DigestUtils.sha256Hex(fis); String var3 = DigestUtils.sha512Hex(fis); assert ((params[2].equals(var0)) && (params[3].equals(var1)) && (params[4].equals(var2)) && (params[5].equals(var3))) : new ValidationError( "Mod integrity check FAILED: mismatched hashes (Has the mod file been edited?)"); LOGGER.info("Validation success!"); return; } } } catch (IOException e) { throw new ValidationError("Validation FAILED - I/O error", e); } } else { isDevEnv = true; LOGGER.warn( "The mod is currently running on a development environment - Integrity checking will not proceed"); } } else { LOGGER.warn("#########################################################################"); LOGGER.warn("WARNING: Integrity checks have been DISABLED!"); LOGGER.warn("Hash checks will not be performed - this mod may not run as intended"); LOGGER.warn("Any changes made to this mod will not be validated, whether it came from"); LOGGER.warn("a legitimate source or an attempt to insert code into this modification"); LOGGER.warn("#########################################################################"); } }
From source file:io.hops.memcache.PathMemcache.java
private String getKey(String path) { return keyPrefix + DigestUtils.sha256Hex(path); }