List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:com.nebkat.plugin.text.TextPlugin.java
@EventHandler @CommandFilter("hash") public void onHashCommand(CommandEvent e) { if (e.getParams().length < 2) { e.showUsage(getBot());// ww w . j a v a 2 s . co m return; } String algorithm = e.getParams()[0]; String text = e.getRawParams().substring(algorithm.length() + 1); String result = "Algorithm unsupported"; if (algorithm.equalsIgnoreCase("md5")) { result = DigestUtils.md5Hex(text); } else if (algorithm.equalsIgnoreCase("md2")) { result = DigestUtils.md2Hex(text); } else if (algorithm.equalsIgnoreCase("sha1") || algorithm.equalsIgnoreCase("sha")) { result = DigestUtils.sha1Hex(text); } else if (algorithm.equalsIgnoreCase("sha256")) { result = DigestUtils.sha256Hex(text); } else if (algorithm.equalsIgnoreCase("sha384")) { result = DigestUtils.sha384Hex(text); } else if (algorithm.equalsIgnoreCase("sha512")) { result = DigestUtils.sha512Hex(text); } Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": " + result); }
From source file:com.thoughtworks.go.apiv2.environments.EnvironmentsControllerV2.java
private String calculateEtag(Collection<EnvironmentConfig> environmentConfigs) { final String environmentConfigSegment = environmentConfigs.stream().map(this::etagFor) .collect(Collectors.joining(SEP_CHAR)); return DigestUtils.sha256Hex(environmentConfigSegment); }
From source file:it.greenvulcano.gvesb.iam.service.internal.GVUsersManager.java
@Override public void checkManagementRequirements() { final Logger logger = LoggerFactory.getLogger(getClass()); Map<UserRepositoryHibernate.Parameter, Object> parameters = new HashMap<>(2); parameters.put(UserRepositoryHibernate.Parameter.role, Authority.ADMINISTRATOR); parameters.put(UserRepositoryHibernate.Parameter.enabled, Boolean.TRUE); int admins = userRepository.count(parameters); /**/* ww w .j a v a 2 s . co m*/ * Adding default user 'gvadmin' if no present */ if (admins == 0) { logger.info("Creating a default 'gvadmin'"); User admin; try { createUser("gvadmin", "gvadmin"); } catch (SecurityException | InvalidUsernameException | InvalidPasswordException | UserExistException e) { logger.info("A user named 'gvadmin' exist: restoring his default settings", e); admin = userRepository.get("gvadmin").get(); admin.setPassword(DigestUtils.sha256Hex("gvadmin")); admin.setPasswordTime(new Date()); admin.setExpired(true); userRepository.add(admin); } admin = userRepository.get("gvadmin").get(); admin.setEnabled(true); admin.clearRoles(); admin.addRole(new RoleJPA(Authority.ADMINISTRATOR, "Created by GV")); //roles required to use karaf admin.addRole(new RoleJPA("admin", "Created by GV")); admin.addRole(new RoleJPA("manager", "Created by GV")); admin.addRole(new RoleJPA("viewer", "Created by GV")); admin.addRole(new RoleJPA("systembundles", "Created by GV")); admin.addRole(new RoleJPA("ssh", "Created by GV")); userRepository.add(admin); } }
From source file:jongo.JongoUtils.java
public static String getHashedPassword(final String password) { return DigestUtils.sha256Hex(password); }
From source file:com.mweagle.tereus.commands.CreateCommand.java
protected void validateTemplate(TereusInput tereusInput, String parameterizedTemplate) throws UnsupportedEncodingException { if (tereusInput.dryRun) { tereusInput.logger.info("Dry run requested (-n/--noop). Stack validation bypassed."); } else {//ww w . ja v a 2 s . c o m tereusInput.logger.info("Validating template with AWS"); final String bucketName = tereusInput.params.get(CONSTANTS.PARAMETER_NAMES.S3_BUCKET_NAME).toString(); final byte[] templateBytes = parameterizedTemplate.getBytes("UTF-8"); final InputStream is = new ByteArrayInputStream(templateBytes); final String templateDigest = DigestUtils.sha256Hex(templateBytes); final String keyName = String.format("%s-tereus-pre.cf.template", templateDigest); try (S3Resource resource = new S3Resource(bucketName, keyName, is, Optional.of(Long.valueOf(templateBytes.length)))) { Optional<String> templateURL = resource.upload(); final ValidateTemplateRequest validationRequest = new ValidateTemplateRequest(); validationRequest.setTemplateURL(templateURL.get()); final AmazonCloudFormationClient awsClient = new AmazonCloudFormationClient( tereusInput.awsCredentials); awsClient.setRegion(tereusInput.awsRegion); final ValidateTemplateResult validationResult = awsClient.validateTemplate(validationRequest); tereusInput.logger.debug("Stack template validation results:"); tereusInput.logger.debug(validationResult.toString()); } } }
From source file:edu.kit.dama.staging.processor.impl.InputHashOP.java
/** * Hash a single file using the internally defined hash algorithm. * * @param pFile The file to hash/* w ww . ja v a2 s .c o m*/ * * @return The hash value * * @throws IOException If pFile cannot be read */ private String hashFile(File pFile) throws IOException { LOGGER.debug("Hashing file {}", pFile.getAbsolutePath()); InputStream is = null; try { is = new FileInputStream(pFile); String hash; switch (hashType) { case SHA: hash = DigestUtils.sha1Hex(is); break; case SHA256: hash = DigestUtils.sha256Hex(is); break; case SHA384: hash = DigestUtils.sha384Hex(is); break; case SHA512: hash = DigestUtils.sha512Hex(is); break; default: hash = DigestUtils.md5Hex(is); } return hash; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { //ignore } } } }
From source file:io.hops.hopsworks.api.jupyter.JupyterService.java
@POST @Path("/start") @Consumes(MediaType.APPLICATION_JSON)/* w ww . j av a 2 s.c o m*/ @Produces(MediaType.APPLICATION_JSON) @AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST }) public Response startNotebookServer(JupyterSettings jupyterSettings, @Context SecurityContext sc, @Context HttpServletRequest req) throws ProjectException, HopsSecurityException, ServiceException { String hdfsUser = getHdfsUser(sc); String loggedinemail = sc.getUserPrincipal().getName(); Users hopsworksUser = userFacade.findByEmail(loggedinemail); String realName = hopsworksUser.getFname() + " " + hopsworksUser.getLname(); if (project.getPaymentType().equals(PaymentType.PREPAID)) { YarnProjectsQuota projectQuota = yarnProjectsQuotaFacade.findByProjectName(project.getName()); if (projectQuota == null || projectQuota.getQuotaRemaining() < 0) { throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_QUOTA_INSUFFICIENT, Level.FINE); } } boolean enabled = project.getConda(); if (!enabled) { throw new ProjectException(RESTCodes.ProjectErrorCode.ANACONDA_NOT_ENABLED, Level.FINE); } JupyterProject jp = jupyterFacade.findByUser(hdfsUser); if (jp == null) { HdfsUsers user = hdfsUsersFacade.findByName(hdfsUser); String configSecret = DigestUtils.sha256Hex(Integer.toString(ThreadLocalRandom.current().nextInt())); JupyterDTO dto = null; DistributedFileSystemOps dfso = dfsService.getDfsOps(); try { jupyterSettingsFacade.update(jupyterSettings); dto = jupyterProcessFacade.startServerAsJupyterUser(project, configSecret, hdfsUser, realName, jupyterSettings); HopsUtils.materializeCertificatesForUserCustomDir(project.getName(), user.getUsername(), settings.getHdfsTmpCertDir(), dfso, certificateMaterializer, settings, dto.getCertificatesDir()); // When Livy launches a job it will look in the standard directory for the certificates // We materialize them twice but most probably other operations will need them too, so it is OK // Remember to remove both when stopping Jupyter server or an exception is thrown certificateMaterializer.materializeCertificatesLocal(user.getUsername(), project.getName()); } catch (IOException | ServiceException ex) { LOGGER.log(Level.SEVERE, null, ex); certificateMaterializer.removeCertificatesLocal(user.getUsername(), project.getName()); if (dto != null) { HopsUtils.cleanupCertificatesForUserCustomDir(user.getUsername(), project.getName(), settings.getHdfsTmpCertDir(), certificateMaterializer, dto.getCertificatesDir(), settings); } else { throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CERT_LOCATION_UNDEFINED, Level.SEVERE); } throw new ServiceException(RESTCodes.ServiceErrorCode.JUPYTER_START_ERROR, Level.SEVERE, ex.getMessage(), null, ex); } finally { if (dfso != null) { dfsService.closeDfsClient(dfso); } } String externalIp = Ip.getHost(req.getRequestURL().toString()); jp = jupyterFacade.saveServer(externalIp, project, configSecret, dto.getPort(), user.getId(), dto.getToken(), dto.getPid()); if (jp == null) { throw new ServiceException(RESTCodes.ServiceErrorCode.JUPYTER_SAVE_SETTINGS_ERROR, Level.SEVERE); } } return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(jp).build(); }
From source file:com.thoughtworks.go.domain.materials.svn.SvnMaterialTest.java
@Test void shouldGenerateFingerprintBasedOnSqlCriteria() { SvnMaterial one = new SvnMaterial("url", "username", "password", true); SvnMaterial two = new SvnMaterial("url", "username", "password", false); assertThat(one.getFingerprint()).isNotEqualTo(two.getFingerprint()); assertThat(one.getFingerprint()).isEqualTo( DigestUtils.sha256Hex("type=SvnMaterial<|>url=url<|>username=username<|>checkExternals=true")); }
From source file:fi.vm.kapa.identification.adapter.service.SessionParserService.java
String createTupasRequestMac(String version, String rcvId, String lang, String timestamp, String idType, String returnLink, String cancelLink, String rejectLink, String keyVersion, String sharedSecret) { String tupasString = "701&" + version + "&" + rcvId + "&" + lang + "&" + timestamp + "&" + idType + "&" + returnLink + "&" + cancelLink + "&" + rejectLink + "&" + keyVersion + "&03&" + sharedSecret + "&"; logger.debug("Generated Tupas request MAC string:\n{}", tupasString); try {/*from ww w .ja v a 2s.com*/ return DigestUtils.sha256Hex(tupasString.getBytes("ISO-8859-1")).toUpperCase(); } catch (UnsupportedEncodingException e) { logger.error("Unable to calculate tupas request MAC", e); return null; } }
From source file:com.thoughtworks.go.domain.materials.svn.SvnMaterialTest.java
@Test void shouldGeneratePipelineUniqueFingerprintBasedOnFingerprintAndDest() { SvnMaterial one = new SvnMaterial("url", "username", "password", true, "folder1"); SvnMaterial two = new SvnMaterial("url", "username", "password", true, "folder2"); assertThat(one.getPipelineUniqueFingerprint()).isNotEqualTo(two.getFingerprint()); assertThat(one.getPipelineUniqueFingerprint()).isEqualTo(DigestUtils .sha256Hex("type=SvnMaterial<|>url=url<|>username=username<|>checkExternals=true<|>dest=folder1")); }