List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:io.hops.hopsworks.common.dao.jupyter.JupyterSettingsFacade.java
public JupyterSettings findByProjectUser(int projectId, String email) { JupyterSettingsPK pk = new JupyterSettingsPK(projectId, email); JupyterSettings js = null;/*from w w w . ja v a 2s . c o m*/ js = em.find(JupyterSettings.class, pk); if (js == null) { String secret = DigestUtils.sha256Hex(Integer.toString(ThreadLocalRandom.current().nextInt())); js = new JupyterSettings(pk); js.setSecret(secret); js.setMode("sparkDynamic"); persist(js); } return js; }
From source file:io.hops.hopsworks.common.dao.rstudio.RStudioSettingsFacade.java
public RStudioSettings findByProjectUser(int projectId, String email) { RStudioSettingsPK pk = new RStudioSettingsPK(projectId, email); RStudioSettings js = null;/* w ww . j ava2s. com*/ js = em.find(RStudioSettings.class, pk); if (js == null) { String secret = DigestUtils.sha256Hex(Integer.toString(ThreadLocalRandom.current().nextInt())); js = new RStudioSettings(pk); js.setSecret(secret); js.setMode("sparkDynamic"); persist(js); } return js; }
From source file:eu.cloud4soa.soa.jaxrs.test.ApplicationDeploymentTest.java
public void deployApplication() throws FileNotFoundException { // final String BASE_URI = "http://localhost:8080/frontend-dashboard-0.0.1-SNAPSHOT/services/REST/ApplicationDeploymentRS/deployApplication"; final String BASE_URI = "http://localhost:8080/cloud4soa.soa/services/REST/ApplicationDeploymentRS/deployApplication"; WebClient client = WebClient.create(BASE_URI); client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN); // ContentDisposition cd = new ContentDisposition("attachment;filename=image.jpg"); // Attachment att = new Attachment("root", imageInputStream, cd); // ApplicationDeployment applicationDeploymentRS = (ApplicationDeployment) JAXRSClientFactory.create("http://localhost:8080/books", ApplicationDeployment.class); // WebClient.client(applicationDeploymentRS).type("multipart/mixed"); URL fileURL = this.getClass().getClassLoader().getResource("SimpleWar.war"); if (fileURL == null) throw new FileNotFoundException("SimpleWar.war"); ByteArrayOutputStream bas = new ByteArrayOutputStream(); File file = new File(fileURL.getPath()); file.length();//w w w . java2s.com FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); //Calculate digest from InputStream // InputStream tempIs = new FileInputStream(file); String tempFileDigest = null; try { FileInputStream tempFis = new FileInputStream(file); tempFileDigest = DigestUtils.sha256Hex(tempFis); } catch (IOException ex) { Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex); } // JSONObject applicationInstanceJsonObj=new JSONObject(); // try { // applicationInstanceJsonObj.put("acronym","App1"); // applicationInstanceJsonObj.put("applicationcode","001"); // applicationInstanceJsonObj.put("programminglanguage","Java"); // } catch (JSONException ex) { // ex.printStackTrace(); // } // // System.out.println(applicationInstanceJsonObj); JSONObject applicationInstanceJsonObj = new JSONObject(); try { applicationInstanceJsonObj.put("acronym", "SimpleWar"); applicationInstanceJsonObj.put("archiveFileName", "app"); applicationInstanceJsonObj.put("archiveExtensionName", ".war"); applicationInstanceJsonObj.put("digest", tempFileDigest); applicationInstanceJsonObj.put("sizeQuantity", file.length()); applicationInstanceJsonObj.put("version", "2"); // applicationInstanceJsonObj.put("",""); } catch (JSONException ex) { Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(applicationInstanceJsonObj); JSONObject paaSInstanceJsonObj = new JSONObject(); try { // paaSInstanceJsonObj.put("providerTitle","CloudBees"); paaSInstanceJsonObj.put("providerTitle", "Beanstalk"); } catch (JSONException ex) { Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(paaSInstanceJsonObj); ProviderFactory.getSharedInstance().registerUserProvider(new JSONProvider()); // POST the request // Response response = applicationDeploymentRS.deployApplication(dis, applicationInstanceJsonObj, paaSInstanceJsonObj); Attachment att1 = new Attachment("applicationInstance", "application/json", applicationInstanceJsonObj.toString()); Attachment att2 = new Attachment("paaSInstance", "application/json", paaSInstanceJsonObj.toString()); Attachment att3 = new Attachment("applicationArchive", "application/octet-stream", dis); List<Attachment> listAttch = new LinkedList<Attachment>(); listAttch.add(att1); listAttch.add(att2); listAttch.add(att3); Response response = client.post(new MultipartBody(listAttch)); if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.ACCEPTED) try { System.out.println( "Response Status : " + IOUtils.readStringFromStream((InputStream) response.getEntity())); } catch (IOException ex) { Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex); } try { fis.close(); bis.close(); dis.close(); } catch (IOException ex) { Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:it.scoppelletti.programmerpower.security.DefaultUserManager.java
@Transactional(propagation = Propagation.SUPPORTS) public String digestPassword(SecureString value) { return DigestUtils.sha256Hex(value.getBytes()); }
From source file:at.stefanproell.ResultSetVerification.ResultSetVerificationAPI.java
/** * Calculate SHA1 hash from input/*from w w w .jav a 2s . co m*/ * * @param inputString * @return * @throws NoSuchAlgorithmException */ public String calculateSHA256HashFromString(String inputString) { try { this.crypto.update(inputString.getBytes("utf8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String hash = DigestUtils.sha256Hex(this.crypto.digest()); return hash; }
From source file:it.greenvulcano.gvesb.iam.service.internal.GVUsersManager.java
@Override public User createUser(String username, String password) throws InvalidUsernameException, InvalidPasswordException, UserExistException { if (!username.matches(User.USERNAME_PATTERN)) throwException(new InvalidUsernameException(username)); if (!password.matches(User.PASSWORD_PATTERN)) throwException(new InvalidPasswordException(password)); UserJPA user = new UserJPA(); user.setUsername(username);/*from ww w . j a v a2 s .c o m*/ user.setPassword(DigestUtils.sha256Hex(password)); user.setPasswordTime(new Date()); user.setEnabled(true); try { userRepository.add(user); } catch (org.hibernate.StaleObjectStateException | ConstraintViolationException constraintViolationException) { throwException(new UserExistException(username)); } return userRepository.get(username).get(); }
From source file:domen.Korisnik.java
public void setHashPassword(String pass) { this.password = DigestUtils.sha256Hex(password); }
From source file:co.cask.hydrator.plugin.Hasher.java
@Override public void transform(StructuredRecord in, Emitter<StructuredRecord> emitter) throws Exception { StructuredRecord.Builder builder = StructuredRecord.builder(in.getSchema()); List<Schema.Field> fields = in.getSchema().getFields(); for (Schema.Field field : fields) { String name = field.getName(); if (fieldSet.contains(name) && field.getSchema().getType() == Schema.Type.STRING) { String value = in.get(name); String digest = value; switch (config.hash.toLowerCase()) { case "md2": digest = DigestUtils.md2Hex(value); break; case "md5": digest = DigestUtils.md5Hex(value); break; case "sha1": digest = DigestUtils.sha1Hex(value); break; case "sha256": digest = DigestUtils.sha256Hex(value); break; case "sha384": digest = DigestUtils.sha384Hex(value); break; case "sha512": digest = DigestUtils.sha512Hex(value); break; }/*w w w .ja v a2 s. c o m*/ builder.set(name, digest); } else { builder.set(name, in.get(name)); } } emitter.emit(builder.build()); }
From source file:hu.holdinarms.resource.AdminResource.java
/** * Add new admin.// w w w.j a va 2 s . c o m * * @param admin The admin who add the new admin. * @param username The new admin's username. * @param password The new admin's password. * @return The new admin. */ @POST @UnitOfWork @Path("/add/{username}/{password}") public Admin addAdmin(@Auth Admin admin, @PathParam("username") String username, @PathParam("password") String password) { if (adminDao.findByUsername(username) != null) { return null; } Admin newAdmin = new Admin(); newAdmin.setUsername(username); newAdmin.setPassword(DigestUtils.sha256Hex(password)); newAdmin.setWhoAdded(admin); return adminDao.save(newAdmin); }
From source file:net.solarnetwork.node.backup.FileBackupResourceProvider.java
@Override public Iterable<BackupResource> getBackupResources() { if (resourceDirectories == null || resourceDirectories.length < 1) { return Collections.emptyList(); }/* ww w.j a v a 2 s. c o m*/ final Pattern pat = (fileNamePattern == null ? null : Pattern.compile(fileNamePattern, Pattern.CASE_INSENSITIVE)); List<BackupResource> fileList = new ArrayList<BackupResource>(20); for (String path : resourceDirectories) { File rootDir = (rootPath != null && rootPath.length() > 0 ? new File(rootPath, path) : new File(path)); if (!rootDir.isDirectory()) { log.info("Skipping path {} because does not exist or is not a directory", rootDir.getAbsolutePath()); continue; } File[] files = rootDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return pat.matcher(name).find(); } }); if (files == null || files.length < 1) { continue; } for (File f : files) { // make sure backup path is relative final String backupPath = path + '/' + f.getName(); String digest = null; InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(f)); digest = DigestUtils.sha256Hex(in); } catch (IOException e) { log.warn("Error calculating SHA-256 digest of {}: {}", f, e.getMessage()); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore } } } fileList.add(new ResourceBackupResource(new FileSystemResource(f), backupPath, getKey(), digest)); } } return fileList; }