X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Fauth%2FCmsAuthUtils.java;h=46adcf8a516db80a509476947cbcb4c9ee5cd364;hb=c2366f32052deada7d96f635e86f745f438f094e;hp=72676611e4e43f631429c52e8b31a6a0893e4529;hpb=b843d903237a2a4192c40d8c933e71137284050b;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/auth/CmsAuthUtils.java b/org.argeo.cms/src/org/argeo/cms/auth/CmsAuthUtils.java index 72676611e..46adcf8a5 100644 --- a/org.argeo.cms/src/org/argeo/cms/auth/CmsAuthUtils.java +++ b/org.argeo.cms/src/org/argeo/cms/auth/CmsAuthUtils.java @@ -19,6 +19,7 @@ import org.argeo.api.cms.CmsConstants; import org.argeo.cms.internal.auth.CmsSessionImpl; import org.argeo.cms.internal.auth.ImpliedByPrincipal; import org.argeo.cms.internal.http.WebCmsSessionImpl; +import org.argeo.cms.internal.runtime.CmsContextImpl; import org.argeo.cms.security.NodeSecurityUtils; import org.argeo.osgi.useradmin.AuthenticatingUser; import org.osgi.framework.BundleContext; @@ -136,7 +137,7 @@ class CmsAuthUtils { request.setAttribute(HttpContext.AUTHORIZATION, authorization); CmsSessionImpl cmsSession; - CmsSessionImpl currentLocalSession = CmsSessionImpl.getByLocalId(httpSessId); + CmsSessionImpl currentLocalSession = CmsContextImpl.getCmsContext().getCmsSessionByLocalId(httpSessId); if (currentLocalSession != null) { boolean currentLocalSessionAnonymous = currentLocalSession.getAuthorization().getName() == null; if (!anonymous) { @@ -165,6 +166,7 @@ class CmsAuthUtils { } else { // new CMS session cmsSession = new WebCmsSessionImpl(subject, authorization, locale, request); + CmsContextImpl.getCmsContext().registerCmsSession(cmsSession); } if (cmsSession == null)// should be dead code (cf. SuppressWarning of the method) @@ -181,33 +183,34 @@ class CmsAuthUtils { } } else { CmsSessionImpl cmsSession = new CmsSessionImpl(subject, authorization, locale, "desktop"); + CmsContextImpl.getCmsContext().registerCmsSession(cmsSession); CmsSessionId nodeSessionId = new CmsSessionId(cmsSession.getUuid()); subject.getPrivateCredentials().add(nodeSessionId); } } - public static CmsSessionImpl cmsSessionFromHttpSession(BundleContext bc, String httpSessionId) { - Authorization authorization = null; - Collection> sr; - try { - sr = bc.getServiceReferences(CmsSession.class, - "(" + CmsSession.SESSION_LOCAL_ID + "=" + httpSessionId + ")"); - } catch (InvalidSyntaxException e) { - throw new IllegalArgumentException("Cannot get CMS session for id " + httpSessionId, e); - } - CmsSessionImpl cmsSession; - if (sr.size() == 1) { - cmsSession = (CmsSessionImpl) bc.getService(sr.iterator().next()); -// locale = cmsSession.getLocale(); - authorization = cmsSession.getAuthorization(); - if (authorization.getName() == null) - return null;// anonymous is not sufficient - } else if (sr.size() == 0) - return null; - else - throw new IllegalStateException(sr.size() + ">1 web sessions detected for http session " + httpSessionId); - return cmsSession; - } +// public static CmsSessionImpl cmsSessionFromHttpSession(BundleContext bc, String httpSessionId) { +// Authorization authorization = null; +// Collection> sr; +// try { +// sr = bc.getServiceReferences(CmsSession.class, +// "(" + CmsSession.SESSION_LOCAL_ID + "=" + httpSessionId + ")"); +// } catch (InvalidSyntaxException e) { +// throw new IllegalArgumentException("Cannot get CMS session for id " + httpSessionId, e); +// } +// CmsSessionImpl cmsSession; +// if (sr.size() == 1) { +// cmsSession = (CmsSessionImpl) bc.getService(sr.iterator().next()); +//// locale = cmsSession.getLocale(); +// authorization = cmsSession.getAuthorization(); +// if (authorization.getName() == null) +// return null;// anonymous is not sufficient +// } else if (sr.size() == 0) +// return null; +// else +// throw new IllegalStateException(sr.size() + ">1 web sessions detected for http session " + httpSessionId); +// return cmsSession; +// } public static T getSinglePrincipal(Subject subject, Class clss) { Set principals = subject.getPrincipals(clss);