List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:io.hops.hopsworks.dela.DelaSetupWorker.java
private void setup(Timer timer) { Optional<String> masterPswd = settings.getHopsSiteClusterPswd(); if (!masterPswd.isPresent()) { //TODO Alex - use the registration pswd hash once the admin UI is ready String pswd = DigestUtils.sha256Hex(settings.getHopsSiteClusterPswdAux()); settings.setHopsSiteClusterPswd(pswd); masterPswd = settings.getHopsSiteClusterPswd(); }/*from www .java2 s. com*/ Optional<String> clusterName = settings.getHopsSiteClusterName(); if (clusterName.isPresent()) { Optional<Triplet<KeyStore, KeyStore, String>> keystoreAux = CertificateHelper.loadKeystoreFromDB( masterPswd.get(), clusterName.get(), clusterCertFacade, certificatesMgmService); if (keystoreAux.isPresent()) { setupComplete(keystoreAux.get(), timer); return; } } Optional<Triplet<KeyStore, KeyStore, String>> keystoreAux = CertificateHelper .loadKeystoreFromFile(masterPswd.get(), settings, clusterCertFacade, certificatesMgmService); if (keystoreAux.isPresent()) { setupComplete(keystoreAux.get(), timer); } else { LOGGER.log(Level.WARNING, "{0} - dela setup not ready - certificates not ready", new Object[] { DelaException.Source.HOPS_SITE }); } }
From source file:net.solarnetwork.central.dras.dao.ibatis.test.IbatisUserDaoTest.java
@Test public void insertUserWithMultipleContactInfo() { UserContact ct1 = new UserContact(UserContact.ContactKind.VOICE, "555-555-5555", 1); UserContact ct2 = new UserContact(UserContact.ContactKind.FAX, "666-666-6666", 2); UserContact ct3 = new UserContact(UserContact.ContactKind.PAGER, "777-777-7777", null); List<UserContact> contacts = new ArrayList<UserContact>(1); contacts.add(ct1);//from w w w.j a v a2 s .c o m contacts.add(ct2); contacts.add(ct3); 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.solarnetwork.node.backup.FileBackupResourceProvider.java
private void moveTemporaryResourceFile(File tempFile, File outputFile) throws IOException { if (outputFile.exists()) { // if the file has not changed, just delete tmp file InputStream outputFileInputStream = null; InputStream tmpOutputFileInputStream = null; try {/*from w w w . ja v a2 s . c o m*/ outputFileInputStream = new FileInputStream(outputFile); tmpOutputFileInputStream = new FileInputStream(tempFile); String outputFileHash = DigestUtils.sha256Hex(outputFileInputStream); String tmpOutputFileHash = DigestUtils.sha256Hex(tmpOutputFileInputStream); if (tmpOutputFileHash.equals(outputFileHash)) { // file unchanged, so just delete tmp file tempFile.delete(); } else { log.debug("{} content updated", outputFile); outputFile.delete(); tempFile.renameTo(outputFile); } } finally { if (outputFileInputStream != null) { try { outputFileInputStream.close(); } catch (IOException e) { // ignore; } } if (tmpOutputFileInputStream != null) { try { tmpOutputFileInputStream.close(); } catch (IOException e) { // ignore } } } } else { // rename temp file tempFile.renameTo(outputFile); } }
From source file:io.lavagna.service.UserRepository.java
@Transactional(readOnly = false) public void deleteRememberMeToken(int userId, String token) { queries.deleteToken(DigestUtils.sha256Hex(token), userId); }
From source file:it.greenvulcano.gvesb.iam.service.internal.GVUsersManager.java
@Override public User resetUserPassword(String username, String defaultPassword) throws UserNotFoundException, InvalidPasswordException, UnverifiableUserException { User user = userRepository.get(username).orElseThrow(() -> new UserNotFoundException(username)); if (!Objects.requireNonNull(defaultPassword, "A default password is required") .matches(User.PASSWORD_PATTERN)) throw new InvalidPasswordException(defaultPassword); if (!user.getPassword().isPresent()) throw new UnverifiableUserException(username); user.setPassword(DigestUtils.sha256Hex(defaultPassword)); user.setPasswordTime(new Date()); user.setExpired(true);/*w w w .j a v a 2s .c om*/ userRepository.add(user); return user; }
From source file:be.fedict.eid.tsl.tool.TslInternalFrame.java
private void updateView() { this.signerCertificate = this.trustServiceList.verifySignature(); if (null != this.signerCertificate) { this.signer.setText(this.signerCertificate.getSubjectX500Principal().toString()); byte[] encodedPublicKey = this.signerCertificate.getPublicKey().getEncoded(); this.signerSha1Fingerprint.setText(DigestUtils.shaHex(encodedPublicKey)); this.signerSha256Fingerprint.setText(DigestUtils.sha256Hex(encodedPublicKey)); this.saveSignerCertificateButton.setEnabled(true); } else {// w ww . j ava2 s. c o m this.signer.setText("[TSL is not signed]"); this.signerSha1Fingerprint.setText(""); this.signerSha256Fingerprint.setText(""); this.saveSignerCertificateButton.setEnabled(false); } }
From source file:io.lavagna.service.UserRepository.java
public boolean rememberMeTokenExists(int userId, String token) { String hashedToken = DigestUtils.sha256Hex(token); return queries.tokenExists(hashedToken, userId).equals(1); }
From source file:com.mweagle.tereus.commands.UpdateCommand.java
protected void updateStack(UpdateInput updateInput, String transformedTemplate, String stackTargetName) throws UnsupportedEncodingException { if (updateInput.dryRun) { updateInput.logger.info("Dry run requested (-n/--noop). Stack update bypassed."); } else {//from w ww .j a v a 2s . c om // Fetch the stack parameters final DescribeStacksRequest stackRequest = new DescribeStacksRequest().withStackName(stackTargetName); final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient( updateInput.awsCredentials); awsClient.setRegion(updateInput.awsRegion); final DescribeStacksResult result = awsClient.describeStacks(stackRequest); final Stack existantStack = result.getStacks().get(0); final Optional<Parameter> s3Bucket = findNamedParameter(CONSTANTS.PARAMETER_NAMES.S3_BUCKET_NAME, existantStack.getParameters()); Preconditions.checkArgument(s3Bucket.isPresent(), "Failed to determine S3 BucketName from existant template via parameter name: " + CONSTANTS.PARAMETER_NAMES.S3_BUCKET_NAME); // Super, now put the new content to S3, update the parameter list // to include the new URL, and submit the updated stack. final byte[] templateBytes = transformedTemplate.getBytes("UTF-8"); final InputStream is = new ByteArrayInputStream(templateBytes); final String templateDigest = DigestUtils.sha256Hex(templateBytes); final String keyName = String.format("%s-tereus.cf.template", templateDigest); try (S3Resource resource = new S3Resource(s3Bucket.get().getParameterValue(), keyName, is, Optional.of(Long.valueOf(templateBytes.length)))) { // Upload the template resource.upload(); // Go ahead and create the stack. final UpdateStackRequest request = new UpdateStackRequest().withStackName(stackTargetName); request.setTemplateURL(resource.getResourceURL().get()); request.setParameters(existantStack.getParameters()); request.setCapabilities(Arrays.asList("CAPABILITY_IAM")); updateInput.logger.debug("Updating stack: {}", stackTargetName); final Optional<DescribeStacksResult> updateResult = new CloudFormation().updateStack(request, updateInput.awsRegion, updateInput.logger); // If everything worked out, then release the template // URL s.t. subsequent ASG instantiated instances have access // to the template content if (updateResult.isPresent()) { updateInput.logger.info("Stack successfully updated"); updateInput.logger.info(updateResult.get().toString()); resource.setReleased(true); } } } }
From source file:it.greenvulcano.script.impl.ScriptExecutorImpl.java
/** * Initialize the instance.//from w ww . j a v a 2 s.c om * * @param lang * script engine language * @param script * the script to configure; if null the script must be passes in the execute method; overridden by 'file' * @param file * if not null, defines the script file to read * @param bcName * defines the BaseContext to be used to enrich the script; * if null is used the default context for the given language, if defined * @throws GVScriptException */ public void init(String lang, String script, String file, String bcName) throws GVScriptException { try { this.lang = lang; if ((file != null) && !"".equals(file)) { this.script = cache.getScript(file); } else { this.script = script; if ((this.script == null) || "".equals(this.script)) { externalScript = true; } } if (!externalScript && ((this.script == null) || "".equals(this.script))) { throw new GVScriptException("Empty configured script!"); } ScriptEngine engine = getScriptEngine(lang); if (engine == null) { throw new GVScriptException("ScriptEngine[" + this.lang + "] not found!"); } bindings = engine.createBindings(); String baseContext = BaseContextManager.instance().getBaseContextScript(lang, bcName); if (baseContext != null) { this.script = baseContext + "\n\n" + (this.script != null ? this.script : ""); if (externalScript) { engine.eval(this.script, bindings); } } else if (bcName != null) { throw new GVScriptException("BaseContext[" + this.lang + "/" + bcName + "] not found!"); } if (engine instanceof Compilable && PropertiesHandler.isExpanded(script)) { String scriptKey = DigestUtils.sha256Hex(script); Optional<CompiledScript> cachedCompiledScript = cache.getCompiledScript(scriptKey); if (cachedCompiledScript.isPresent()) { compScript = cachedCompiledScript.get(); } else { logger.debug("Static script[" + lang + "], can be compiled for performance"); compScript = ((Compilable) engine).compile(script); cache.putCompiledScript(scriptKey, compScript); } } initialized = true; } catch (GVScriptException exc) { logger.error("Error initializing ScriptExecutorImpl", exc); throw exc; } catch (Exception exc) { logger.error("Error initializing ScriptExecutorImpl", exc); throw new GVScriptException("Error initializing ScriptExecutorImpl", exc); } }
From source file:net.solarnetwork.central.dras.biz.dao.DaoUserBiz.java
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public User storeUser(User template, Set<String> roles, Set<Long> programs) { User entity;/* w w w.jav a 2 s. c o m*/ if (template.getId() != null) { entity = userDao.get(template.getId()); } else { entity = new User(); } boolean changedPassword = false; if (entity.getPassword() != null && template.getPassword() != null) { String digest = DigestUtils.sha256Hex(template.getPassword()); if (digest != entity.getPassword()) { changedPassword = true; } } else if (template.getPassword() != null) { // providing a password when wasn't set before... must digest changedPassword = true; } ClassUtils.copyBeanProperties(template, entity, null); if (entity.getEnabled() == null) { entity.setEnabled(Boolean.TRUE); } if (changedPassword) { entity.setPassword(DigestUtils.sha256Hex(entity.getPassword())); } Long newUserId = userDao.store(entity); userDao.assignUserRoles(newUserId, roles); if (programs != null) { Effective eff = createEffective(null); boolean updated = false; for (Long programId : programs) { Set<Member> members = programDao.getUserMembers(programId, null); Set<Long> newMembers = new HashSet<Long>(members.size() + 1); for (Member m : members) { newMembers.add(m.getId()); } if (!newMembers.contains(newUserId)) { newMembers.add(newUserId); programDao.assignUserMembers(programId, newMembers, eff.getId()); updated = true; } } if (!updated) { // we don't need that Effective effectiveDao.delete(eff); } } return userDao.get(newUserId); }