1 package org
.argeo
.cms
.acr
;
3 import java
.util
.Collections
;
4 import java
.util
.HashMap
;
5 import java
.util
.Locale
;
8 import javax
.security
.auth
.login
.LoginContext
;
9 import javax
.security
.auth
.login
.LoginException
;
11 import org
.argeo
.api
.acr
.ContentSession
;
12 import org
.argeo
.api
.acr
.spi
.ProvidedRepository
;
13 import org
.argeo
.api
.cms
.CmsAuth
;
14 import org
.argeo
.api
.cms
.CmsSession
;
15 import org
.argeo
.api
.cms
.CmsState
;
16 import org
.argeo
.api
.uuid
.UuidFactory
;
17 import org
.argeo
.cms
.auth
.CurrentUser
;
18 import org
.argeo
.cms
.internal
.runtime
.CmsContextImpl
;
21 * Multi-session {@link ProvidedRepository}, integrated with a CMS.
23 public class CmsContentRepository
extends AbstractContentRepository
{
24 public final static String RUN_BASE
= "/run";
25 public final static String DIRECTORY_BASE
= "/directory";
27 private Map
<CmsSession
, CmsContentSession
> userSessions
= Collections
.synchronizedMap(new HashMap
<>());
29 private CmsState cmsState
;
30 private UuidFactory uuidFactory
;
37 public ContentSession
get() {
38 return get(CmsContextImpl
.getCmsContext().getDefaultLocale());
42 public ContentSession
get(Locale locale
) {
43 // Subject subject = Subject.getSubject(AccessController.getContext());
44 CmsSession cmsSession
= CurrentUser
.getCmsSession();
45 CmsContentSession contentSession
= userSessions
.get(cmsSession
);
46 if (contentSession
== null) {
47 final CmsContentSession newContentSession
= new CmsContentSession(this, cmsSession
.getUuid(),
48 cmsSession
.getSubject(), locale
, uuidFactory
);
49 cmsSession
.addOnCloseCallback((c
) -> {
50 newContentSession
.close();
51 userSessions
.remove(cmsSession
);
53 contentSession
= newContentSession
;
55 return contentSession
;
59 protected CmsContentSession
newSystemSession() {
60 LoginContext loginContext
;
62 loginContext
= new LoginContext(CmsAuth
.DATA_ADMIN
.getLoginContextName());
64 } catch (LoginException e1
) {
65 throw new RuntimeException("Could not login as data admin", e1
);
68 return new CmsContentSession(this, getCmsState().getUuid(), loginContext
.getSubject(), Locale
.getDefault(),
72 protected CmsState
getCmsState() {
76 public void setCmsState(CmsState cmsState
) {
77 this.cmsState
= cmsState
;
80 public void setUuidFactory(UuidFactory uuidFactory
) {
81 this.uuidFactory
= uuidFactory
;