]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/acr/CmsContentRepository.java
Remove naming exceptions from DNS browser
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / CmsContentRepository.java
1 package org.argeo.cms.acr;
2
3 import java.util.Collections;
4 import java.util.HashMap;
5 import java.util.Locale;
6 import java.util.Map;
7
8 import javax.security.auth.login.LoginContext;
9 import javax.security.auth.login.LoginException;
10
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;
19
20 /**
21 * Multi-session {@link ProvidedRepository}, integrated with a CMS.
22 */
23 public class CmsContentRepository extends AbstractContentRepository {
24 public final static String RUN_BASE = "/run";
25 public final static String DIRECTORY_BASE = "/directory";
26
27 private Map<CmsSession, CmsContentSession> userSessions = Collections.synchronizedMap(new HashMap<>());
28
29 private CmsState cmsState;
30 private UuidFactory uuidFactory;
31
32 /*
33 * REPOSITORY
34 */
35
36 @Override
37 public ContentSession get() {
38 return get(CmsContextImpl.getCmsContext().getDefaultLocale());
39 }
40
41 @Override
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);
52 });
53 contentSession = newContentSession;
54 }
55 return contentSession;
56 }
57
58 @Override
59 protected CmsContentSession newSystemSession() {
60 LoginContext loginContext;
61 try {
62 loginContext = new LoginContext(CmsAuth.DATA_ADMIN.getLoginContextName());
63 loginContext.login();
64 } catch (LoginException e1) {
65 throw new RuntimeException("Could not login as data admin", e1);
66 } finally {
67 }
68 return new CmsContentSession(this, getCmsState().getUuid(), loginContext.getSubject(), Locale.getDefault(),
69 uuidFactory);
70 }
71
72 protected CmsState getCmsState() {
73 return cmsState;
74 }
75
76 public void setCmsState(CmsState cmsState) {
77 this.cmsState = cmsState;
78 }
79
80 public void setUuidFactory(UuidFactory uuidFactory) {
81 this.uuidFactory = uuidFactory;
82 }
83
84 }