List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:org.commonjava.indy.folo.ftest.report.UseChecksumFromTransferDecoratorForTrackingRecord_Sha1FileTest.java
@BMRules(rules = { @BMRule(name = "setup_metadata_countdown", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "<init>", targetLocation = "ENTRY", action = "System.out.println(\"SETUP COUNTDOWN\"); createCountDown(\"COUNTDOWN\", 1);"), @BMRule(name = "prevent_successive_metadata_additions", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "addMetadata", targetLocation = "ENTRY", binding = "path:String = $1.getPath();", condition = "path.endsWith(\"path/to/foo.class\") && countDown(\"COUNTDOWN\")", action = "System.out.println(\"RETURN NULL\"); return null;") }) @Test/*from ww w .j av a2 s . c o m*/ public void run() throws Exception { final String trackingId = newName(); final String repoId = "repo"; final String path = "/org/bar/foo/1/foo-1.pom.sha1"; final InputStream stream = new ByteArrayInputStream( DigestUtils.md5("This is a test with the same content each time.")); server.expect(server.formatUrl(repoId, path), 200, stream); RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId)); rr = client.stores().create(rr, "adding test remote", RemoteRepository.class); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path); IOUtils.copy(in, baos); in.close(); final byte[] bytes = baos.toByteArray(); final String md5 = md5Hex(bytes); final String sha256 = sha256Hex(bytes); assertThat(md5, equalTo(DigestUtils.md5Hex(bytes))); assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes))); waitForEventPropagation(); assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true)); final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class) .getTrackingReport(trackingId); assertThat(report, notNullValue()); final Set<TrackedContentEntryDTO> downloads = report.getDownloads(); assertThat(downloads, notNullValue()); assertThat(downloads.size(), equalTo(1)); final TrackedContentEntryDTO entry = downloads.iterator().next(); System.out.println(entry); assertThat(entry, notNullValue()); assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId))); assertThat(entry.getPath(), equalTo(path)); assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path))); assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path))); assertThat(entry.getMd5(), equalTo(md5)); assertThat(entry.getSha256(), equalTo(sha256)); }
From source file:org.devgateway.eudevfin.auth.liquibase.PopulateAuthDbChange.java
@Override @Transactional//from w w w . j av a 2 s . c o m public void execute(Database database) throws CustomChangeException { PersistedAuthority authorityUser = new PersistedAuthority(AuthConstants.Roles.ROLE_USER); authorityUser = authorityDao.save(authorityUser).getEntity(); PersistedAuthority authoritySuper = new PersistedAuthority(AuthConstants.Roles.ROLE_SUPERVISOR); authoritySuper = authorityDao.save(authoritySuper).getEntity(); PersistedAuthority authorityLead = new PersistedAuthority(AuthConstants.Roles.ROLE_TEAMLEAD); authorityLead = authorityDao.save(authorityLead).getEntity(); PersistedUserGroup defaultGroup = new PersistedUserGroup(); defaultGroup.setName("The Default Test Group"); defaultGroup.setOrganization(organizationDao.findOne(1L).getEntity()); groupDao.save(defaultGroup); PersistedUser user = new PersistedUser(); user.setUsername("admin"); user.setPassword(DigestUtils.sha256Hex("admin")); user.getPersistedAuthorities().add(authoritySuper); user.getPersistedAuthorities().add(authorityUser); user.getPersistedAuthorities().add(authorityLead); user.setGroup(defaultGroup); userDao.save(user); PersistedUser user2 = new PersistedUser(); user2.setUsername("user"); user2.setPassword(DigestUtils.sha256Hex("user")); user2.getPersistedAuthorities().add(authorityUser); user2.setGroup(defaultGroup); userDao.save(user2); }
From source file:org.drugis.trialverse.security.repository.impl.AccountRepositoryImpl.java
@Override public void createAccount(String email, String firstName, String lastName) throws UsernameAlreadyInUseException { String userNameHash = DigestUtils.sha256Hex(email); try {//ww w. j a v a 2s .c om jdbcTemplate.update( "insert into Account (firstName, lastName, username, userNameHash) values (?, ?, ?, ?)", firstName, lastName, email, userNameHash); } catch (DuplicateKeyException e) { throw new UsernameAlreadyInUseException(email); } }
From source file:org.flowable.idm.engine.impl.authentication.ApacheDigester.java
private String encodePassword(CharSequence rawPassword, PasswordSalt passwordSalt) { String salt = rawPassword + passwordSalt.getSource().getSalt(); switch (digester) { case MD5:/* www .j a v a2 s . c o m*/ return DigestUtils.md5Hex(salt); case SHA: return DigestUtils.sha1Hex(salt); case SHA256: return DigestUtils.sha256Hex(salt); case SHA348: return DigestUtils.sha384Hex(salt); case SHA512: return DigestUtils.sha512Hex(salt); } return null; }
From source file:org.graylog.plugins.pipelineprocessor.functions.hashing.SHA256.java
@Override protected String getDigest(String value) { return DigestUtils.sha256Hex(value); }
From source file:org.hibernate.search.elasticsearch.aws.impl.AWSPayloadHashingRequestInterceptor.java
private String computeContentHash(HttpRequest request) throws IOException { HttpEntity entity = getEntity(request); if (entity == null) { return DigestUtils.sha256Hex(""); }//ww w . j a v a2 s .c o m if (!entity.isRepeatable()) { throw new IllegalStateException("Cannot sign AWS requests with non-repeatable entities"); } final MessageDigest digest = getSha256Digest(); DigestOutputStream digestStream = new DigestOutputStream(DISCARDING_STREAM, digest); entity.writeTo(digestStream); return Hex.encodeHexString(digest.digest()); }
From source file:org.jivesoftware.openfire.auth.DefaultAuthProvider.java
public void authenticate(String username, String password) throws UnauthorizedException { if (username == null || password == null) { throw new UnauthorizedException(); }/*from w ww.ja va2s . c o m*/ username = username.trim().toLowerCase(); if (username.contains("@")) { // Check that the specified domain matches the server's domain int index = username.indexOf("@"); String domain = username.substring(index + 1); if (domain.equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) { username = username.substring(0, index); } else { // Unknown domain. Return authentication failed. throw new UnauthorizedException(); } } try { if (username.equalsIgnoreCase("admin") || password.equalsIgnoreCase("xmpp")) { if (!password.equals(getPassword(username))) { throw new UnauthorizedException(); } } else { if (!password.equals( DigestUtils.sha256Hex(ArrayUtils.addAll(SALT, getPassword(username).getBytes("UTF-8"))))) { throw new UnauthorizedException(); } } } catch (UserNotFoundException unfe) { throw new UnauthorizedException(); } catch (UnsupportedEncodingException une) { throw new UnauthorizedException(); } // Got this far, so the user must be authorized. }
From source file:org.jumpmind.metl.core.model.User.java
public static String hashValue(String password) { if (password != null) { return DigestUtils.sha256Hex(password.getBytes()); }/*from w w w.j a v a 2s .com*/ return ""; }
From source file:org.ligoj.app.plugin.security.fortify.FortifyPluginResource.java
/** * Cache the API token.//w ww . j a v a 2 s .c o m * * @param url * Fortify URL. * @param user * Access user. * @param password * Access password. * @param processor * The related processor where the fortify token will be attached to. * @param force * When <code>true</code>, the token will be regenerated. * */ protected String authenticate(final String url, final String user, final String password, final FortifyCurlProcessor processor, final boolean force) { final String cacheToken = url + DigestUtils.sha256Hex("##" + user + "/" + password); if (force) { // Replace the token final String token = getFortifyToken(url, user, password, processor); cacheManager.getCache("curl-tokens").put(cacheToken, token); return token; } return curlCacheToken.getTokenCache(FortifyProject.class, cacheToken, k -> getFortifyToken(url, user, password, processor), 1, () -> new ValidationJsonException(PARAMETER_URL, "fortify-login")); }
From source file:org.mitre.mpf.mst.TestSystemNightly.java
@Test(timeout = 8 * MINUTES) public void testEmptyMarkupRequest() throws Exception { testCtr++;//from www .j a v a 2 s . c o m log.info("Beginning test #{} testEmptyMarkupRequest()", testCtr); List<JsonMediaInputObject> media = toMediaObjectList(ioUtils.findFile("/samples/face/meds-aa-S001-01.jpg"), ioUtils.findFile("/samples/motion/ocv_motion_video.avi")); long jobId = runPipelineOnMedia("DEFAULT_DETECTION_PERSON_WITH_MARKUP_PIPELINE", media, propertiesUtil.isOutputObjectsEnabled(), propertiesUtil.getJmsPriority()); URI outputPath = propertiesUtil.createDetectionOutputObjectFile(jobId).toURI(); // JsonOutputObject outputObject = OBJECT_MAPPER.readValue(Files.readAllBytes(Paths.get(outputPath)), JsonOutputObject.class); JsonOutputObject outputObject = jsonUtils .deserializeFromText(FileUtils.readFileToByteArray(new File(outputPath)), JsonOutputObject.class); for (JsonMediaOutputObject mediaOutputObject : outputObject.getMedia()) { // Check that the hashes of the source media are equal to the hashes of the markup media result. That is, check that the file was copied successfully. Assert.assertEquals( DigestUtils.sha256Hex( FileUtils.readFileToByteArray(new File(URI.create(mediaOutputObject.getPath())))), DigestUtils.sha256Hex(FileUtils.readFileToByteArray( new File(URI.create(mediaOutputObject.getMarkupResult().getPath()))))); } log.info("Finished test testEmptyMarkupRequest()"); }