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
.cms
.auth
.CurrentUser
;
16 import org
.argeo
.cms
.internal
.runtime
.CmsContextImpl
;
19 * Multi-session {@link ProvidedRepository}, integrated with a CMS.
21 public class CmsContentRepository
extends AbstractContentRepository
{
23 private Map
<CmsSession
, CmsContentSession
> userSessions
= Collections
.synchronizedMap(new HashMap
<>());
30 public ContentSession
get() {
31 return get(CmsContextImpl
.getCmsContext().getDefaultLocale());
35 public ContentSession
get(Locale locale
) {
36 // Subject subject = Subject.getSubject(AccessController.getContext());
37 CmsSession cmsSession
= CurrentUser
.getCmsSession();
38 CmsContentSession contentSession
= userSessions
.get(cmsSession
);
39 if (contentSession
== null) {
40 final CmsContentSession newContentSession
= new CmsContentSession(this, cmsSession
.getSubject(), locale
);
41 cmsSession
.addOnCloseCallback((c
) -> {
42 newContentSession
.close();
43 userSessions
.remove(cmsSession
);
45 contentSession
= newContentSession
;
47 return contentSession
;
51 protected CmsContentSession
newSystemSession() {
52 LoginContext loginContext
;
54 loginContext
= new LoginContext(CmsAuth
.DATA_ADMIN
.getLoginContextName());
56 } catch (LoginException e1
) {
57 throw new RuntimeException("Could not login as data admin", e1
);
60 return new CmsContentSession(this, loginContext
.getSubject(), Locale
.getDefault());