Skip to content

Commit 06f6695

Browse files
committed
Use system user for repopulate search index
The previous fix from opencast#6490 did not fully address the issue, as the `getSeries` service is dependent on the current organization context from the `securityService`. Consequently, related series were not retrievable. To resolve this, a switch to the corresponding system user was implemented. This change ensures that the correct organization context is used, thereby granting all necessary permissions to reindex both series and events.
1 parent bca31cb commit 06f6695

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

modules/search-service-impl/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@
6565
<groupId>jakarta.ws.rs</groupId>
6666
<artifactId>jakarta.ws.rs-api</artifactId>
6767
</dependency>
68-
<dependency>
69-
<groupId>org.osgi</groupId>
70-
<artifactId>osgi.core</artifactId>
71-
</dependency>
7268
<dependency>
7369
<groupId>org.osgi</groupId>
7470
<artifactId>org.osgi.service.component</artifactId>

modules/search-service-impl/src/main/java/org/opencastproject/search/impl/SearchServiceIndex.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
package org.opencastproject.search.impl;
2323

24-
import static org.opencastproject.systems.OpencastConstants.DIGEST_USER_PROPERTY;
25-
2624
import org.opencastproject.elasticsearch.index.ElasticsearchIndex;
2725
import org.opencastproject.elasticsearch.index.rebuild.AbstractIndexProducer;
2826
import org.opencastproject.elasticsearch.index.rebuild.IndexProducer;
@@ -41,6 +39,7 @@
4139
import org.opencastproject.search.impl.persistence.SearchServiceDatabaseException;
4240
import org.opencastproject.security.api.AccessControlList;
4341
import org.opencastproject.security.api.AuthorizationService;
42+
import org.opencastproject.security.api.Organization;
4443
import org.opencastproject.security.api.OrganizationDirectoryService;
4544
import org.opencastproject.security.api.Permissions;
4645
import org.opencastproject.security.api.Role;
@@ -152,7 +151,7 @@ public SearchServiceIndex() {
152151
@Activate
153152
public void activate(final ComponentContext cc) throws IllegalStateException {
154153
createIndex();
155-
systemUserName = cc.getBundleContext().getProperty(DIGEST_USER_PROPERTY);
154+
systemUserName = SecurityUtil.getSystemUserName(cc);
156155
}
157156

158157
private void createIndex() {
@@ -244,14 +243,14 @@ public void addSynchronously(MediaPackage mediaPackage)
244243
}
245244

246245
private void indexMediaPackage(MediaPackage mediaPackage, AccessControlList acl)
247-
throws SearchException, UnauthorizedException, SearchServiceDatabaseException {
248-
indexMediaPackage(mediaPackage, acl, null, null, securityService.getOrganization().getId());
246+
throws SearchException, SearchServiceDatabaseException {
247+
indexMediaPackage(mediaPackage, acl, null, null);
249248
}
250249

251-
private void indexMediaPackage(MediaPackage mediaPackage, AccessControlList acl, Date modDate, Date delDate,
252-
String orgId)
253-
throws SearchException, UnauthorizedException, SearchServiceDatabaseException {
250+
private void indexMediaPackage(MediaPackage mediaPackage, AccessControlList acl, Date modDate, Date delDate)
251+
throws SearchException, SearchServiceDatabaseException {
254252
String mediaPackageId = mediaPackage.getIdentifier().toString();
253+
String orgId = securityService.getOrganization().getId();
255254
//If the entry has been deleted then there's *probably* no dc file to load.
256255
DublinCoreCatalog dc = null == delDate
257256
? DublinCoreUtil.loadEpisodeDublinCore(workspace, mediaPackage).orElse(DublinCores.mkSimple())
@@ -452,6 +451,9 @@ public boolean deleteSeriesSynchronously(String seriesId) throws SearchException
452451

453452
@Override
454453
public void repopulate() throws IndexRebuildException {
454+
final Organization originalOrg = securityService.getOrganization();
455+
final User originalUser = securityService.getUser();
456+
455457
try {
456458
int total = persistence.countMediaPackages();
457459
int pageSize = 50;
@@ -465,6 +467,11 @@ public void repopulate() throws IndexRebuildException {
465467
page.forEach(tuple -> {
466468
try {
467469
MediaPackage mediaPackage = tuple.getA();
470+
Organization organization = organizationDirectory.getOrganization(tuple.getB());
471+
final var systemUser = SecurityUtil.createSystemUser(systemUserName, organization);
472+
securityService.setUser(systemUser);
473+
securityService.setOrganization(organization);
474+
468475
String mediaPackageId = mediaPackage.getIdentifier().toString();
469476

470477
AccessControlList acl = persistence.getAccessControlList(mediaPackageId);
@@ -476,8 +483,9 @@ public void repopulate() throws IndexRebuildException {
476483
logger.debug("Updating series ACL with merged access control list: {}", seriesAcl);
477484

478485
current.getAndIncrement();
479-
indexMediaPackage(mediaPackage, acl, modificationDate, deletionDate, tuple.getB());
480-
} catch (SearchServiceDatabaseException | UnauthorizedException e) {
486+
487+
indexMediaPackage(mediaPackage, acl, modificationDate, deletionDate);
488+
} catch (SearchServiceDatabaseException e) {
481489
logIndexRebuildError(logger, total, current.get(), e);
482490
//NB: Runtime exception thrown to escape the functional interfacing
483491
throw new RuntimeException("Internal Index Rebuild Failure", e);
@@ -493,6 +501,9 @@ public void repopulate() throws IndexRebuildException {
493501
} catch (SearchServiceDatabaseException | RuntimeException e) {
494502
logIndexRebuildError(logger, e);
495503
throw new IndexRebuildException("Index Rebuild Failure", e);
504+
} finally {
505+
securityService.setUser(originalUser);
506+
securityService.setOrganization(originalOrg);
496507
}
497508
}
498509

0 commit comments

Comments
 (0)