X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Facr%2FCmsContentRepository.java;h=15b893bb3d3ade0aab47e084fd0ace6316511910;hb=5724ab347ddfba8f2b21cdcc2fa0b8e1e2b4e527;hp=c2d6b21e406f61a5930e43f235de6fa8e7c2e42b;hpb=eb4cc3db3bf141c229f0f7ff929daff108bee6d2;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/acr/CmsContentRepository.java b/org.argeo.cms/src/org/argeo/cms/acr/CmsContentRepository.java index c2d6b21e4..15b893bb3 100644 --- a/org.argeo.cms/src/org/argeo/cms/acr/CmsContentRepository.java +++ b/org.argeo.cms/src/org/argeo/cms/acr/CmsContentRepository.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; +import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; @@ -12,16 +13,25 @@ import org.argeo.api.acr.ContentSession; import org.argeo.api.acr.spi.ProvidedRepository; import org.argeo.api.cms.CmsAuth; import org.argeo.api.cms.CmsSession; -import org.argeo.cms.auth.CurrentUser; +import org.argeo.api.cms.CmsState; +import org.argeo.api.cms.DataAdminPrincipal; +import org.argeo.api.uuid.UuidFactory; +import org.argeo.cms.CurrentUser; import org.argeo.cms.internal.runtime.CmsContextImpl; +import org.argeo.cms.util.CurrentSubject; /** * Multi-session {@link ProvidedRepository}, integrated with a CMS. */ public class CmsContentRepository extends AbstractContentRepository { + public final static String RUN_BASE = "/run"; + public final static String DIRECTORY_BASE = "/directory"; private Map userSessions = Collections.synchronizedMap(new HashMap<>()); + private CmsState cmsState; + private UuidFactory uuidFactory; + /* * REPOSITORY */ @@ -33,11 +43,22 @@ public class CmsContentRepository extends AbstractContentRepository { @Override public ContentSession get(Locale locale) { - // Subject subject = Subject.getSubject(AccessController.getContext()); + Subject subject = CurrentSubject.current(); + if (subject == null) + throw new IllegalStateException("Caller must be authenticated"); + if (!CmsSession.hasCmsSession(subject)) { + if (DataAdminPrincipal.isDataAdmin(subject)) { + // TODO open multiple data admin sessions? + return getSystemSession(); + } + throw new IllegalStateException("Caller must be authenticated"); + } + CmsSession cmsSession = CurrentUser.getCmsSession(); CmsContentSession contentSession = userSessions.get(cmsSession); if (contentSession == null) { - final CmsContentSession newContentSession = new CmsContentSession(this, cmsSession.getSubject(), locale); + final CmsContentSession newContentSession = new CmsContentSession(this, cmsSession.uuid(), + cmsSession.getSubject(), locale, uuidFactory); cmsSession.addOnCloseCallback((c) -> { newContentSession.close(); userSessions.remove(cmsSession); @@ -57,7 +78,20 @@ public class CmsContentRepository extends AbstractContentRepository { throw new RuntimeException("Could not login as data admin", e1); } finally { } - return new CmsContentSession(this, loginContext.getSubject(), Locale.getDefault()); + return new CmsContentSession(this, getCmsState().getUuid(), loginContext.getSubject(), Locale.getDefault(), + uuidFactory); + } + + protected CmsState getCmsState() { + return cmsState; + } + + public void setCmsState(CmsState cmsState) { + this.cmsState = cmsState; + } + + public void setUuidFactory(UuidFactory uuidFactory) { + this.uuidFactory = uuidFactory; } }