You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2023/01/29 04:41:45 UTC
[sling-org-apache-sling-app-cms] branch master updated: Replacing SHA1 with SHA2
This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
The following commit(s) were added to refs/heads/master by this push:
new 688d5341 Replacing SHA1 with SHA2
688d5341 is described below
commit 688d5341a36c7241bc8d7f281420f466ef75d903
Author: Dan Klco <kl...@adobe.com>
AuthorDate: Sat Jan 28 23:41:37 2023 -0500
Replacing SHA1 with SHA2
---
.../cms/core/internal/FileMetadataExtractorImpl.java | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/FileMetadataExtractorImpl.java b/core/src/main/java/org/apache/sling/cms/core/internal/FileMetadataExtractorImpl.java
index 0ec653d2..3bef6421 100644
--- a/core/src/main/java/org/apache/sling/cms/core/internal/FileMetadataExtractorImpl.java
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/FileMetadataExtractorImpl.java
@@ -98,7 +98,7 @@ public class FileMetadataExtractorImpl implements FileMetadataExtractor {
}
if (properties != null) {
properties.putAll(extractMetadata(file.getResource()));
- properties.put("SHA1", generateSha1(resource)); //NOSONAR
+ properties.put("SHA256", generateSha(resource));
resource.getResourceResolver().refresh();
if (metadata == null) {
resource.getResourceResolver().create(content, CMSConstants.NN_METADATA, properties);
@@ -115,15 +115,15 @@ public class FileMetadataExtractorImpl implements FileMetadataExtractor {
}
}
- public String generateSha1(Resource resource) throws IOException {
+ public String generateSha(Resource resource) throws IOException {
try (InputStream is = resource.adaptTo(InputStream.class)) {
- String sha1 = DigestUtils.sha1Hex(is);
- log.info("Generated SHA {} for {}", sha1, resource.getPath());
- return sha1;
+ String sha256 = DigestUtils.sha256Hex(is);
+ log.info("Generated SHA {} for {}", sha256, resource.getPath());
+ return sha256;
}
}
- @SuppressWarnings(value={"java:S1874"})
+ @SuppressWarnings(value = { "java:S1874" })
public Map<String, Object> extractMetadata(Resource resource)
throws IOException, SAXException, TikaException, RepositoryException, LoginException {
log.info("Extracting metadata from {}", resource.getPath());
@@ -137,14 +137,13 @@ public class FileMetadataExtractorImpl implements FileMetadataExtractor {
parser.parse(is, handler, md, context);
} catch (SAXException se) {
// unfortunately, we can't use instanceof to check as the class is not exported
- if ("WriteLimitReachedException".equals(se.getClass().getSimpleName())) { //NOSONAR
+ if ("WriteLimitReachedException".equals(se.getClass().getSimpleName())) { // NOSONAR
log.info("Write limit reached for {}", resource.getPath());
} else {
throw se;
}
}
-
try (ResourceResolver adminResolver = resolverFactory.getAdministrativeResourceResolver(null)) {
NamespaceRegistry registry = adminResolver.adaptTo(Session.class).getWorkspace().getNamespaceRegistry();
for (String name : md.names()) {