- CmsSession cmsSession = CmsSessionImpl.getByLocalId(httpSessId);
- if (cmsSession == null)
- cmsSession = new WebCmsSessionImpl(subject, authorization, httpSessId);
- request.setAttribute(CmsSession.class.getName(), cmsSession);
- // else
- // throw new CmsException("Already a CMS session registered for
- // "+httpSessId);
-
- // if (httpSession.getAttribute(HttpContext.AUTHORIZATION) == null)
- // {
-
- // Collection<ServiceReference<CmsSession>> sr;
- // try {
- // sr = bc.getServiceReferences(CmsSession.class,
- // "(" + CmsSession.SESSION_LOCAL_ID + "=" + httpSessId + ")");
- // } catch (InvalidSyntaxException e) {
- // throw new CmsException("Cannot get CMS session for id " +
- // httpSessId, e);
- // }
- // ServiceReference<CmsSession> cmsSessionRef;
- // if (sr.size() == 1) {
- // cmsSessionRef = sr.iterator().next();
- // } else if (sr.size() == 0) {
- // WebCmsSessionImpl cmsSessionImpl = new WebCmsSessionImpl(subject,
- // authorization, httpSessId);
- // cmsSessionRef =
- // cmsSessionImpl.getServiceRegistration().getReference();
- // if (log.isDebugEnabled())
- // log.debug("Initialized " + cmsSessionImpl + " for " +
- // authorization.getName());
- // } else
- // throw new CmsException(sr.size() + " CMS sessions registered for
- // " + httpSessId);
- //
- // cmsSession = (CmsSession) bc.getService(cmsSessionRef);
- // cmsSession.addHttpSession(request);
- // if (log.isTraceEnabled())
- // log.trace("Added " + request.getServletPath() + " to " +
- // cmsSession + " (" + request.getRequestURI()
- // + ")");
- // httpSession.setAttribute(HttpContext.REMOTE_USER,
- // authorization.getName());
- // httpSession.setAttribute(HttpContext.AUTHORIZATION,
- // authorization);
- CmsSessionId nodeSessionId = new CmsSessionId(cmsSession.getUuid());
- if (subject.getPrivateCredentials(CmsSessionId.class).size() == 0)
- subject.getPrivateCredentials().add(nodeSessionId);
- else {
- UUID storedSessionId = subject.getPrivateCredentials(CmsSessionId.class).iterator().next().getUuid();
- // if (storedSessionId.equals(httpSessionId.getValue()))
- throw new CmsException(
- "Subject already logged with session " + storedSessionId + " (not " + nodeSessionId + ")");
+ CmsSessionImpl cmsSession = CmsSessionImpl.getByLocalId(httpSessId);
+ if (cmsSession != null) {
+ if (authorization.getName() != null) {
+ if (cmsSession.getAuthorization().getName() == null) {
+ cmsSession.close();
+ cmsSession = null;
+ } else if (!authorization.getName().equals(cmsSession.getAuthorization().getName())) {
+ throw new CmsException("Inconsistent user " + authorization.getName()
+ + " for existing CMS session " + cmsSession);
+ }
+ // keyring
+ if (cmsSession != null)
+ subject.getPrivateCredentials().addAll(cmsSession.getSecretKeys());
+ } else {// anonymous
+ if (cmsSession.getAuthorization().getName() != null) {
+ cmsSession.close();
+ // TODO rather throw an exception ? log a warning ?
+ cmsSession = null;
+ }
+ }
+ } else if (cmsSession == null) {
+ cmsSession = new WebCmsSessionImpl(subject, authorization, locale, request);
+ }
+ // request.setAttribute(CmsSession.class.getName(), cmsSession);
+ if (cmsSession != null) {
+ CmsSessionId nodeSessionId = new CmsSessionId(cmsSession.getUuid());
+ if (subject.getPrivateCredentials(CmsSessionId.class).size() == 0)
+ subject.getPrivateCredentials().add(nodeSessionId);
+ else {
+ UUID storedSessionId = subject.getPrivateCredentials(CmsSessionId.class).iterator().next()
+ .getUuid();
+ // if (storedSessionId.equals(httpSessionId.getValue()))
+ throw new CmsException(
+ "Subject already logged with session " + storedSessionId + " (not " + nodeSessionId + ")");
+ }