Remove dependency between CMS and CMS UI
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 8 Apr 2017 12:48:24 +0000 (14:48 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 8 Apr 2017 12:48:24 +0000 (14:48 +0200)
19 files changed:
org.argeo.cms.ui/src/org/argeo/cms/ui/AbstractCmsEntryPoint.java
org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java
org.argeo.cms.ui/src/org/argeo/cms/util/CmsUtils.java
org.argeo.cms.ui/src/org/argeo/cms/util/LoginEntryPoint.java
org.argeo.cms.ui/src/org/argeo/cms/util/OpenUserMenu.java [deleted file]
org.argeo.cms.ui/src/org/argeo/cms/util/SimpleApp.java
org.argeo.cms.ui/src/org/argeo/cms/widgets/auth/CmsLogin.java
org.argeo.cms/src/org/argeo/cms/auth/AnonymousLoginModule.java
org.argeo.cms/src/org/argeo/cms/auth/CmsAuthUtils.java
org.argeo.cms/src/org/argeo/cms/auth/CmsAuthenticated.java [deleted file]
org.argeo.cms/src/org/argeo/cms/auth/CmsSession.java
org.argeo.cms/src/org/argeo/cms/auth/CurrentUser.java
org.argeo.cms/src/org/argeo/cms/auth/HttpRequestCallbackHandler.java
org.argeo.cms/src/org/argeo/cms/auth/HttpSessionLoginModule.java
org.argeo.cms/src/org/argeo/cms/auth/UserAdminLoginModule.java
org.argeo.cms/src/org/argeo/cms/i18n/LocaleUtils.java
org.argeo.cms/src/org/argeo/cms/internal/auth/CmsSessionImpl.java
org.argeo.cms/src/org/argeo/cms/internal/http/CmsSessionProvider.java
org.argeo.cms/src/org/argeo/cms/internal/http/WebCmsSessionImpl.java

index 99989db19c0cdb58835d1b3ac218a864f3e53415..2d83f8ded0ab2c60f80fcb9641c2f09e53b8edbc 100644 (file)
@@ -21,7 +21,6 @@ import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.CmsException;
 import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.auth.HttpRequestCallbackHandler;
-import org.argeo.cms.auth.CmsAuthenticated;
 import org.argeo.eclipse.ui.specific.UiContext;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.node.NodeConstants;
@@ -110,7 +109,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
 
        @Override
        protected final void createContents(final Composite parent) {
-               UiContext.setData(CmsAuthenticated.KEY, this);
+               UiContext.setData(CmsView.KEY, this);
                Subject.doAs(getSubject(), new PrivilegedAction<Void>() {
                        @Override
                        public Void run() {
@@ -167,10 +166,15 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
        // public LoginContext getLoginContext() {
        // return loginContext;
        // }
-       public Subject getSubject() {
+       protected Subject getSubject() {
                return loginContext.getSubject();
        }
 
+       @Override
+       public boolean isAnonymous() {
+               return CurrentUser.isAnonymous(getSubject());
+       }
+
        @Override
        public synchronized void logout() {
                if (loginContext == null)
@@ -341,7 +345,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
                @Override
                public void navigated(BrowserNavigationEvent event) {
                        setState(event.getState());
-                       refresh();
+                       doRefresh();
                }
        }
 }
\ No newline at end of file
index 51f6acc8cb770e37be2c353123b2368fb701c8d1..6d70935d7e4a0ffd9d8205cac0404dc97fdbf2ff 100644 (file)
@@ -2,10 +2,10 @@ package org.argeo.cms.ui;
 
 import javax.security.auth.login.LoginContext;
 
-import org.argeo.cms.auth.CmsAuthenticated;
+/** Provides interaction with the CMS system. */
+public interface CmsView {
+       String KEY = "org.argeo.cms.ui.view";
 
-/** Provides interaction with the CMS system. UNSTABLE API at this stage. */
-public interface CmsView extends CmsAuthenticated {
        UxContext getUxContext();
 
        // NAVIGATION
@@ -15,11 +15,13 @@ public interface CmsView extends CmsAuthenticated {
        void authChange(LoginContext loginContext);
 
        void logout();
-       
-//     void registerCallbackHandler(CallbackHandler callbackHandler);
+
+       // void registerCallbackHandler(CallbackHandler callbackHandler);
 
        // SERVICES
        void exception(Throwable e);
 
        CmsImageManager getImageManager();
+
+       boolean isAnonymous();
 }
index 3bb984b6a86bfff20ec7a6d2d5aea92ead954859..2a4d9141b234b4dd258d77908da255197d648282 100644 (file)
@@ -10,7 +10,6 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.io.IOUtils;
 import org.argeo.cms.CmsException;
-import org.argeo.cms.auth.CmsAuthenticated;
 import org.argeo.cms.ui.CmsConstants;
 import org.argeo.cms.ui.CmsView;
 import org.argeo.eclipse.ui.specific.UiContext;
@@ -41,7 +40,7 @@ public class CmsUtils implements CmsConstants {
         * this call.
         */
        public static CmsView getCmsView() {
-               return UiContext.getData(CmsAuthenticated.KEY);
+               return UiContext.getData(CmsView.KEY);
        }
 
        public static StringBuilder getServerBaseUrl(HttpServletRequest request) {
index a43b9ee92723f1fb28b15604e62a74b56bf32378..b7bf9103ab7ce2f0bd9398a596e2012cbba4d936 100644 (file)
@@ -11,7 +11,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.CmsException;
 import org.argeo.cms.auth.CurrentUser;
-import org.argeo.cms.auth.CmsAuthenticated;
 import org.argeo.cms.ui.CmsImageManager;
 import org.argeo.cms.ui.CmsView;
 import org.argeo.cms.ui.UxContext;
@@ -35,7 +34,7 @@ public class LoginEntryPoint implements EntryPoint, CmsView {
        @Override
        public int createUI() {
                final Display display = createDisplay();
-               UiContext.setData(CmsAuthenticated.KEY, this);
+               UiContext.setData(CmsView.KEY, this);
                CmsLoginShell loginShell = createCmsLoginShell();
                try {
                        // try pre-auth
@@ -67,7 +66,7 @@ public class LoginEntryPoint implements EntryPoint, CmsView {
                        }
                }
 
-               if (CurrentUser.getUsername() == null)
+               if (CurrentUser.getUsername(getSubject()) == null)
                        return -1;
                uxContext = new SimpleUxContext();
                return postLogin();
@@ -160,10 +159,15 @@ public class LoginEntryPoint implements EntryPoint, CmsView {
        // return loginContext;
        // }
 
-       public Subject getSubject() {
+       protected Subject getSubject() {
                return loginContext.getSubject();
        }
 
+       @Override
+       public boolean isAnonymous() {
+               return CurrentUser.isAnonymous(getSubject());
+       }
+
        @Override
        public CmsImageManager getImageManager() {
                // TODO Auto-generated method stub
diff --git a/org.argeo.cms.ui/src/org/argeo/cms/util/OpenUserMenu.java b/org.argeo.cms.ui/src/org/argeo/cms/util/OpenUserMenu.java
deleted file mode 100644 (file)
index 7853146..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.argeo.cms.util;
-
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.widgets.Control;
-
-/** Open the user menu when clicked */
-@Deprecated
-public class OpenUserMenu extends MouseAdapter {
-       private static final long serialVersionUID = 3634864186295639792L;
-
-       @Override
-       public void mouseDown(MouseEvent e) {
-               if (e.button == 1) {
-                       new UserMenu((Control) e.getSource());
-               }
-       }
-}
\ No newline at end of file
index 51aafcb23794d3295b2b846c82ba50e980d1389d..780a01d184c4dfbd3dded5fb74f4c094aca2d343 100644 (file)
@@ -23,6 +23,7 @@ import org.argeo.cms.ui.CmsConstants;
 import org.argeo.cms.ui.CmsUiProvider;
 import org.argeo.cms.ui.LifeCycleUiProvider;
 import org.argeo.jcr.JcrUtils;
+import org.argeo.node.NodeConstants;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.application.Application;
 import org.eclipse.rap.rwt.application.Application.OperationMode;
@@ -58,8 +59,8 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
        private Repository repository;
        private String workspace = null;
        private String jcrBasePath = "/";
-       private List<String> roPrincipals = Arrays.asList("anonymous", "everyone");
-       private List<String> rwPrincipals = Arrays.asList("everyone");
+       private List<String> roPrincipals = Arrays.asList(NodeConstants.ROLE_ANONYMOUS, NodeConstants.ROLE_USER);
+       private List<String> rwPrincipals = Arrays.asList(NodeConstants.ROLE_USER);
 
        private CmsUiProvider header;
        private Map<String, CmsUiProvider> pages = new LinkedHashMap<String, CmsUiProvider>();
@@ -151,9 +152,10 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                try {
                        session = JcrUtils.loginOrCreateWorkspace(repository, workspace);
                        VersionManager vm = session.getWorkspace().getVersionManager();
-                       if (!vm.isCheckedOut("/"))
-                               vm.checkout("/");
                        JcrUtils.mkdirs(session, jcrBasePath);
+                       session.save();
+                       if (!vm.isCheckedOut(jcrBasePath))
+                               vm.checkout(jcrBasePath);
                        for (String principal : rwPrincipals)
                                JcrUtils.addPrivilege(session, jcrBasePath, principal, Privilege.JCR_WRITE);
                        for (String principal : roPrincipals)
index f25ad19e2398b3cc5d900cd6b03b04814b07cfe5..4af348059fa30fe528a676eda78336f8090aa866 100644 (file)
@@ -19,7 +19,6 @@ import javax.security.auth.login.LoginException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.CmsMsg;
-import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.auth.HttpRequestCallback;
 import org.argeo.cms.i18n.LocaleUtils;
 import org.argeo.cms.ui.CmsStyles;
@@ -79,7 +78,7 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
        }
 
        protected boolean isAnonymous() {
-               return CurrentUser.isAnonymous(cmsView.getSubject());
+               return cmsView.isAnonymous();
        }
 
        public final void createUi(Composite parent) {
@@ -246,12 +245,12 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
 
        protected boolean login() {
                // Subject subject = cmsView.getLoginContext().getSubject();
-//             LoginContext loginContext = cmsView.getLoginContext();
+               // LoginContext loginContext = cmsView.getLoginContext();
                try {
                        //
                        // LOGIN
                        //
-//                     loginContext.logout();
+                       // loginContext.logout();
                        LoginContext loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, this);
                        loginContext.login();
                        cmsView.authChange(loginContext);
index 7a1283afa9d7cc72ed93b50eafb07320ce7e4ff1..1ac4545fcb0ac950056fc45e647310a0fcbbfbf8 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.cms.auth;
 
+import java.util.Locale;
 import java.util.Map;
 
 import javax.security.auth.Subject;
@@ -49,8 +50,11 @@ public class AnonymousLoginModule implements LoginModule {
        public boolean commit() throws LoginException {
                UserAdmin userAdmin = bc.getService(bc.getServiceReference(UserAdmin.class));
                Authorization authorization = userAdmin.getAuthorization(null);
-               CmsAuthUtils.addAuthorization(subject, authorization,
-                               (HttpServletRequest) sharedState.get(CmsAuthUtils.SHARED_STATE_HTTP_REQUEST));
+               HttpServletRequest request = (HttpServletRequest) sharedState.get(CmsAuthUtils.SHARED_STATE_HTTP_REQUEST);
+               Locale locale = Locale.getDefault();
+               if (request != null)
+                       locale = request.getLocale();
+               CmsAuthUtils.addAuthorization(subject, authorization, locale, request);
                if (log.isDebugEnabled())
                        log.debug("Anonymous logged in to CMS: " + subject);
                return true;
index 33a8dc62eb4a4979299bbadf501ac7cc0002f4d8..6fa7bd2a1c343d03e3b73ed14018175c8c43ad77 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.cms.auth;
 
 import java.security.Principal;
+import java.util.Locale;
 import java.util.Set;
 import java.util.UUID;
 
@@ -42,7 +43,8 @@ class CmsAuthUtils {
        final static String HEADER_AUTHORIZATION = "Authorization";
        final static String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
 
-       static void addAuthorization(Subject subject, Authorization authorization, HttpServletRequest request) {
+       static void addAuthorization(Subject subject, Authorization authorization, Locale locale,
+                       HttpServletRequest request) {
                assert subject != null;
                checkSubjectEmpty(subject);
                assert authorization != null;
@@ -87,7 +89,7 @@ class CmsAuthUtils {
                        throw new CmsException("Cannot commit", e);
                }
 
-               registerSessionAuthorization(request, subject, authorization);
+               registerSessionAuthorization(request, subject, authorization, locale);
        }
 
        private static void checkSubjectEmpty(Subject subject) {
@@ -116,7 +118,7 @@ class CmsAuthUtils {
        }
 
        private static void registerSessionAuthorization(HttpServletRequest request, Subject subject,
-                       Authorization authorization) {
+                       Authorization authorization, Locale locale) {
                if (request != null) {
                        HttpSession httpSession = request.getSession(false);
                        String httpSessId = httpSession.getId();
@@ -125,7 +127,7 @@ class CmsAuthUtils {
                        request.setAttribute(HttpContext.REMOTE_USER, remoteUser);
                        request.setAttribute(HttpContext.AUTHORIZATION, authorization);
 
-                       CmsSessionImpl cmsSession = (CmsSessionImpl) CmsSessionImpl.getByLocalId(httpSessId);
+                       CmsSessionImpl cmsSession = CmsSessionImpl.getByLocalId(httpSessId);
                        if (cmsSession != null) {
                                if (authorization.getName() != null) {
                                        if (cmsSession.getAuthorization().getName() == null) {
@@ -146,7 +148,7 @@ class CmsAuthUtils {
                        }
 
                        if (cmsSession == null)
-                               cmsSession = new WebCmsSessionImpl(subject, authorization, request);
+                               cmsSession = new WebCmsSessionImpl(subject, authorization, locale, request);
                        // request.setAttribute(CmsSession.class.getName(), cmsSession);
                        CmsSessionId nodeSessionId = new CmsSessionId(cmsSession.getUuid());
                        if (subject.getPrivateCredentials(CmsSessionId.class).size() == 0)
diff --git a/org.argeo.cms/src/org/argeo/cms/auth/CmsAuthenticated.java b/org.argeo.cms/src/org/argeo/cms/auth/CmsAuthenticated.java
deleted file mode 100644 (file)
index 704e933..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.argeo.cms.auth;
-
-import javax.security.auth.Subject;
-
-public interface CmsAuthenticated {
-       String KEY = "org.argeo.cms.authenticated";
-
-       Subject getSubject();
-//     LoginContext getLoginContext();
-
-}
index 118f875891a8782ed8248d6633b730bb689cc600..f6984bcc6c64433e631fd026f057651814f462c9 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.cms.auth;
 
 import java.time.ZonedDateTime;
+import java.util.Locale;
 import java.util.UUID;
 
 import javax.naming.ldap.LdapName;
@@ -27,6 +28,8 @@ public interface CmsSession {
 
        ZonedDateTime getCreationTime();
        ZonedDateTime getEnd();
+       
+       Locale getLocale();
 
        boolean isValid();
 
index 2f6325d279ccf687f82370771c8b5237746e3e19..450abd3cf6fd1ab736185593a413a90e5cd301ce 100644 (file)
@@ -32,7 +32,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.CmsException;
 import org.argeo.cms.internal.auth.CmsSessionImpl;
-import org.argeo.eclipse.ui.specific.UiContext;
 import org.argeo.node.NodeConstants;
 import org.osgi.service.useradmin.Authorization;
 
@@ -42,7 +41,8 @@ import org.osgi.service.useradmin.Authorization;
  */
 public final class CurrentUser {
        private final static Log log = LogFactory.getLog(CurrentUser.class);
-//     private final static BundleContext bc = FrameworkUtil.getBundle(CurrentUser.class).getBundleContext();
+       // private final static BundleContext bc =
+       // FrameworkUtil.getBundle(CurrentUser.class).getBundleContext();
        /*
         * CURRENT USER API
         */
@@ -124,28 +124,42 @@ public final class CurrentUser {
                String username = getUsername(subject);
                return username == null || username.equalsIgnoreCase(NodeConstants.ROLE_ANONYMOUS);
        }
+
+       public CmsSession getCmsSession() {
+               Subject subject = currentSubject();
+               CmsSessionId cmsSessionId = subject.getPrivateCredentials(CmsSessionId.class).iterator().next();
+               return CmsSessionImpl.getByUuid(cmsSessionId.getUuid());
+       }
+
        /*
         * HELPERS
         */
-
        private static Subject currentSubject() {
-               CmsAuthenticated cmsView = getNodeAuthenticated();
-               if (cmsView != null)
-                       return cmsView.getSubject();
-               Subject subject = Subject.getSubject(AccessController.getContext());
+               // CmsAuthenticated cmsView = getNodeAuthenticated();
+               // if (cmsView != null)
+               // return cmsView.getSubject();
+               Subject subject = getAccessControllerSubject();
                if (subject != null)
                        return subject;
                throw new CmsException("Cannot find related subject");
        }
 
+       private static Subject getAccessControllerSubject() {
+               return Subject.getSubject(AccessController.getContext());
+       }
+
+       // public static boolean isAuthenticated() {
+       // return getAccessControllerSubject() != null;
+       // }
+
        /**
         * The node authenticated component (typically a CMS view) related to this
         * display, or null if none is available from this call. <b>Not API: Only
         * for low-level access.</b>
         */
-       private static CmsAuthenticated getNodeAuthenticated() {
-               return UiContext.getData(CmsAuthenticated.KEY);
-       }
+       // private static CmsAuthenticated getNodeAuthenticated() {
+       // return UiContext.getData(CmsAuthenticated.KEY);
+       // }
 
        private static Authorization getAuthorization(Subject subject) {
                return subject.getPrivateCredentials(Authorization.class).iterator().next();
@@ -157,30 +171,8 @@ public final class CurrentUser {
                        nodeSessionId = subject.getPrivateCredentials(CmsSessionId.class).iterator().next().getUuid();
                else
                        return false;
-               CmsSessionImpl cmsSession = (CmsSessionImpl) CmsSessionImpl.getByUuid(nodeSessionId.toString());
+               CmsSessionImpl cmsSession = CmsSessionImpl.getByUuid(nodeSessionId.toString());
                cmsSession.close();
-               // Collection<ServiceReference<CmsSession>> srs;
-               // try {
-               // srs = bc.getServiceReferences(CmsSession.class, "(" +
-               // CmsSession.SESSION_UUID + "=" + nodeSessionId + ")");
-               // } catch (InvalidSyntaxException e) {
-               // throw new CmsException("Cannot retrieve CMS session #" +
-               // nodeSessionId, e);
-               // }
-               //
-               // if (srs.size() == 0) {
-               // // if (log.isTraceEnabled())
-               // // log.warn("No CMS web session found for http session " +
-               // // nodeSessionId);
-               // return false;
-               // } else if (srs.size() > 1)
-               // throw new CmsException(srs.size() + " CMS web sessions found for http
-               // session " + nodeSessionId);
-               //
-               // WebCmsSessionImpl cmsSession = (WebCmsSessionImpl)
-               // bc.getService(srs.iterator().next());
-//             cmsSession.cleanUp();
-               // subject.getPrivateCredentials().removeAll(subject.getPrivateCredentials(CmsSessionId.class));
                if (log.isDebugEnabled())
                        log.debug("Logged out CMS session " + cmsSession.getUuid());
                return true;
index 191a114523fd595c054df750b96d8c67169b6ebd..bcc403fa996c4060cc4e3baa27158a40392cf298 100644 (file)
@@ -4,6 +4,7 @@ import java.io.IOException;
 
 import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.LanguageCallback;
 import javax.security.auth.callback.UnsupportedCallbackException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -27,6 +28,8 @@ public class HttpRequestCallbackHandler implements CallbackHandler {
                        if (callback instanceof HttpRequestCallback) {
                                ((HttpRequestCallback) callback).setRequest(request);
                                ((HttpRequestCallback) callback).setResponse(response);
+                       } else if (callback instanceof LanguageCallback) {
+                               ((LanguageCallback) callback).setLocale(request.getLocale());
                        }
        }
 
index 9cf32974f536f62f50dc46b65f285cfde94a29eb..dd01e4b53d50e2653486b2b49a32cc85d0edd4bd 100644 (file)
@@ -111,7 +111,7 @@ public class HttpSessionLoginModule implements LoginModule {
                }
 
                if (authorization != null) {
-                       CmsAuthUtils.addAuthorization(subject, authorization, request);
+                       CmsAuthUtils.addAuthorization(subject, authorization, request.getLocale(), request);
                        cleanUp();
                        return true;
                } else {
index 7e95c951a3f8eb67f80f1970feda3712b5fcdbfb..52ac0970bf7cbb28c69af37cf283cc25d2e3e26c 100644 (file)
@@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.CmsException;
-import org.argeo.eclipse.ui.specific.UiContext;
 import org.argeo.naming.LdapAttrs;
 import org.argeo.osgi.useradmin.IpaUtils;
 import org.osgi.framework.BundleContext;
@@ -49,6 +48,7 @@ public class UserAdminLoginModule implements LoginModule {
        // private state
        private BundleContext bc;
        private User authenticatedUser = null;
+       private Locale locale;
 
        @SuppressWarnings("unchecked")
        @Override
@@ -107,10 +107,11 @@ public class UserAdminLoginModule implements LoginModule {
                        }
 
                        // i18n
-                       Locale locale = langCallback.getLocale();
+                       locale = langCallback.getLocale();
                        if (locale == null)
                                locale = Locale.getDefault();
-                       UiContext.setLocale(locale);
+                       // FIXME add it to Subject
+                       // UiContext.setLocale(locale);
 
                        username = nameCallback.getName();
                        if (username == null || username.trim().equals("")) {
@@ -173,7 +174,7 @@ public class UserAdminLoginModule implements LoginModule {
                                                "User admin found no authorization for authenticated user " + authenticatingUser.getName());
                }
                // Log and monitor new login
-               CmsAuthUtils.addAuthorization(subject, authorization,
+               CmsAuthUtils.addAuthorization(subject, authorization, locale,
                                (HttpServletRequest) sharedState.get(CmsAuthUtils.SHARED_STATE_HTTP_REQUEST));
                if (log.isDebugEnabled())
                        log.debug("Logged in to CMS: " + subject);
index 6253e585beeb50b25420f967157fc6d0e92718f9..700e731058037a26a2da15c998910b315523332c 100644 (file)
@@ -5,8 +5,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.ResourceBundle;
 
-import org.argeo.eclipse.ui.specific.UiContext;
-
 /** Utilities simplifying the development of localization enums. */
 public class LocaleUtils {
        public static Object local(Enum<?> en) {
@@ -21,10 +19,8 @@ public class LocaleUtils {
                return local(en, locale, resource, en.getClass().getClassLoader());
        }
 
-       public static Object local(Enum<?> en, Locale locale, String resource,
-                       ClassLoader classLoader) {
-               ResourceBundle rb = ResourceBundle.getBundle(resource, locale,
-                               classLoader);
+       public static Object local(Enum<?> en, Locale locale, String resource, ClassLoader classLoader) {
+               ResourceBundle rb = ResourceBundle.getBundle(resource, locale, classLoader);
                return rb.getString(en.name());
        }
 
@@ -41,7 +37,9 @@ public class LocaleUtils {
        }
 
        static Locale getCurrentLocale() {
-               return UiContext.getLocale();
+               // return UiContext.getLocale();
+               // FIXME look into Subject or settings
+               return Locale.getDefault();
        }
 
        /** Returns null if argument is null. */
index af29d25945c9eb6b34a084b31f0b6a48b892b83f..9b667717beaf80a60463d7f5068b87c99979798a 100644 (file)
@@ -10,6 +10,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.LinkedHashSet;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
@@ -50,6 +51,7 @@ public class CmsSessionImpl implements CmsSession {
 
        private final ZonedDateTime creationTime;
        private ZonedDateTime end;
+       private final Locale locale;
 
        private ServiceRegistration<CmsSession> serviceRegistration;
 
@@ -57,8 +59,9 @@ public class CmsSessionImpl implements CmsSession {
        private Set<String> dataSessionsInUse = new HashSet<>();
        private LinkedHashSet<Session> additionalDataSessions = new LinkedHashSet<>();
 
-       public CmsSessionImpl(Subject initialSubject, Authorization authorization, String localSessionId) {
+       public CmsSessionImpl(Subject initialSubject, Authorization authorization, Locale locale, String localSessionId) {
                this.creationTime = ZonedDateTime.now();
+               this.locale = locale;
                this.initialContext = Subject.doAs(initialSubject, new PrivilegedAction<AccessControlContext>() {
 
                        @Override
@@ -90,15 +93,17 @@ public class CmsSessionImpl implements CmsSession {
                serviceRegistration = bc.registerService(CmsSession.class, this, props);
        }
 
-       public synchronized void close() {
+       public void close() {
                end = ZonedDateTime.now();
                serviceRegistration.unregister();
 
-               // TODO check data session in use ?
-               for (String path : dataSessions.keySet())
-                       JcrUtils.logoutQuietly(dataSessions.get(path));
-               for (Session session : additionalDataSessions)
-                       JcrUtils.logoutQuietly(session);
+               synchronized (this) {
+                       // TODO check data session in use ?
+                       for (String path : dataSessions.keySet())
+                               JcrUtils.logoutQuietly(dataSessions.get(path));
+                       for (Session session : additionalDataSessions)
+                               JcrUtils.logoutQuietly(session);
+               }
 
                try {
                        LoginContext lc;
@@ -111,7 +116,7 @@ public class CmsSessionImpl implements CmsSession {
                } catch (LoginException e) {
                        log.warn("Could not logout " + getSubject() + ": " + e);
                }
-               notifyAll();
+               log.debug("Closed " + this);
        }
 
        private Subject getSubject() {
@@ -199,14 +204,6 @@ public class CmsSessionImpl implements CmsSession {
                return uuid;
        }
 
-       public String getLocalSessionId() {
-               return localSessionId;
-       }
-
-       public ServiceRegistration<CmsSession> getServiceRegistration() {
-               return serviceRegistration;
-       }
-
        @Override
        public LdapName getUserDn() {
                return userDn;
@@ -217,10 +214,16 @@ public class CmsSessionImpl implements CmsSession {
                return localSessionId;
        }
 
+       @Override
        public boolean isAnonymous() {
                return anonymous;
        }
 
+       @Override
+       public Locale getLocale() {
+               return locale;
+       }
+
        @Override
        public ZonedDateTime getCreationTime() {
                return creationTime;
@@ -235,7 +238,7 @@ public class CmsSessionImpl implements CmsSession {
                return "CMS Session " + userDn + " local=" + localSessionId + ", uuid=" + uuid;
        }
 
-       public static CmsSession getByLocalId(String localId) {
+       public static CmsSessionImpl getByLocalId(String localId) {
                Collection<ServiceReference<CmsSession>> sr;
                try {
                        sr = bc.getServiceReferences(CmsSession.class, "(" + CmsSession.SESSION_LOCAL_ID + "=" + localId + ")");
@@ -245,7 +248,7 @@ public class CmsSessionImpl implements CmsSession {
                ServiceReference<CmsSession> cmsSessionRef;
                if (sr.size() == 1) {
                        cmsSessionRef = sr.iterator().next();
-                       return bc.getService(cmsSessionRef);
+                       return (CmsSessionImpl) bc.getService(cmsSessionRef);
                } else if (sr.size() == 0) {
                        return null;
                } else
@@ -253,7 +256,7 @@ public class CmsSessionImpl implements CmsSession {
 
        }
 
-       public static CmsSession getByUuid(String uuid) {
+       public static CmsSessionImpl getByUuid(Object uuid) {
                Collection<ServiceReference<CmsSession>> sr;
                try {
                        sr = bc.getServiceReferences(CmsSession.class, "(" + CmsSession.SESSION_UUID + "=" + uuid + ")");
@@ -263,7 +266,7 @@ public class CmsSessionImpl implements CmsSession {
                ServiceReference<CmsSession> cmsSessionRef;
                if (sr.size() == 1) {
                        cmsSessionRef = sr.iterator().next();
-                       return bc.getService(cmsSessionRef);
+                       return (CmsSessionImpl) bc.getService(cmsSessionRef);
                } else if (sr.size() == 0) {
                        return null;
                } else
index 85390e62eeb414d9c0918ca6de106826da09c8bc..4f0c184dbc1b392031b3150a4aa7e8a2b72ccde1 100644 (file)
@@ -35,7 +35,7 @@ class CmsSessionProvider implements SessionProvider, Serializable {
        public Session getSession(HttpServletRequest request, Repository rep, String workspace)
                        throws javax.jcr.LoginException, ServletException, RepositoryException {
 
-               CmsSessionImpl cmsSession = (CmsSessionImpl) WebCmsSessionImpl.getCmsSession(request);
+               CmsSessionImpl cmsSession = WebCmsSessionImpl.getCmsSession(request);
                // if (cmsSession == null)
                // return anonymousSession(request, rep, workspace);
                if (log.isTraceEnabled()) {
index 3d5e3fe4c612d65781e5fe8196078dc4c05cafcb..1df7b1760cfb4471ca013ca3b564ec3b87929379 100644 (file)
@@ -1,10 +1,11 @@
 package org.argeo.cms.internal.http;
 
+import java.util.Locale;
+
 import javax.security.auth.Subject;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
-import org.argeo.cms.auth.CmsSession;
 import org.argeo.cms.internal.auth.CmsSessionImpl;
 import org.osgi.service.useradmin.Authorization;
 
@@ -14,8 +15,8 @@ public class WebCmsSessionImpl extends CmsSessionImpl {
 
        private HttpSession httpSession;
 
-       public WebCmsSessionImpl(Subject initialSubject, Authorization authorization, HttpServletRequest request) {
-               super(initialSubject, authorization, request.getSession(false).getId());
+       public WebCmsSessionImpl(Subject initialSubject, Authorization authorization, Locale locale, HttpServletRequest request) {
+               super(initialSubject, authorization, locale,request.getSession(false).getId());
                httpSession = request.getSession(false);
        }
 
@@ -31,7 +32,7 @@ public class WebCmsSessionImpl extends CmsSessionImpl {
                }
        }
 
-       public static CmsSession getCmsSession(HttpServletRequest request) {
+       public static CmsSessionImpl getCmsSession(HttpServletRequest request) {
                return CmsSessionImpl.getByLocalId(request.getSession(false).getId());
        }
 }