Prepare refactoring
authorBruno Sinou <bsinou@argeo.org>
Thu, 15 Sep 2016 10:49:13 +0000 (10:49 +0000)
committerBruno Sinou <bsinou@argeo.org>
Thu, 15 Sep 2016 10:49:13 +0000 (10:49 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@9156 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.cms.ui.workbench.rap/bnd.bnd
org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.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/src/org/argeo/cms/AbstractCmsEntryPoint.java
org.argeo.cms/src/org/argeo/cms/CmsView.java
org.argeo.cms/src/org/argeo/cms/auth/CurrentUser.java
org.argeo.node.api/src/org/argeo/node/NodeAuthenticated.java [new file with mode: 0644]
pom.xml

index e80b9ecaee06768681f5484ce23bfd3e03148ae3..9f4fc9245c5dfe372c13d627ab0234033066a907 100644 (file)
@@ -10,4 +10,5 @@ org.argeo.eclipse.ui.workbench.commands,\
 org.argeo.cms,\
 org.argeo.cms.auth,\
 org.argeo.security.ui,\
+org.argeo.node,\
 *
index 14f3755ff9c4bbe4b1ca526860fb466bf5fbd5ba..bd5052c5b9a79f1bf1b548e23a31fc7a0db09ffe 100644 (file)
@@ -12,7 +12,6 @@ import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.CmsException;
 import org.argeo.cms.CmsStyles;
 import org.argeo.cms.CmsUiProvider;
-import org.eclipse.gemini.blueprint.context.BundleContextAware;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.service.ResourceManager;
 import org.eclipse.swt.SWT;
@@ -23,12 +22,13 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
 import org.osgi.framework.BundleContext;
-import org.springframework.beans.factory.InitializingBean;
+import org.osgi.framework.FrameworkUtil;
 
 /** A link to an internal or external location. */
-public class CmsLink implements CmsUiProvider, InitializingBean,
-               BundleContextAware {
+public class CmsLink implements CmsUiProvider {
        private final static Log log = LogFactory.getLog(CmsLink.class);
+       private BundleContext bc = FrameworkUtil.getBundle(getClass())
+                       .getBundleContext();
 
        private String label;
        private String custom;
@@ -42,8 +42,6 @@ public class CmsLink implements CmsUiProvider, InitializingBean,
        // private Boolean isUrl = false;
        private Integer imageWidth, imageHeight;
 
-       private BundleContext bundleContext;
-
        public CmsLink() {
                super();
        }
@@ -57,24 +55,10 @@ public class CmsLink implements CmsUiProvider, InitializingBean,
                this.label = label;
                this.target = target;
                this.custom = custom;
-               afterPropertiesSet();
+               init();
        }
 
-       @Override
-       public void afterPropertiesSet() {
-               // if (target != null) {
-               // if (target.startsWith("/")) {
-               // isUrl = true;
-               // } else {
-               // try {
-               // new URL(target);
-               // isUrl = true;
-               // } catch (MalformedURLException e1) {
-               // isUrl = false;
-               // }
-               // }
-               // }
-
+       public void init() {
                if (image != null) {
                        ImageData image = loadImage();
                        imageWidth = image.width;
@@ -190,10 +174,7 @@ public class CmsLink implements CmsUiProvider, InitializingBean,
                        // pure URL
                        url = new URL(image);
                } catch (MalformedURLException e1) {
-                       // in OSGi bundle
-                       if (bundleContext == null)
-                               throw new CmsException("No bundle context available");
-                       url = bundleContext.getBundle().getResource(image);
+                       url = bc.getBundle().getResource(image);
                }
 
                if (url == null)
@@ -224,11 +205,6 @@ public class CmsLink implements CmsUiProvider, InitializingBean,
                this.image = image;
        }
 
-       @Override
-       public void setBundleContext(BundleContext bundleContext) {
-               this.bundleContext = bundleContext;
-       }
-
        public void setMouseListener(MouseListener mouseListener) {
                this.mouseListener = mouseListener;
        }
@@ -245,30 +221,4 @@ public class CmsLink implements CmsUiProvider, InitializingBean,
                                        + " (must be: top, bottom or center)");
                }
        }
-
-       // private class MListener extends MouseAdapter {
-       // private static final long serialVersionUID = 3634864186295639792L;
-       //
-       // @Override
-       // public void mouseDown(MouseEvent e) {
-       // if (e.button == 1) {
-       // }
-       // }
-       // }
-       //
-       // private class DListener implements DisposeListener {
-       // private static final long serialVersionUID = -3808587499269394812L;
-       // private final Image img;
-       //
-       // public DListener(Image img) {
-       // super();
-       // this.img = img;
-       // }
-       //
-       // @Override
-       // public void widgetDisposed(DisposeEvent event) {
-       // img.dispose();
-       // }
-       //
-       // }
 }
index 78279cd4b1cc951f904de4480dcaca430ae12001..5ebfeb831917d130e4f23b46e311661c71b47f02 100644 (file)
@@ -20,6 +20,7 @@ import org.argeo.cms.auth.AuthConstants;
 import org.argeo.eclipse.ui.specific.UiContext;
 import org.argeo.jcr.ArgeoJcrConstants;
 import org.argeo.jcr.JcrUtils;
+import org.argeo.node.NodeAuthenticated;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.service.ResourceManager;
 import org.eclipse.swt.SWT;
@@ -44,7 +45,7 @@ public class CmsUtils implements CmsConstants {
         * this call.
         */
        public static CmsView getCmsView() {
-               return UiContext.getData(CmsView.KEY);
+               return UiContext.getData(NodeAuthenticated.KEY);
        }
 
        public static StringBuilder getServerBaseUrl(HttpServletRequest request) {
index 07a139730ab9045a864db174cddba18399c9cad5..2dea8d3f7e6eb04b896006a80963a3110226b80d 100644 (file)
@@ -18,6 +18,7 @@ import org.argeo.cms.auth.HttpRequestCallbackHandler;
 import org.argeo.cms.widgets.auth.CmsLogin;
 import org.argeo.cms.widgets.auth.CmsLoginShell;
 import org.argeo.eclipse.ui.specific.UiContext;
+import org.argeo.node.NodeAuthenticated;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.application.EntryPoint;
 import org.eclipse.swt.events.SelectionListener;
@@ -33,7 +34,7 @@ public class LoginEntryPoint implements EntryPoint, CmsView {
        @Override
        public int createUI() {
                final Display display = createDisplay();
-               UiContext.setData(CmsView.KEY, this);
+               UiContext.setData(NodeAuthenticated.KEY, this);
                try {
                        // try pre-auth
                        loginContext = new LoginContext(AuthConstants.LOGIN_CONTEXT_USER,
index 743a142a4430c4e4e7e2253ce012439a3c04ce0c..2632a140996a48a708367efd9f84779458499b02 100644 (file)
@@ -23,6 +23,7 @@ import org.argeo.cms.auth.AuthConstants;
 import org.argeo.cms.auth.HttpRequestCallbackHandler;
 import org.argeo.eclipse.ui.specific.UiContext;
 import org.argeo.jcr.JcrUtils;
+import org.argeo.node.NodeAuthenticated;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.application.AbstractEntryPoint;
 import org.eclipse.rap.rwt.client.WebClient;
@@ -107,7 +108,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
 
        @Override
        protected final void createContents(final Composite parent) {
-               UiContext.setData(CmsView.KEY, this);
+               UiContext.setData(NodeAuthenticated.KEY, this);
                Subject.doAs(subject, new PrivilegedAction<Void>() {
                        @Override
                        public Void run() {
index 75cefd1c03687aad342dbc26159c465703427484..ad4796e22b0fbdbdea3c17e09f6b647c5119b145 100644 (file)
@@ -1,26 +1,23 @@
 package org.argeo.cms;
 
-import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
 
-/** Provides interaction with the CMS system. UNSTABLE API at this stage. */
-public interface CmsView {
-       public final static String KEY = "org.argeo.cms.view";
+import org.argeo.node.NodeAuthenticated;
 
+/** Provides interaction with the CMS system. UNSTABLE API at this stage. */
+public interface CmsView extends NodeAuthenticated {
        UxContext getUxContext();
 
        // NAVIGATION
-       public void navigateTo(String state);
+       void navigateTo(String state);
 
        // SECURITY
-       public void authChange(LoginContext loginContext);
-
-       public Subject getSubject();
+       void authChange(LoginContext loginContext);
 
-       public void logout();
+       void logout();
 
        // SERVICES
-       public void exception(Throwable e);
+       void exception(Throwable e);
 
-       public CmsImageManager getImageManager();
+       CmsImageManager getImageManager();
 }
index 1ec52f057523cbe9aacade8a5ca55e1362acf390..2d606f2a8c4885bf767fc982892741941a0de1e5 100644 (file)
@@ -25,8 +25,8 @@ import javax.security.auth.Subject;
 import javax.security.auth.x500.X500Principal;
 
 import org.argeo.cms.CmsException;
-import org.argeo.cms.CmsView;
 import org.argeo.eclipse.ui.specific.UiContext;
+import org.argeo.node.NodeAuthenticated;
 import org.osgi.service.useradmin.Authorization;
 
 /** Static utilities */
@@ -49,11 +49,12 @@ public final class CurrentUser {
 
        public static boolean isAnonymous(Subject subject) {
                String username = getUsername(subject);
-               return username == null || username.equalsIgnoreCase(AuthConstants.ROLE_ANONYMOUS);
+               return username == null
+                               || username.equalsIgnoreCase(AuthConstants.ROLE_ANONYMOUS);
        }
 
        private static Subject currentSubject() {
-               CmsView cmsView = getCmsView();
+               NodeAuthenticated cmsView = getNodeAuthenticated();
                if (cmsView != null)
                        return cmsView.getSubject();
                Subject subject = Subject.getSubject(AccessController.getContext());
@@ -63,22 +64,19 @@ public final class CurrentUser {
        }
 
        /**
-        * The CMS view related to this display, or null if none is available from
-        * this call.
+        * The node authenticated component (typically a CMS view) related to this
+        * display, or null if none is available from this call.
         */
-       private static CmsView getCmsView() {
-               return UiContext.getData(CmsView.KEY);
+       public static NodeAuthenticated getNodeAuthenticated() {
+               return UiContext.getData(NodeAuthenticated.KEY);
        }
 
        public final static String getUsername(Subject subject) {
-               // Subject subject = Subject.getSubject(AccessController.getContext());
-               // if (subject == null)
-               // return null;
                if (subject.getPrincipals(X500Principal.class).size() != 1)
                        return null;
-               Principal principal = subject.getPrincipals(X500Principal.class).iterator().next();
+               Principal principal = subject.getPrincipals(X500Principal.class)
+                               .iterator().next();
                return principal.getName();
-
        }
 
        public final static String getDisplayName(Subject subject) {
@@ -86,7 +84,8 @@ public final class CurrentUser {
        }
 
        private static Authorization getAuthorization(Subject subject) {
-               return subject.getPrivateCredentials(Authorization.class).iterator().next();
+               return subject.getPrivateCredentials(Authorization.class).iterator()
+                               .next();
        }
 
        public final static Set<String> roles() {
@@ -95,7 +94,8 @@ public final class CurrentUser {
 
        public final static Set<String> roles(Subject subject) {
                Set<String> roles = new HashSet<String>();
-               X500Principal userPrincipal = subject.getPrincipals(X500Principal.class).iterator().next();
+               X500Principal userPrincipal = subject
+                               .getPrincipals(X500Principal.class).iterator().next();
                roles.add(userPrincipal.getName());
                for (Principal group : subject.getPrincipals(Group.class)) {
                        roles.add(group.getName());
diff --git a/org.argeo.node.api/src/org/argeo/node/NodeAuthenticated.java b/org.argeo.node.api/src/org/argeo/node/NodeAuthenticated.java
new file mode 100644 (file)
index 0000000..ed25490
--- /dev/null
@@ -0,0 +1,10 @@
+package org.argeo.node;
+
+import javax.security.auth.Subject;
+
+public interface NodeAuthenticated {
+       String KEY = "org.argeo.node.authenticated";
+
+       Subject getSubject();
+
+}
diff --git a/pom.xml b/pom.xml
index 521ee519e373a2b96f988b4eea4f77e235dea332..888fd7a9efde8c2421895741d1e558ffc2e5fc46 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,6 @@
                <!-- Eclipse -->
                <module>org.argeo.eclipse.ui</module>
                <module>org.argeo.eclipse.ui.rap</module>
-<!--           <module>org.argeo.eclipse.ui.workbench</module> -->
                <!-- CMS -->
                <module>org.argeo.node.api</module>
                <module>org.argeo.cms</module>