Add open content session from CMS session
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 25 Jun 2023 09:46:36 +0000 (11:46 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 25 Jun 2023 09:46:36 +0000 (11:46 +0200)
org.argeo.cms/src/org/argeo/cms/acr/ContentUtils.java

index 0513a0d3e4354a447c125b21559da75953fe873a..bf5954411bc157a32003bf17d3e4363e8ee9d5bc 100644 (file)
@@ -16,6 +16,7 @@ import org.argeo.api.acr.ContentRepository;
 import org.argeo.api.acr.ContentSession;
 import org.argeo.api.acr.DName;
 import org.argeo.api.cms.CmsAuth;
+import org.argeo.api.cms.CmsSession;
 import org.argeo.api.cms.directory.CmsDirectory;
 import org.argeo.api.cms.directory.CmsUserManager;
 import org.argeo.api.cms.directory.HierarchyUnit;
@@ -176,7 +177,7 @@ public class ContentUtils {
                }
        }
 
-       public static ContentSession openDataAdminSession(ContentRepository repository) {
+       public static ContentSession openDataAdminSession(ContentRepository contentRepository) {
                LoginContext loginContext;
                try {
                        loginContext = CmsAuth.DATA_ADMIN.newLoginContext();
@@ -189,12 +190,16 @@ public class ContentUtils {
                ClassLoader currentCl = Thread.currentThread().getContextClassLoader();
                try {
                        Thread.currentThread().setContextClassLoader(ContentUtils.class.getClassLoader());
-                       return CurrentSubject.callAs(loginContext.getSubject(), () -> repository.get());
+                       return CurrentSubject.callAs(loginContext.getSubject(), () -> contentRepository.get());
                } finally {
                        Thread.currentThread().setContextClassLoader(currentCl);
                }
        }
 
+       public static ContentSession openSession(ContentRepository contentRepository, CmsSession cmsSession) {
+               return CurrentSubject.callAs(cmsSession.getSubject(), () -> contentRepository.get());
+       }
+
        /**
         * Constructs a relative path between a base path and a given path.
         *