- 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)
+ CmsSessionImpl cmsSession;
+ CmsSessionImpl currentLocalSession = CmsSessionImpl.getByLocalId(httpSessId);
+ if (currentLocalSession != null) {
+ boolean currentLocalSessionAnonymous = currentLocalSession.getAuthorization().getName() == null;
+ if (!anonymous) {
+ if (currentLocalSessionAnonymous) {
+ currentLocalSession.close();
+ // new CMS session
+ cmsSession = new WebCmsSessionImpl(subject, authorization, locale, request);
+ } else if (!authorization.getName().equals(currentLocalSession.getAuthorization().getName())) {
+ throw new IllegalStateException("Inconsistent user " + authorization.getName()
+ + " for existing CMS session " + currentLocalSession);
+ } else {
+ // keep current session
+ cmsSession = currentLocalSession;
+ // keyring