From: Mathieu Baudier Date: Wed, 11 Feb 2015 17:11:32 +0000 (+0000) Subject: Merge application and entry point factory X-Git-Tag: argeo-commons-2.1.30~397 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=04dade003a08c5915280ae653639b0af7cddeb0c;p=lgpl%2Fargeo-commons.git Merge application and entry point factory git-svn-id: https://svn.argeo.org/commons/trunk@7789 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java b/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java index 6722d7b86..1c9fc483d 100644 --- a/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java +++ b/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java @@ -1,5 +1,7 @@ package org.argeo.cms; +import static org.argeo.cms.internal.kernel.KernelConstants.SPRING_SECURITY_CONTEXT_KEY; + import java.util.Locale; import java.util.ResourceBundle; @@ -8,6 +10,7 @@ import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; +import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -23,10 +26,9 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; /** Manages history and navigation */ -public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint - implements CmsSession { +abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implements + CmsSession { private final Log log = LogFactory.getLog(AbstractCmsEntryPoint.class); - private static final String SPRING_SECURITY_CONTEXT_KEY = "SPRING_SECURITY_CONTEXT"; private Repository repository; private String workspace; @@ -35,15 +37,16 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint // current state private Node node; private String state; - private String page; + // private String page; private Throwable exception; private BrowserNavigation history; public AbstractCmsEntryPoint(Repository repository, String workspace) { if (SecurityContextHolder.getContext().getAuthentication() == null) { - SecurityContext contextFromSessionObject = (SecurityContext) RWT - .getRequest().getSession() + HttpSession httpSession = RWT.getRequest().getSession(); + // log.debug("Session: " + httpSession.getId()); + SecurityContext contextFromSessionObject = (SecurityContext) httpSession .getAttribute(SPRING_SECURITY_CONTEXT_KEY); if (contextFromSessionObject != null) SecurityContextHolder.setContext(contextFromSessionObject); @@ -163,7 +166,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint String previousState = this.state; node = null; - page = null; + // page = null; this.state = newState; try { @@ -173,7 +176,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint node = addNode(session, state, null); else node = session.getNode(state); - page = ""; + // page = ""; } else if (firstSlash > 0) { String prefix = state.substring(0, firstSlash); String path = state.substring(firstSlash); @@ -206,18 +209,19 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint throw new CmsException("Data " + path + " does not exist"); } - page = prefix; + throw new CmsException("Unsupported state prefix '" + prefix + + "'"); + // page = prefix; } else { node = getDefaultNode(session); - if (state.equals("~")) - page = ""; - else - page = state; + // if (state.equals("~")) + // page = ""; + // else + // page = state; } if (log.isTraceEnabled()) - log.trace("page=" + page + ", node=" + node + ", state=" - + state); + log.trace("node=" + node + ", state=" + state); } catch (RepositoryException e) { throw new CmsException("Cannot retrieve node", e); @@ -240,9 +244,9 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint return state; } - protected String getPage() { - return page; - } + // protected String getPage() { + // return page; + // } protected Throwable getException() { return exception; diff --git a/org.argeo.cms/src/org/argeo/cms/CmsApplication.java b/org.argeo.cms/src/org/argeo/cms/CmsApplication.java index 44dd82553..90df56a61 100644 --- a/org.argeo.cms/src/org/argeo/cms/CmsApplication.java +++ b/org.argeo.cms/src/org/argeo/cms/CmsApplication.java @@ -2,21 +2,44 @@ package org.argeo.cms; import java.io.IOException; import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import javax.jcr.Node; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.security.Privilege; +import javax.jcr.version.VersionManager; + +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.cms.internal.ImageManagerImpl; +import org.argeo.jcr.JcrUtils; import org.eclipse.gemini.blueprint.context.BundleContextAware; +import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.application.Application; import org.eclipse.rap.rwt.application.Application.OperationMode; import org.eclipse.rap.rwt.application.ApplicationConfiguration; +import org.eclipse.rap.rwt.application.EntryPoint; import org.eclipse.rap.rwt.application.EntryPointFactory; import org.eclipse.rap.rwt.application.ExceptionHandler; import org.eclipse.rap.rwt.client.WebClient; import org.eclipse.rap.rwt.service.ResourceLoader; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; import org.osgi.framework.BundleContext; /** Configures an Argeo CMS RWT application. */ @@ -24,8 +47,9 @@ public class CmsApplication implements CmsConstants, ApplicationConfiguration, BundleContextAware { final static Log log = LogFactory.getLog(CmsApplication.class); - private Map entryPoints = new HashMap(); - private Map> entryPointsBranding = new HashMap>(); + // private Map entryPoints = new HashMap(); + private Map> branding = new HashMap>(); private Map> styleSheets = new HashMap>(); private List resources = new ArrayList(); @@ -33,6 +57,22 @@ public class CmsApplication implements CmsConstants, ApplicationConfiguration, // private Bundle clientScriptingBundle; private BundleContext bundleContext; + private Repository repository; + private String workspace = null; + private String basePath = "/"; + private List roPrincipals = Arrays.asList("anonymous", "everyone"); + private List rwPrincipals = Arrays.asList("everyone"); + + private CmsLogin cmsLogin; + + private CmsUiProvider header; + private Map pages = new LinkedHashMap(); + + private Integer headerHeight = 40; + + // Managers + private CmsImageManager imageManager = new ImageManagerImpl(); + public void configure(Application application) { try { application.setOperationMode(OperationMode.SWT_COMPATIBILITY); @@ -52,29 +92,41 @@ public class CmsApplication implements CmsConstants, ApplicationConfiguration, log.debug("Registered resource " + resource); } + Map defaultBranding = null; + if (branding.containsKey("*")) + defaultBranding = branding.get("*"); + // entry points - for (String entryPoint : entryPoints.keySet()) { - Map properties = new HashMap(); - if (entryPointsBranding.containsKey(entryPoint)) { - properties = entryPointsBranding.get(entryPoint); - if (properties.containsKey(WebClient.FAVICON)) { - String faviconRelPath = properties - .get(WebClient.FAVICON); - application.addResource(faviconRelPath, - new BundleResourceLoader(bundleContext)); - if (log.isTraceEnabled()) - log.trace("Registered favicon " + faviconRelPath); - - } - - if (!properties.containsKey(WebClient.BODY_HTML)) - properties.put(WebClient.BODY_HTML, - DEFAULT_LOADING_BODY); + for (String page : pages.keySet()) { + Map properties = defaultBranding != null ? new HashMap( + defaultBranding) : new HashMap(); + if (branding.containsKey(page)) { + properties.putAll(branding.get(page)); + } + // favicon + if (properties.containsKey(WebClient.FAVICON)) { + String faviconRelPath = properties.get(WebClient.FAVICON); + application.addResource(faviconRelPath, + new BundleResourceLoader(bundleContext)); + if (log.isTraceEnabled()) + log.trace("Registered favicon " + faviconRelPath); + } - application.addEntryPoint("/" + entryPoint, - entryPoints.get(entryPoint), properties); - log.info("Registered entry point /" + entryPoint); + // page title + if (!properties.containsKey(WebClient.PAGE_TITLE)) + properties.put( + WebClient.PAGE_TITLE, + Character.toUpperCase(page.charAt(0)) + + page.substring(1)); + + // default body HTML + if (!properties.containsKey(WebClient.BODY_HTML)) + properties.put(WebClient.BODY_HTML, DEFAULT_LOADING_BODY); + + application.addEntryPoint("/" + page, new CmsEntryPointFactory( + page), properties); + log.info("Registered entry point /" + page); } // stylesheets @@ -86,9 +138,6 @@ public class CmsApplication implements CmsConstants, ApplicationConfiguration, } } - -// application.addPhaseListener(new CmsPhaseListener()); - } catch (RuntimeException e) { // Easier access to initialisation errors log.error("Unexpected exception when configuring RWT application.", @@ -97,24 +146,104 @@ public class CmsApplication implements CmsConstants, ApplicationConfiguration, } } - private static ResourceLoader createResourceLoader(final String resourceName) { - return new ResourceLoader() { - public InputStream getResourceAsStream(String resourceName) - throws IOException { - return getClass().getClassLoader().getResourceAsStream( - resourceName); + public void init() throws RepositoryException { + if (workspace == null) + throw new CmsException( + "Workspace must be set when calling initialization." + + " Please make sure that read-only and read-write roles" + + " have been properly configured:" + + " the defaults are open."); + + Session session = null; + try { + session = JcrUtils.loginOrCreateWorkspace(repository, workspace); + VersionManager vm = session.getWorkspace().getVersionManager(); + if (!vm.isCheckedOut("/")) + vm.checkout("/"); + JcrUtils.mkdirs(session, basePath); + for (String principal : rwPrincipals) + JcrUtils.addPrivilege(session, basePath, principal, + Privilege.JCR_WRITE); + for (String principal : roPrincipals) + JcrUtils.addPrivilege(session, basePath, principal, + Privilege.JCR_READ); + + for (String pageName : pages.keySet()) { + try { + initPage(session, pages.get(pageName)); + session.save(); + } catch (Exception e) { + throw new CmsException( + "Cannot initialize page " + pageName, e); + } } - }; + + } finally { + JcrUtils.logoutQuietly(session); + } } - public void setEntryPoints( - Map entryPointFactories) { - this.entryPoints = entryPointFactories; + protected void initPage(Session adminSession, CmsUiProvider page) + throws RepositoryException { + if (page instanceof LifeCycleUiProvider) + ((LifeCycleUiProvider) page).init(adminSession); } - public void setEntryPointsBranding( - Map> entryPointBranding) { - this.entryPointsBranding = entryPointBranding; + public void destroy() { + for (String pageName : pages.keySet()) { + try { + CmsUiProvider page = pages.get(pageName); + if (page instanceof LifeCycleUiProvider) + ((LifeCycleUiProvider) page).destroy(); + } catch (Exception e) { + log.error("Cannot destroy page " + pageName, e); + } + } + } + + public void setRepository(Repository repository) { + this.repository = repository; + } + + public void setWorkspace(String workspace) { + this.workspace = workspace; + } + + public void setCmsLogin(CmsLogin cmsLogin) { + this.cmsLogin = cmsLogin; + } + + public void setHeader(CmsUiProvider header) { + this.header = header; + } + + public void setPages(Map pages) { + this.pages = pages; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public void setRoPrincipals(List roPrincipals) { + this.roPrincipals = roPrincipals; + } + + public void setRwPrincipals(List rwPrincipals) { + this.rwPrincipals = rwPrincipals; + } + + public void setHeaderHeight(Integer headerHeight) { + this.headerHeight = headerHeight; + } + + // public void setEntryPoints( + // Map entryPointFactories) { + // this.entryPoints = entryPointFactories; + // } + + public void setBranding(Map> branding) { + this.branding = branding; } public void setStyleSheets(Map> styleSheets) { @@ -138,26 +267,166 @@ public class CmsApplication implements CmsConstants, ApplicationConfiguration, } -// class CmsPhaseListener implements PhaseListener { -// private static final long serialVersionUID = -1966645586738534609L; -// -// @Override -// public PhaseId getPhaseId() { -// return PhaseId.RENDER; -// } -// -// @Override -// public void beforePhase(PhaseEvent event) { -// CmsSession cmsSession = CmsSession.current.get(); -// String state = cmsSession.getState(); -// if (state == null) -// cmsSession.navigateTo("~"); -// } -// -// @Override -// public void afterPhase(PhaseEvent event) { -// } -// } + private class CmsEntryPointFactory implements EntryPointFactory { + private final String page; + + public CmsEntryPointFactory(String page) { + this.page = page; + } + + @Override + public EntryPoint create() { + CmsEntryPoint entryPoint = new CmsEntryPoint(repository, workspace, + pages.get(page)); + entryPoint.setState(""); + CmsSession.current.set(entryPoint); + return entryPoint; + } + + } + + private class CmsEntryPoint extends AbstractCmsEntryPoint { + private Composite headerArea; + private Composite bodyArea; + private final CmsUiProvider uiProvider; + + public CmsEntryPoint(Repository repository, String workspace, + CmsUiProvider uiProvider) { + super(repository, workspace); + this.uiProvider = uiProvider; + } + + @Override + protected void createContents(Composite parent) { + try { + getShell().getDisplay().setData(CmsSession.KEY, this); + + parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, + true)); + parent.setLayout(CmsUtils.noSpaceGridLayout()); + + headerArea = new Composite(parent, SWT.NONE); + headerArea.setLayout(new FillLayout()); + GridData headerData = new GridData(SWT.FILL, SWT.FILL, false, + false); + headerData.heightHint = headerHeight; + headerArea.setLayoutData(headerData); + refreshHeader(); + + bodyArea = new Composite(parent, SWT.NONE); + bodyArea.setData(RWT.CUSTOM_VARIANT, CmsStyles.CMS_BODY); + bodyArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, + true)); + bodyArea.setBackgroundMode(SWT.INHERIT_DEFAULT); + bodyArea.setLayout(CmsUtils.noSpaceGridLayout()); + refreshBody(); + } catch (Exception e) { + throw new CmsException("Cannot create entrypoint contents", e); + } + } + + @Override + protected void refreshHeader() { + if (headerArea == null) + return; + for (Control child : headerArea.getChildren()) + child.dispose(); + try { + header.createUi(headerArea, getNode()); + } catch (RepositoryException e) { + throw new CmsException("Cannot refresh header", e); + } + headerArea.layout(true, true); + } + + @Override + protected void refreshBody() { + if (bodyArea == null) + return; + // clear + for (Control child : bodyArea.getChildren()) + child.dispose(); + bodyArea.setLayout(CmsUtils.noSpaceGridLayout()); + + // Exception + Throwable exception = getException(); + if (exception != null) { + new Label(bodyArea, SWT.NONE).setText("Unreachable state : " + + getState()); + if (getNode() != null) + new Label(bodyArea, SWT.NONE).setText("Context : " + + getNode()); + + Text errorText = new Text(bodyArea, SWT.MULTI | SWT.H_SCROLL + | SWT.V_SCROLL); + errorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, + true)); + StringWriter sw = new StringWriter(); + exception.printStackTrace(new PrintWriter(sw)); + errorText.setText(sw.toString()); + IOUtils.closeQuietly(sw); + resetException(); + // TODO report + } else { + String state = getState(); + try { + if (state == null) + throw new CmsException("State cannot be null"); + uiProvider.createUi(bodyArea, getNode()); + // if (page == null) + // throw new CmsException("Page cannot be null"); + // // else if (state.length() == 0) + // // log.debug("empty state"); + // else if (pages.containsKey(page)) + // pages.get(page).createUi(bodyArea, getNode()); + // else { + // // try { + // // RWT.getResponse().sendError(404); + // // } catch (IOException e) { + // // log.error("Cannot send 404 code", e); + // // } + // throw new CmsException("Unsupported state " + state); + // } + } catch (RepositoryException e) { + throw new CmsException("Cannot refresh body", e); + } + } + bodyArea.layout(true, true); + } + + @Override + protected void logAsAnonymous() { + cmsLogin.logInAsAnonymous(); + } + + @Override + protected Node getDefaultNode(Session session) + throws RepositoryException { + if (!session.hasPermission(basePath, "read")) { + if (session.getUserID().equals("anonymous")) + throw new CmsLoginRequiredException(); + else + throw new CmsException("Unauthorized"); + } + return session.getNode(basePath); + } + + @Override + public CmsImageManager getImageManager() { + return imageManager; + } + + } + + private static ResourceLoader createResourceLoader(final String resourceName) { + return new ResourceLoader() { + public InputStream getResourceAsStream(String resourceName) + throws IOException { + return getClass().getClassLoader().getResourceAsStream( + resourceName); + } + }; + } /* * TEXTS diff --git a/org.argeo.cms/src/org/argeo/cms/CmsConstants.java b/org.argeo.cms/src/org/argeo/cms/CmsConstants.java index 9d299dcbc..cae0167c8 100644 --- a/org.argeo.cms/src/org/argeo/cms/CmsConstants.java +++ b/org.argeo.cms/src/org/argeo/cms/CmsConstants.java @@ -6,13 +6,13 @@ import org.eclipse.swt.graphics.Point; /** Commons constants */ public interface CmsConstants { // DATAKEYS - public static final String STYLE = RWT.CUSTOM_VARIANT; - public static final String MARKUP = RWT.MARKUP_ENABLED; + public final static String STYLE = RWT.CUSTOM_VARIANT; + public final static String MARKUP = RWT.MARKUP_ENABLED; // STANDARD RESOURCES - public static final String LOADING_IMAGE = "icons/loading.gif"; + public final static String LOADING_IMAGE = "icons/loading.gif"; - public static final String NO_IMAGE = "icons/noPic-square-640px.png"; - public static final Point NO_IMAGE_SIZE = new Point(640, 640); - public static final Float NO_IMAGE_RATIO = 1f; + public final static String NO_IMAGE = "icons/noPic-square-640px.png"; + public final static Point NO_IMAGE_SIZE = new Point(640, 640); + public final static Float NO_IMAGE_RATIO = 1f; } diff --git a/org.argeo.cms/src/org/argeo/cms/CmsEntryPointFactory.java b/org.argeo.cms/src/org/argeo/cms/CmsEntryPointFactory.java index de631ddae..873ae8131 100644 --- a/org.argeo.cms/src/org/argeo/cms/CmsEntryPointFactory.java +++ b/org.argeo.cms/src/org/argeo/cms/CmsEntryPointFactory.java @@ -21,7 +21,6 @@ import org.argeo.cms.internal.ImageManagerImpl; import org.argeo.jcr.JcrUtils; import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.application.EntryPoint; -import org.eclipse.rap.rwt.application.EntryPointFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; @@ -31,7 +30,8 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** Creates and registers an {@link EntryPoint} */ -public class CmsEntryPointFactory implements EntryPointFactory { +@Deprecated +class CmsEntryPointFactory { private final static Log log = LogFactory .getLog(CmsEntryPointFactory.class); @@ -51,7 +51,6 @@ public class CmsEntryPointFactory implements EntryPointFactory { // Managers private CmsImageManager imageManager = new ImageManagerImpl(); - @Override public EntryPoint create() { CmsEntryPoint cmsEntryPoint = new CmsEntryPoint(repository, workspace); CmsSession.current.set(cmsEntryPoint); @@ -199,6 +198,7 @@ public class CmsEntryPointFactory implements EntryPointFactory { headerArea.layout(true, true); } + @SuppressWarnings("unused") @Override protected void refreshBody() { if (bodyArea == null) @@ -229,7 +229,7 @@ public class CmsEntryPointFactory implements EntryPointFactory { // TODO report } else { String state = getState(); - String page = getPage(); + String page = null; try { if (state == null) throw new CmsException("State cannot be null"); diff --git a/org.argeo.cms/src/org/argeo/cms/CmsLogin.java b/org.argeo.cms/src/org/argeo/cms/CmsLogin.java index f470d9ba6..54ed1efcb 100644 --- a/org.argeo.cms/src/org/argeo/cms/CmsLogin.java +++ b/org.argeo.cms/src/org/argeo/cms/CmsLogin.java @@ -1,10 +1,16 @@ package org.argeo.cms; +import static org.argeo.cms.internal.kernel.KernelConstants.SPRING_SECURITY_CONTEXT_KEY; + import java.util.Collections; import java.util.List; +import javax.servlet.http.HttpSession; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.cms.internal.kernel.KernelConstants; +import org.eclipse.rap.rwt.RWT; import org.springframework.security.authentication.AnonymousAuthenticationToken; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -18,13 +24,14 @@ import org.springframework.security.core.userdetails.UserDetails; public class CmsLogin { private final static Log log = LogFactory.getLog(CmsLogin.class); private AuthenticationManager authenticationManager; - private String systemKey = "argeo"; + private String systemKey = KernelConstants.DEFAULT_SECURITY_KEY; protected void logInAsAnonymous() { // TODO Better deal with anonymous authentication try { List anonAuthorities = Collections - .singletonList(new SimpleGrantedAuthority("ROLE_ANONYMOUS")); + .singletonList(new SimpleGrantedAuthority( + KernelConstants.ANONYMOUS_USER)); UserDetails anonUser = new User("anonymous", "", true, true, true, true, anonAuthorities); AnonymousAuthenticationToken anonToken = new AnonymousAuthenticationToken( @@ -44,49 +51,13 @@ public class CmsLogin { Authentication authentication = authenticationManager .authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); + HttpSession httpSession = RWT.getRequest().getSession(); + httpSession.setAttribute(SPRING_SECURITY_CONTEXT_KEY, + SecurityContextHolder.getContext()); if (log.isDebugEnabled()) log.debug("Authenticated as " + authentication); } - /* - * UI - */ - - // @Override - // public Control createUi(Composite parent, Node context) - // throws RepositoryException { - // Composite comp = new Composite(parent, SWT.NONE); - // comp.setLayout(new GridLayout(1, true)); - // comp.setData(RWT.CUSTOM_VARIANT, CmsStyles.CMS_LOGIN); - // refreshUi(comp); - // return comp; - // } - - // protected void refreshUi(Composite comp) { - // String username = SecurityContextHolder.getContext() - // .getAuthentication().getName(); - // if (username.equals("anonymous")) - // username = null; - // - // for (Control child : comp.getChildren()) { - // child.dispose(); - // } - // - // Label l = new Label(comp, SWT.NONE); - // l.setData(RWT.CUSTOM_VARIANT, CmsStyles.CMS_LOGIN); - // l.setData(RWT.MARKUP_ENABLED, true); - // l.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); - // if (username != null) { - // l.setText("" + username + ""); - // l.addMouseListener(new UserListener()); - // } else { - // l.setText("Log in"); - // l.addMouseListener(new LoginListener()); - // } - // - // comp.pack(); - // } - public void setAuthenticationManager( AuthenticationManager authenticationManager) { this.authenticationManager = authenticationManager; @@ -96,124 +67,4 @@ public class CmsLogin { this.systemKey = systemKey; } - // private class UserListener extends MouseAdapter { - // private static final long serialVersionUID = -3565359775509786183L; - // private Control source; - // private Shell dialog; - // - // @Override - // public void mouseDown(MouseEvent e) { - // source = ((Control) e.widget); - // if (dialog != null) { - // dialog.close(); - // dialog.dispose(); - // dialog = null; - // } else { - // dialog = createDialog(source); - // } - // } - // - // @SuppressWarnings("serial") - // protected Shell createDialog(Control source) { - // Shell dialog = new Shell(source.getDisplay(), SWT.NO_TRIM - // | SWT.BORDER | SWT.ON_TOP); - // dialog.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU); - // dialog.setLayout(new GridLayout(1, false)); - // - // final CmsSession cmsSession = (CmsSession) source.getDisplay() - // .getData(CmsSession.KEY); - // - // Label l = new Label(dialog, SWT.NONE); - // l.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU_ITEM); - // l.setText("Log out"); - // GridData lData = new GridData(SWT.FILL, SWT.FILL, true, false); - // lData.widthHint = 120; - // l.setLayoutData(lData); - // - // l.addMouseListener(new MouseAdapter() { - // public void mouseDown(MouseEvent e) { - // SecurityContextHolder.getContext().setAuthentication(null); - // UserListener.this.dialog.close(); - // UserListener.this.dialog.dispose(); - // cmsSession.authChange(); - // } - // }); - // - // dialog.pack(); - // dialog.layout(); - // dialog.setLocation(source.toDisplay( - // source.getSize().x - dialog.getSize().x, source.getSize().y)); - // dialog.open(); - // return dialog; - // } - // } - // - // private class LoginListener extends MouseAdapter { - // private static final long serialVersionUID = 677115566708451462L; - // private Control source; - // private Shell dialog; - // - // @Override - // public void mouseDown(MouseEvent e) { - // source = ((Control) e.widget); - // if (dialog != null) { - // dialog.close(); - // dialog.dispose(); - // dialog = null; - // } else { - // dialog = createDialog(source); - // } - // } - // - // @SuppressWarnings("serial") - // protected Shell createDialog(Control source) { - // Integer textWidth = 150; - // Shell dialog = new Shell(source.getDisplay(), SWT.NO_TRIM - // | SWT.BORDER | SWT.ON_TOP); - // dialog.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG); - // dialog.setLayout(new GridLayout(2, false)); - // - // new Label(dialog, SWT.NONE).setText("Username"); - // final Text username = new Text(dialog, SWT.BORDER); - // username.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG_USERNAME); - // GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false); - // gd.widthHint = textWidth; - // username.setLayoutData(gd); - // - // new Label(dialog, SWT.NONE).setText("Password"); - // final Text password = new Text(dialog, SWT.BORDER | SWT.PASSWORD); - // password.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG_PASSWORD); - // gd = new GridData(SWT.FILL, SWT.FILL, true, false); - // gd.widthHint = textWidth; - // password.setLayoutData(gd); - // - // dialog.pack(); - // dialog.layout(); - // dialog.setLocation(source.toDisplay( - // source.getSize().x - dialog.getSize().x, source.getSize().y)); - // dialog.open(); - // - // // Listeners - // TraverseListener tl = new TraverseListener() { - // public void keyTraversed(TraverseEvent e) { - // if (e.detail == SWT.TRAVERSE_RETURN) - // login(username.getText(), password.getTextChars()); - // } - // }; - // username.addTraverseListener(tl); - // password.addTraverseListener(tl); - // return dialog; - // } - // - // protected void login(String username, char[] password) { - // CmsSession cmsSession = (CmsSession) source.getDisplay().getData( - // CmsSession.KEY); - // logInWithPassword(username, password); - // dialog.close(); - // dialog.dispose(); - // refreshUi(source.getParent()); - // cmsSession.authChange(); - // } - // - // } } diff --git a/org.argeo.cms/src/org/argeo/cms/UserMenu.java b/org.argeo.cms/src/org/argeo/cms/UserMenu.java index da48237fa..41ff9ab7f 100644 --- a/org.argeo.cms/src/org/argeo/cms/UserMenu.java +++ b/org.argeo.cms/src/org/argeo/cms/UserMenu.java @@ -1,5 +1,9 @@ package org.argeo.cms; +import static org.argeo.cms.internal.kernel.KernelConstants.SPRING_SECURITY_CONTEXT_KEY; + +import javax.servlet.http.HttpSession; + import org.eclipse.rap.rwt.RWT; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; @@ -81,6 +85,8 @@ public class UserMenu extends Shell implements CmsStyles { public void mouseDown(MouseEvent e) { SecurityContextHolder.getContext().setAuthentication(null); + HttpSession httpSession = RWT.getRequest().getSession(); + httpSession.removeAttribute(SPRING_SECURITY_CONTEXT_KEY); close(); dispose(); cmsSession.authChange(); diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelConstants.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelConstants.java index eb60f4596..1c6f8f020 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelConstants.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelConstants.java @@ -1,6 +1,9 @@ package org.argeo.cms.internal.kernel; -interface KernelConstants { +public interface KernelConstants { + // (internal) API + public final static String SPRING_SECURITY_CONTEXT_KEY = "SPRING_SECURITY_CONTEXT"; + // Node final static String REPO_HOME = "argeo.node.repo.home"; final static String REPO_CONFIGURATION = "argeo.node.repo.configuration"; @@ -31,4 +34,5 @@ interface KernelConstants { final static String PATH_REMOTING_PUBLIC = "/data/pub"; final static String PATH_REMOTING_PRIVATE = "/data/jcr"; final static String PATH_WORKBENCH_PUBLIC = "/ui/public"; + } diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeHttp.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeHttp.java index db66de2ea..928afd3a3 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeHttp.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeHttp.java @@ -40,8 +40,6 @@ class NodeHttp implements KernelConstants, ArgeoJcrConstants { private final static String HEADER_AUTHORIZATION = "Authorization"; private final static String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate"; - static final String SPRING_SECURITY_CONTEXT_KEY = "SPRING_SECURITY_CONTEXT"; - private final AuthenticationManager authenticationManager; private final BundleContext bundleContext; private ExtendedHttpService httpService;