[PRODSEC-9364] added java-uuid-generator (#2778)

* [PRODSEC-9364] added java-uuid-generator

* [PRODSEC-9364] addressed formatting issues

* [PRODSEC-9364] removed unnecessary qualifier java.util

* [PRODSEC-9364] removed addition import and change year in header
This commit is contained in:
Manish Kumar
2024-07-15 21:29:09 +05:30
committed by GitHub
parent 6f13f36c5a
commit 25c4b677de
8 changed files with 51 additions and 49 deletions

View File

@@ -47,11 +47,11 @@
<artifactId>commons-math3</artifactId> <artifactId>commons-math3</artifactId>
<version>3.6.1</version> <version>3.6.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.uuid/java-uuid-generator -->
<dependency> <dependency>
<groupId>org.safehaus.jug</groupId> <groupId>com.fasterxml.uuid</groupId>
<artifactId>jug</artifactId> <artifactId>java-uuid-generator</artifactId>
<version>2.0.0</version> <version>5.1.0</version>
<classifier>asl</classifier>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>

View File

@@ -21,7 +21,7 @@ package org.alfresco.util;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Random; import java.util.Random;
import org.safehaus.uuid.UUIDGenerator; import com.fasterxml.uuid.Generators;
import org.alfresco.api.AlfrescoPublicApi; import org.alfresco.api.AlfrescoPublicApi;
/** /**
@@ -69,7 +69,7 @@ public final class GUID
public static String generate() public static String generate()
{ {
int randomInt = RANDOM.nextInt(SECURE_RANDOM_POOL_MAX_ITEMS); int randomInt = RANDOM.nextInt(SECURE_RANDOM_POOL_MAX_ITEMS);
return UUIDGenerator.getInstance().generateRandomBasedUUID(SECURE_RANDOM_POOL[randomInt]).toString(); return Generators.randomBasedGenerator(SECURE_RANDOM_POOL[randomInt]).generate().toString();
} }
// == Not sure if we need this functionality again (derekh) == // == Not sure if we need this functionality again (derekh) ==

View File

@@ -33,13 +33,13 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import com.fasterxml.uuid.Generators;
import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.service.cmr.repository.datatype.Duration; import org.alfresco.service.cmr.repository.datatype.Duration;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.safehaus.uuid.UUIDGenerator;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
/** /**
@@ -497,7 +497,7 @@ public class InMemoryTicketComponentImpl implements TicketComponent
this.userName = userName; this.userName = userName;
this.validDuration = validDuration; this.validDuration = validDuration;
this.testDuration = validDuration.divide(2); this.testDuration = validDuration.divide(2);
final String guid = UUIDGenerator.getInstance().generateRandomBasedUUID().toString(); final String guid = Generators.randomBasedGenerator().generate().toString();
this.ticketId = computeTicketId(expires, expiryDate, userName, guid); this.ticketId = computeTicketId(expires, expiryDate, userName, guid);

View File

@@ -84,7 +84,7 @@
<include>org.alfresco:alfresco-core</include> <include>org.alfresco:alfresco-core</include>
<include>org.alfresco:alfresco-repository</include> <include>org.alfresco:alfresco-repository</include>
<include>org.apache.commons:commons-compress</include> <include>org.apache.commons:commons-compress</include>
<include>org.safehaus.jug:jug</include> <include>com.fasterxml.uuid:java-uuid-generator</include>
<include>org.alfresco.surf:spring-surf-core</include> <include>org.alfresco.surf:spring-surf-core</include>
<include>org.tukaani:xz</include> <include>org.tukaani:xz</include>
<include>org.apache.maven:maven-artifact</include> <include>org.apache.maven:maven-artifact</include>

View File

@@ -25,6 +25,7 @@
*/ */
package org.alfresco.repo.module.tool; package org.alfresco.repo.module.tool;
import com.fasterxml.uuid.Generators;
import de.schlichtherle.truezip.file.*; import de.schlichtherle.truezip.file.*;
import de.schlichtherle.truezip.fs.FsSyncException; import de.schlichtherle.truezip.fs.FsSyncException;
import de.schlichtherle.truezip.fs.archive.zip.JarDriver; import de.schlichtherle.truezip.fs.archive.zip.JarDriver;
@@ -34,7 +35,6 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.module.ModuleVersionNumber; import org.alfresco.repo.module.ModuleVersionNumber;
import org.alfresco.service.cmr.module.ModuleDetails; import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.service.cmr.module.ModuleInstallState; import org.alfresco.service.cmr.module.ModuleInstallState;
import org.safehaus.uuid.UUIDGenerator;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
@@ -916,7 +916,7 @@ public class ModuleManagementTool implements LogOutput
*/ */
private static String generateGuid() private static String generateGuid()
{ {
return UUIDGenerator.getInstance().generateTimeBasedUUID().toString(); return Generators.timeBasedGenerator().generate().toString();
} }
/** /**

View File

@@ -36,7 +36,10 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.UUIDUtil;
import org.alfresco.sync.events.types.ActivityEvent; import org.alfresco.sync.events.types.ActivityEvent;
import org.alfresco.sync.events.types.Event; import org.alfresco.sync.events.types.Event;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
@@ -108,8 +111,6 @@ import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Interval; import org.joda.time.Interval;
import org.joda.time.PeriodType; import org.joda.time.PeriodType;
import org.safehaus.uuid.UUID;
import org.safehaus.uuid.UUIDGenerator;
/** /**
* QuickShare Service implementation. * QuickShare Service implementation.
@@ -435,8 +436,8 @@ public class QuickShareServiceImpl implements QuickShareService,
// If it is retura dto built from the existing properties. // If it is retura dto built from the existing properties.
if (! nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE)) if (! nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE))
{ {
UUID uuid = UUIDGenerator.getInstance().generateRandomBasedUUID(); UUID uuid = Generators.randomBasedGenerator().generate();
sharedId = Base64.encodeBase64URLSafeString(uuid.toByteArray()); // => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw) sharedId = Base64.encodeBase64URLSafeString(UUIDUtil.asByteArray(uuid)); // => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw)
final Map<QName, Serializable> props = new HashMap<QName, Serializable>(2); final Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId); props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId);
@@ -1246,7 +1247,7 @@ public class QuickShareServiceImpl implements QuickShareService,
} }
// Create the expiry action // Create the expiry action
final QuickShareLinkExpiryAction expiryAction = new QuickShareLinkExpiryActionImpl(java.util.UUID.randomUUID().toString(), sharedId, final QuickShareLinkExpiryAction expiryAction = new QuickShareLinkExpiryActionImpl(UUID.randomUUID().toString(), sharedId,
"QuickShare link expiry action"); "QuickShare link expiry action");
// Create the persisted schedule // Create the persisted schedule
final ScheduledPersistedAction schedule = scheduledPersistedActionService.createSchedule(expiryAction); final ScheduledPersistedAction schedule = scheduledPersistedActionService.createSchedule(expiryAction);

View File

@@ -1,32 +1,33 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2024 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.security.person; package org.alfresco.repo.security.person;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.UUID;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.batch.BatchProcessor; import org.alfresco.repo.batch.BatchProcessor;
@@ -41,7 +42,6 @@ import org.springframework.extensions.surf.util.AbstractLifecycleBean;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.safehaus.uuid.UUID;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
/** /**
@@ -168,7 +168,7 @@ public class SplitPersonCleanupBootstrapBean extends AbstractLifecycleBean
try try
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
UUID id = new UUID(guidString); UUID id = UUID.fromString(guidString);
// We have a valid guid. // We have a valid guid.
return true; return true;
} }
@@ -188,7 +188,7 @@ public class SplitPersonCleanupBootstrapBean extends AbstractLifecycleBean
try try
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
UUID id = new UUID(guidString); UUID id = UUID.fromString(guidString);
// We have a valid guid. // We have a valid guid.
return true; return true;
} }

View File

@@ -37,7 +37,10 @@ import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.UUID;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.UUIDUtil;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.model.QuickShareModel; import org.alfresco.model.QuickShareModel;
import org.alfresco.repo.model.Repository; import org.alfresco.repo.model.Repository;
@@ -83,8 +86,6 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.rules.RuleChain; import org.junit.rules.RuleChain;
import org.safehaus.uuid.UUID;
import org.safehaus.uuid.UUIDGenerator;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
/** /**
@@ -420,8 +421,8 @@ public class QuickShareServiceIntegrationTest
@Test(expected=InvalidSharedIdException.class) public void getMetadataFromShareIdWithInvalidId() @Test(expected=InvalidSharedIdException.class) public void getMetadataFromShareIdWithInvalidId()
{ {
UUID uuid = UUIDGenerator.getInstance().generateRandomBasedUUID(); UUID uuid = Generators.randomBasedGenerator().generate();
String sharedId = Base64.encodeBase64URLSafeString(uuid.toByteArray()); // => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw) String sharedId = Base64.encodeBase64URLSafeString(UUIDUtil.asByteArray(uuid)); // => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw)
Map<String, Object> metadata = quickShareService.getMetaData(sharedId); Map<String, Object> metadata = quickShareService.getMetaData(sharedId);
} }
@@ -884,7 +885,7 @@ public class QuickShareServiceIntegrationTest
{ {
// Create a private site // Create a private site
AuthenticationUtil.setFullyAuthenticatedUser(user1.getUsername()); AuthenticationUtil.setFullyAuthenticatedUser(user1.getUsername());
String randomUUID = UUIDGenerator.getInstance().generateRandomBasedUUID().toString(); String randomUUID = Generators.randomBasedGenerator().generate().toString();
String siteName = "testSite" + randomUUID; String siteName = "testSite" + randomUUID;
siteService.createSite("site-dashboard", siteName, "Title for " + siteName, siteService.createSite("site-dashboard", siteName, "Title for " + siteName,
"Description for " + siteName, SiteVisibility.PRIVATE); "Description for " + siteName, SiteVisibility.PRIVATE);