Skip to content

Commit

Permalink
fix: fix exception of unrecognized alias on hsqldb - EXO - EXO-65151 -
Browse files Browse the repository at this point in the history
…Meeds-io/MIPs#69 (#164)

Prior to this change, On hsqldb an exception is thrown when the UP is executed because of unrecognized use alias for SALT128 attribute.
This PR changes the request to avoid using alias and prevent the issue.
  • Loading branch information
hakermi authored and rdenarie committed Aug 1, 2023
1 parent 1a278a2 commit 26b0136
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class UserPasswordHashMigration extends UpgradeProductPlugin {
Expand Down Expand Up @@ -73,12 +71,11 @@ public void processUpgrade(String s, String s1) {
AtomicInteger updatedPasswords = new AtomicInteger();
EntityManager entityManager = this.entityManagerService.getEntityManager();
try {
String sqlString = "SELECT jbid_io.NAME, jbid_io_creden.TEXT FROM" +
" (jbid_io_creden INNER JOIN jbid_io ON jbid_io_creden.IDENTITY_OBJECT_ID = jbid_io.ID)" +
" INNER JOIN (SELECT jbid_io_attr.IDENTITY_OBJECT_ID," +
" min(CASE WHEN jbid_io_attr.NAME = 'passwordSalt128' THEN jbid_io_attr.NAME ELSE NULL END) AS salt128" +
" FROM jbid_io_attr GROUP BY jbid_io_attr.IDENTITY_OBJECT_ID" +
" HAVING salt128 IS NULL) jia ON jbid_io_creden.IDENTITY_OBJECT_ID = jia.IDENTITY_OBJECT_ID;";
String sqlString = "SELECT jbid_io.NAME, jbid_io_creden.TEXT FROM"
+ " (jbid_io_creden INNER JOIN jbid_io ON jbid_io_creden.IDENTITY_OBJECT_ID = jbid_io.ID)"
+ " INNER JOIN (SELECT jbid_io_attr.IDENTITY_OBJECT_ID FROM jbid_io_attr"
+ " WHERE jbid_io_attr.IDENTITY_OBJECT_ID NOT IN (SELECT jbid_io_attr.IDENTITY_OBJECT_ID FROM jbid_io_attr WHERE NAME = 'passwordSalt128')"
+ " GROUP BY jbid_io_attr.IDENTITY_OBJECT_ID) jia ON jbid_io_creden.IDENTITY_OBJECT_ID = jia.IDENTITY_OBJECT_ID;";

Query nativeQuery = entityManager.createNativeQuery(sqlString);
List<Object[]> result = nativeQuery.getResultList();
Expand All @@ -90,7 +87,7 @@ public void processUpgrade(String s, String s1) {
User user = picketLinkIDMService.getIdentitySession().getPersistenceManager().findUser(userName);
picketLinkIDMService.getExtendedAttributeManager().addAttribute(userName, PASSWORD_SALT_USER_ATTRIBUTE, saltString);
picketLinkIDMService.getExtendedAttributeManager().updatePassword(user, passwordHash);
int count = updatedPasswords.getAndIncrement();
int count = updatedPasswords.incrementAndGet();
if (count % 50 == 0 || count == result.size()) {
LOG.info("{}/{} passwords have been updated", count, result.size());
}
Expand Down

0 comments on commit 26b0136

Please sign in to comment.