import org.argeo.api.cms.CmsAuth;
import org.argeo.api.cms.CmsConstants;
+import org.argeo.jcr.JcrUtils;
/** Utilities related to Argeo model in JCR */
public class CmsJcrUtils {
public static Session openDataAdminSession(Repository repository, String workspaceName) {
LoginContext loginContext;
try {
- loginContext = new LoginContext(CmsAuth.LOGIN_CONTEXT_DATA_ADMIN);
+ loginContext = CmsAuth.DATA_ADMIN.newLoginContext();
loginContext.login();
} catch (LoginException e1) {
throw new RuntimeException("Could not login as data admin", e1);
@Override
public Session run() {
try {
- return repository.login(workspaceName);
- } catch (NoSuchWorkspaceException e) {
+ return JcrUtils.loginOrCreateWorkspace(repository, workspaceName);
+ } catch (NoSuchWorkspaceException e) {// should not happen
throw new IllegalArgumentException("No workspace " + workspaceName + " available", e);
} catch (RepositoryException e) {
throw new RuntimeException("Cannot open data admin session", e);
private String mountPath;
+ // cache
+ private String jcrWorkspace;
+
private Map<ProvidedSession, JcrSessionAdapter> sessionAdapters = Collections.synchronizedMap(new HashMap<>());
public void start(Map<String, String> properties) {
if ("/".equals(mountPath))
throw new IllegalArgumentException("JCR content provider cannot be root /");
Objects.requireNonNull(mountPath);
- adminSession = CmsJcrUtils.openDataAdminSession(jcrRepository, null);
+ jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
+ adminSession = CmsJcrUtils.openDataAdminSession(jcrRepository, jcrWorkspace);
}
public void stop() {
@Override
public ProvidedContent get(ProvidedSession contentSession, String relativePath) {
- String jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
String jcrPath = "/" + relativePath;
return new JcrContent(contentSession, this, jcrWorkspace, jcrPath);
}