- HttpSession httpSession = request.getSession(false);
- assert httpSession != null;
- String httpSessId = httpSession.getId();
- String remoteUser = authorization.getName() != null ? authorization.getName()
- : NodeConstants.ROLE_ANONYMOUS;
- request.setAttribute(HttpContext.REMOTE_USER, remoteUser);
- request.setAttribute(HttpContext.AUTHORIZATION, authorization);
-
- 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())) {
+ RemoteAuthSession httpSession = request.getSession();
+ String httpSessId = httpSession != null ? httpSession.getId() : null;
+ boolean anonymous = authorization.getName() == null;
+ String remoteUser = !anonymous ? authorization.getName() : CmsConstants.ROLE_ANONYMOUS;
+ request.setAttribute(RemoteAuthRequest.REMOTE_USER, remoteUser);
+ request.setAttribute(RemoteAuthRequest.AUTHORIZATION, authorization);
+
+ CmsSessionImpl cmsSession;
+ CmsSessionImpl currentLocalSession = CmsContextImpl.getCmsContext().getCmsSessionByLocalId(httpSessId);
+ if (currentLocalSession != null) {
+ boolean currentLocalSessionAnonymous = currentLocalSession.isAnonymous();
+ if (!anonymous) {
+ if (currentLocalSessionAnonymous) {
+ currentLocalSession.close();
+ // new CMS session
+ UUID cmsSessionUuid = CmsContextImpl.getCmsContext().getUuidFactory().timeUUID();
+ cmsSession = new RemoteCmsSessionImpl(cmsSessionUuid, subject, authorization, locale, request);
+ CmsContextImpl.getCmsContext().registerCmsSession(cmsSession);
+ } else if (!authorization.getName().equals(currentLocalSession.getAuthorization().getName())) {