forked from Archives/Athou_commafeed
remove commons-codec since we already have guava
This commit is contained in:
@@ -306,10 +306,6 @@
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.commafeed.backend;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Digests {
|
||||
|
||||
public static String sha1Hex(byte[] input) {
|
||||
return hashBytesToHex(Hashing.sha1(), input);
|
||||
}
|
||||
|
||||
public static String sha1Hex(String input) {
|
||||
return hashBytesToHex(Hashing.sha1(), input.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static String md5Hex(String input) {
|
||||
return hashBytesToHex(Hashing.md5(), input.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static String hashBytesToHex(HashFunction function, byte[] input) {
|
||||
return function.hashBytes(input).toString();
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package com.commafeed.backend.cache;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.backend.feed.parser.FeedParserResult.Entry;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
@@ -20,7 +19,7 @@ public abstract class CacheService {
|
||||
public abstract void setLastEntries(Feed feed, List<String> entries);
|
||||
|
||||
public String buildUniqueEntryKey(Entry entry) {
|
||||
return DigestUtils.sha1Hex(entry.guid() + entry.url());
|
||||
return Digests.sha1Hex(entry.guid() + entry.url());
|
||||
}
|
||||
|
||||
// user categories
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.time.Instant;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.binary.StringUtils;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.backend.HttpGetter;
|
||||
import com.commafeed.backend.HttpGetter.HttpResult;
|
||||
import com.commafeed.backend.HttpGetter.NotModifiedException;
|
||||
@@ -68,7 +68,7 @@ public class FeedFetcher {
|
||||
boolean lastModifiedHeaderValueChanged = !StringUtils.equals(lastModified, result.getLastModifiedSince());
|
||||
boolean etagHeaderValueChanged = !StringUtils.equals(eTag, result.getETag());
|
||||
|
||||
String hash = DigestUtils.sha1Hex(content);
|
||||
String hash = Digests.sha1Hex(content);
|
||||
if (lastContentHash != null && lastContentHash.equals(hash)) {
|
||||
log.debug("content hash not modified: {}", feedUrl);
|
||||
throw new NotModifiedException("content hash not modified",
|
||||
|
||||
@@ -12,11 +12,11 @@ import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.codahale.metrics.Meter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
import com.commafeed.backend.dao.UnitOfWork;
|
||||
@@ -89,7 +89,7 @@ public class FeedRefreshUpdater {
|
||||
// lock on content, make sure we are not updating the same entry
|
||||
// twice at the same time
|
||||
Content content = entry.content();
|
||||
String key2 = DigestUtils.sha1Hex(StringUtils.trimToEmpty(content.content() + content.title()));
|
||||
String key2 = Digests.sha1Hex(StringUtils.trimToEmpty(content.content() + content.title()));
|
||||
|
||||
Iterator<Lock> iterator = locks.bulkGet(Arrays.asList(key1, key2)).iterator();
|
||||
Lock lock1 = iterator.next();
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.commafeed.backend.service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.backend.dao.FeedEntryContentDAO;
|
||||
import com.commafeed.backend.feed.FeedUtils;
|
||||
import com.commafeed.backend.feed.parser.FeedParserResult.Content;
|
||||
@@ -42,8 +42,8 @@ public class FeedEntryContentService {
|
||||
|
||||
private FeedEntryContent buildContent(Content content, String baseUrl) {
|
||||
FeedEntryContent entryContent = new FeedEntryContent();
|
||||
entryContent.setTitleHash(DigestUtils.sha1Hex(StringUtils.trimToEmpty(content.title())));
|
||||
entryContent.setContentHash(DigestUtils.sha1Hex(StringUtils.trimToEmpty(content.content())));
|
||||
entryContent.setTitleHash(Digests.sha1Hex(StringUtils.trimToEmpty(content.title())));
|
||||
entryContent.setContentHash(Digests.sha1Hex(StringUtils.trimToEmpty(content.content())));
|
||||
entryContent.setTitle(FeedUtils.truncate(cleaningService.clean(content.title(), baseUrl, true), 2048));
|
||||
entryContent.setContent(cleaningService.clean(content.content(), baseUrl, false));
|
||||
entryContent.setAuthor(FeedUtils.truncate(cleaningService.clean(content.author(), baseUrl, true), 128));
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.commafeed.backend.service;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
@@ -41,7 +40,7 @@ public class FeedEntryService {
|
||||
*/
|
||||
public FeedEntry findOrCreate(Feed feed, Entry entry) {
|
||||
String guid = FeedUtils.truncate(entry.guid(), 2048);
|
||||
String guidHash = DigestUtils.sha1Hex(entry.guid());
|
||||
String guidHash = Digests.sha1Hex(entry.guid());
|
||||
FeedEntry existing = feedEntryDAO.findExisting(guidHash, feed);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
|
||||
@@ -4,9 +4,9 @@ import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.backend.dao.FeedDAO;
|
||||
import com.commafeed.backend.favicon.AbstractFaviconFetcher;
|
||||
import com.commafeed.backend.favicon.Favicon;
|
||||
@@ -39,7 +39,7 @@ public class FeedService {
|
||||
|
||||
public synchronized Feed findOrCreate(String url) {
|
||||
String normalizedUrl = FeedUtils.normalizeURL(url);
|
||||
String normalizedUrlHash = DigestUtils.sha1Hex(normalizedUrl);
|
||||
String normalizedUrlHash = Digests.sha1Hex(normalizedUrl);
|
||||
Feed feed = feedDAO.findByUrl(normalizedUrl, normalizedUrlHash);
|
||||
if (feed == null) {
|
||||
feed = new Feed();
|
||||
@@ -55,7 +55,7 @@ public class FeedService {
|
||||
public void save(Feed feed) {
|
||||
String normalized = FeedUtils.normalizeURL(feed.getUrl());
|
||||
feed.setNormalizedUrl(normalized);
|
||||
feed.setNormalizedUrlHash(DigestUtils.sha1Hex(normalized));
|
||||
feed.setNormalizedUrlHash(Digests.sha1Hex(normalized));
|
||||
feed.setLastUpdated(Instant.now());
|
||||
feed.setEtagHeader(FeedUtils.truncate(feed.getEtagHeader(), 255));
|
||||
feedDAO.saveOrUpdate(feed);
|
||||
|
||||
@@ -8,11 +8,11 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.commafeed.CommaFeedApplication;
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
import com.commafeed.backend.dao.UserDAO;
|
||||
@@ -94,7 +94,7 @@ public class UserService {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
String computedFeverApiKey = DigestUtils.md5Hex(user.getName() + ":" + user.getApiKey());
|
||||
String computedFeverApiKey = Digests.md5Hex(user.getName() + ":" + user.getApiKey());
|
||||
if (!computedFeverApiKey.equals(feverApiKey)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public class UserService {
|
||||
|
||||
public String generateApiKey(User user) {
|
||||
byte[] key = encryptionService.getEncryptedPassword(UUID.randomUUID().toString(), user.getSalt());
|
||||
return DigestUtils.sha1Hex(key);
|
||||
return Digests.sha1Hex(key);
|
||||
}
|
||||
|
||||
public Set<Role> getRoles(User user) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.hc.core5.net.URIBuilder;
|
||||
@@ -14,6 +13,7 @@ import org.apache.hc.core5.net.URIBuilder;
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import com.commafeed.CommaFeedApplication;
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.backend.dao.UserDAO;
|
||||
import com.commafeed.backend.dao.UserRoleDAO;
|
||||
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||
@@ -292,7 +292,7 @@ public class UserREST {
|
||||
}
|
||||
|
||||
try {
|
||||
user.setRecoverPasswordToken(DigestUtils.sha1Hex(UUID.randomUUID().toString()));
|
||||
user.setRecoverPasswordToken(Digests.sha1Hex(UUID.randomUUID().toString()));
|
||||
user.setRecoverPasswordTokenDate(Instant.now());
|
||||
userDAO.saveOrUpdate(user);
|
||||
mailService.sendMail(user, "Password recovery", buildEmailContent(user));
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.commafeed.backend;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class DigestsTest {
|
||||
|
||||
@Test
|
||||
void sha1Hex() {
|
||||
Assertions.assertEquals("aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d", Digests.sha1Hex("hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void md5Hex() {
|
||||
Assertions.assertEquals("5d41402abc4b2a76b9719d911017c592", Digests.md5Hex("hello"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.commafeed.backend.feed;
|
||||
import java.time.Instant;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -17,6 +16,7 @@ import com.commafeed.backend.HttpGetter.HttpResult;
|
||||
import com.commafeed.backend.HttpGetter.NotModifiedException;
|
||||
import com.commafeed.backend.feed.parser.FeedParser;
|
||||
import com.commafeed.backend.urlprovider.FeedURLProvider;
|
||||
import com.google.gwt.thirdparty.guava.common.hash.Hashing;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class FeedFetcherTest {
|
||||
@@ -43,7 +43,7 @@ class FeedFetcherTest {
|
||||
String lastModified = "last-modified-1";
|
||||
String etag = "etag-1";
|
||||
byte[] content = "content".getBytes();
|
||||
String lastContentHash = DigestUtils.sha1Hex(content);
|
||||
String lastContentHash = Hashing.sha1().hashBytes(content).toString();
|
||||
|
||||
Mockito.when(getter.getBinary(url, lastModified, etag, 20000))
|
||||
.thenReturn(new HttpResult(content, "content-type", "last-modified-2", "etag-2", 20, null));
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.commafeed.integration.rest;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.commafeed.backend.Digests;
|
||||
import com.commafeed.frontend.model.UserModel;
|
||||
import com.commafeed.frontend.model.request.ProfileModificationRequest;
|
||||
import com.commafeed.frontend.resource.fever.FeverResponse;
|
||||
@@ -64,7 +64,7 @@ class FeverIT extends BaseIT {
|
||||
|
||||
private FeverResponse fetch(String what, String apiKey) {
|
||||
Form form = new Form();
|
||||
form.param("api_key", DigestUtils.md5Hex("admin:" + apiKey));
|
||||
form.param("api_key", Digests.md5Hex("admin:" + apiKey));
|
||||
form.param(what, "1");
|
||||
return getClient().target(getApiBaseUrl() + "fever/user/{userId}")
|
||||
.resolveTemplate("userId", userId)
|
||||
|
||||
Reference in New Issue
Block a user